本文整理汇总了Python中db.User.hash_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.hash_password方法的具体用法?Python User.hash_password怎么用?Python User.hash_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.User
的用法示例。
在下文中一共展示了User.hash_password方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: route_register_api
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import hash_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: route_register
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import hash_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)