Exemplo n.º 1
0
def ajax_login():
    form = LoginForm(request.form)
    if form.validate_login(request.form):
        user = User.query.filter(User.name == request.form['username']).one()
        login_user(user)
        return jsonify({'status': 1, 'info': u'登录成功'})
    else:
        return jsonify({'status': LOGIN_ERROR_GENERAL, 'info': u'用户名或者密码错误'})
Exemplo n.º 2
0
def login():
    form = LoginForm(request.form)
    url = request.args.get('url')
    if request.method == 'POST' and form.validate_login(request.form):
        user = db.query(User).filter(
            User.name == request.form['username']).one()
        try:
            login_user(user)
            ip = request.remote_addr
            user.login_ip = ip
            db.commit()
        finally:
            pass
        if url is not None and is_safe_url(url):
            return redirect(url)
        else:
            return redirect('/profile/' + str(user.id))
    return render_template('user/login.html', form=form, url=url)