本文整理汇总了Python中db.User.password方法的典型用法代码示例。如果您正苦于以下问题:Python User.password方法的具体用法?Python User.password怎么用?Python User.password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.User
的用法示例。
在下文中一共展示了User.password方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: route_register_api
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import password [as 别名]
def route_register_api():
if g.user:
raise APIError("Already logged in!")
params = {k:v for k, v in request.values.items() if k in ["username", "password", "email"]}
if not all(params.values()):
raise APIError("Missing required paramaters!")
try:
User.get((User.username == params["username"]) | (User.email == params["email"]))
raise APIError("User with that username/email already exists!")
except User.DoesNotExist: pass
u = User(username=params["username"], email=params["email"])
u.password = User.hash_password(params["password"])
session["id"] = u.save()
return APIResponse()
示例2: updateUser
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import password [as 别名]
def updateUser(cookie, uid, handle, name, pwd, admin, email):
session = Session()
u = usermanagment.getUser(cookie)
if not u.admin and uid != u.id:
raise Exception("Invalid access %s %s" % (uid, u.id))
if uid == -1:
cu = User(handle)
session.add(cu)
else:
q = session.query(User).filter_by(id=uid)
if q.count() == 0:
raise Exception("User not found")
cu = q.one()
cu.name = name
cu.email = email
if pwd:
cu.password = pwd
if u.admin:
cu.admin = admin
session.commit()
return cu.id
示例3: route_register
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import password [as 别名]
def route_register():
if g.user:
return redirect("/", code=302)
if request.method == "GET":
return render_template("register.html")
params = {k:v for k, v in request.values.items() if k in ["username", "password", "email"]}
if not all(params.values()):
return redirect("/", code=302)
try:
User.get((User.username == params["username"]) | (User.email == params["email"]))
return redirect("/", code=302)
except User.DoesNotExist: pass
u = User(username=params["username"], email=params["email"])
u.password = User.hash_password(params["password"])
session["id"] = u.save()
g.user = u
return redirect("/", code=302)