本文整理汇总了Python中models.users.User.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python User.serialize方法的具体用法?Python User.serialize怎么用?Python User.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.users.User
的用法示例。
在下文中一共展示了User.serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: signup
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import serialize [as 别名]
def signup(request):
try:
cleanData = utils.format_body_params(request.json)
emailAddress = cleanData.get("emailAddress")
password = request.json.get("password")
firstName = cleanData.get("firstName")
lastName = cleanData.get("lastName")
phoneNumber = cleanData.get("phoneNumber")
if not emailAddress:
return response.json({"error": "No email address provided"}, 400)
if not password:
return response.json({"error": "No password provided"}, 400)
if utils.email_account_exists(emailAddress):
return response.json(
{"error": "An account with that email address already exists"}, 400
)
if len(password) < request.app.config["MIN_PASS_LENGTH"]:
return response.json(
{"error": "Password does not meet required length requirements"}, 400
)
user = User(
firstName=firstName,
lastName=lastName,
emailAddress=emailAddress,
password=utils.encrypt_pass(password),
phoneNumber=phoneNumber,
)
db.session.add(user)
db.session.commit()
req_config = request.app.config
if req_config["SENDGRID_API_KEY"] and req_config["API_ENV"] != "TESTING":
emails.send_welcome_email(user)
return response.json(user.serialize(jwt=True), 201)
except Exception as e:
return utils.exeption_handler(e, "Signup failed", 400)