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


Python User.by_login方法代码示例

本文整理汇总了Python中auth.models.User.by_login方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_login方法的具体用法?Python User.by_login怎么用?Python User.by_login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在auth.models.User的用法示例。


在下文中一共展示了User.by_login方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: change_password

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import by_login [as 别名]
def change_password():
    """Change password

    **Change user password using json params.**
    ---
    tags:
      - Core
    parameters:
      - in: body
        name: body
        required: true
        schema:
          id: change_password_form
          required:
            - old_password
            - password
            - confirm_password
          properties:
            old_password:
              type: string
            password:
              type: string
            confirm_password:
              type: string
    responses:
      200:
        description: Change with success
        schema:
          id: generic_success
          properties:
            message:
              type: string
      400:
        description: Invalid json informations
        schema:
          $ref: "#/definitions/generic_error"
      401:
        description: Invalid credentials
        schema:
          $ref: "#/definitions/generic_error"
    """
    required_fields = ('old_password', 'password', 'confirm_password')
    if all(request.json.get(field) for field in required_fields):
        old_password = request.json.get('old_password')
        password = request.json.get('password')
        confirm_password = request.json.get('confirm_password')
    else:
        return abort(400)

    try:
        user = User.by_login(current_user.username)
        user.change_password(old_password=old_password, password=password, confirm_password=confirm_password)
        return jsonify({'message': 'success'}), 200

    except (InvalidPassword, PasswordMismatch):
        return abort(400)

    except InvalidCredentials:
        return abort(401)
开发者ID:maxnovais,项目名称:flapy_auth,代码行数:61,代码来源:core.py

示例2: redirect

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import by_login [as 别名]
    if g.user:
        return redirect(url_for('profile'))

    form = RegisterForm(request.form)
    if request.method == 'POST' and form.is_valid():
        user = form.save()
        user.add_role('user')
        db.commit()  # commit BEFORE doing auth.login!
        auth.login(user)
        return redirect(url_for('profile'))

    return render_template('index.html', **locals())


@app.route('/user/')
@auth.protected()
def profile():
    return render_template('profile.html', **locals())


if __name__ == '__main__':
    # Just for this demo
    db.create_all()
    if not User.by_login(u'example'):
        db.add(User(login=u'example', password='example'))
        db.commit()
    #

    port = int(os.getenv("PORT", 5000))
    app.run(host='0.0.0.0', port=port)
开发者ID:jpscaletti,项目名称:authcode,代码行数:32,代码来源:main.py

示例3: test_get_inexistent_user

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import by_login [as 别名]
def test_get_inexistent_user():
    with pytest.raises(UserNotFound):
        User.by_login('Luke_Skywalker')
开发者ID:maxnovais,项目名称:flapy_auth,代码行数:5,代码来源:test_user.py

示例4: test_get_user_with_email

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import by_login [as 别名]
def test_get_user_with_email(user):
    user = User.by_login('[email protected]')
    assert str(user) == '<User[1] username=\'Darth_Vader\'>'
开发者ID:maxnovais,项目名称:flapy_auth,代码行数:5,代码来源:test_user.py

示例5: test_get_user_with_username

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import by_login [as 别名]
def test_get_user_with_username(user):
    user = User.by_login('Darth_Vader')
    assert user.email == '[email protected]'
开发者ID:maxnovais,项目名称:flapy_auth,代码行数:5,代码来源:test_user.py

示例6: login

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import by_login [as 别名]
def login():
    """Login

    **Authenticate user using json params.**
    ---
    tags:
      - Core
    parameters:
      - in: body
        name: body
        required: true
        schema:
          id: login_form
          required:
            - username
            - password
          properties:
            username:
              type: string
            password:
              type: string
            remember:
              type: boolean
    responses:
      200:
        description: Login with success
        schema:
          id: generic_success
          properties:
            message:
              type: string
      400:
        description: Invalid json informations
        schema:
          id: generic_error
          properties:
            error_code:
              type: string
      401:
        description: Invalid credentials
        schema:
          $ref: "#/definitions/generic_error"
      404:
        description: User not found
        schema:
          $ref: "#/definitions/generic_error"
    """
    required_fields = ('username', 'password')
    if all(request.json.get(field) for field in required_fields):
        username = request.json.get('username')
        password = request.json.get('password')
        remember = request.json.get('remember')
    else:
        return abort(400)

    try:
        user = User.by_login(username)
        if user.validate_password(password):
            login_user(user, remember)
            return jsonify({'message': 'success'}), 200
        else:
            return abort(401)

    except UserNotFound:
        return abort(404)
开发者ID:maxnovais,项目名称:flapy_auth,代码行数:67,代码来源:core.py


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