Beispiel #1
0
def login():
    form = LoginForm().validate_for_api()
    if request.method == 'POST' and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if not user or not user.check_password(form.secret.data):
            log.logging.error('[ERROR] password or email is not Incorrect')
            raise AuthFailed()
        token = generate_token(user.id, current_app.config['EXPIRE'])
        t = {'token': token.decode('ascii')}
        return jsonify(t), 200
Beispiel #2
0
def login():
    form = LoginForm().validate_for_api()
    user = User.query.filter(
        or_(User.nickname == form.account.data,
            User.email == form.account.data)).first()
    if user and user.check_password(form.secret.data):
        # login_user(user, remember=True)
        # session.permanent = True
        return restful_json(user)
    else:
        return LoginFailed()
Beispiel #3
0
def login_api():
    form = LoginForm().validate_for_api()
    username = form.username.data
    password = form.password.data
    user = get_user_by_username(username)
    if not user:
        raise AuthFailed('Username does not exist')
    if not check_password(user, password):
        raise AuthFailed('Wrong username or password')
    login_user(user, remember=True)
    return Success('Login successful')
Beispiel #4
0
def login():
    form = LoginForm().validate_for_api()
    user = manager.user_model.verify(form.username.data, form.password.data)
    # 此处不能用装饰器记录日志
    Log.create_log(
        message=f'{user.username}登陆成功获取了令牌',
        user_id=user.id, user_name=user.username,
        status_code=200, method='post', path='/cms/user/login',
        authority='无', commit=True
    )
    access_token, refresh_token = get_tokens(user)
    return json_res(access_token=access_token, refresh_token=refresh_token)