當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。