本文整理汇总了Python中app.users.models.User.objects方法的典型用法代码示例。如果您正苦于以下问题:Python User.objects方法的具体用法?Python User.objects怎么用?Python User.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.objects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import objects [as 别名]
def register():
email = request.form['email']
username = request.form['username']
password = request.form['password'].encode('utf8')
salt = generate_random_salt()
password_hash = generate_password_hash(password, salt)
# Check if email already exist in database
# if account does not exist create account in database
if User.objects(email=email).first() == None:
user = User(email=email)
user.accounts['internal'] = {"username":username, "password_hash":password_hash, \
"salt":salt}
user.save()
ret = json_util.dumps({"message":"account created", "status":"success"})
resp = Response(response=ret,
status=201,
mimetype="application/json")
return resp
else:
ret = json_util.dumps({"message":"Email already exist in database"})
resp = Response(response=ret,
status=200,
mimetype="application/json")
return resp
示例2: login
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import objects [as 别名]
def login():
email = request.form['email']
password = request.form['password']
user = User.objects(email=email).first()
if user is not None:
password_hash = user.accounts['internal']['password_hash']
salt = user.accounts['internal']['salt']
if check_password_hash(password, password_hash, salt):
session['user_id'] = user.get_id()
ret = json_util.dumps({"username":user.accounts['internal']['username']})
resp = Response(response=ret, status=200, mimetype="application/json")
return resp
ret = json_util.dumps({"message":"Incorrect Username or Password."})
resp = Response(response=ret, status=401, mimetype="application/json")
return resp
示例3: user_function
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import objects [as 别名]
def user_function():
all_user = User.objects()
return render_template('admin/user.html', all_user=all_user)
示例4: before_request
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import objects [as 别名]
def before_request():
g.user = None
if 'user_id' in session:
g.user = User.objects(id=session['user_id']).first()
示例5: load_user
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import objects [as 别名]
def load_user(user_id):
return User.objects(id=user_id).first()