当前位置: 首页>>代码示例>>Python>>正文


Python User.objects方法代码示例

本文整理汇总了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
开发者ID:cryptojuice,项目名称:goodmusic,代码行数:28,代码来源:views.py

示例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
开发者ID:cryptojuice,项目名称:goodmusic,代码行数:17,代码来源:views.py

示例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)
开发者ID:Saberlion,项目名称:Bearnote,代码行数:5,代码来源:views.py

示例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()
开发者ID:cryptojuice,项目名称:goodmusic,代码行数:6,代码来源:views.py

示例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()
开发者ID:cryptojuice,项目名称:goodmusic,代码行数:4,代码来源:views.py


注:本文中的app.users.models.User.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。