示例#1
0
def refresh_login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = app.db.auth_user(
                request.form['username'],
                request.form['password'])
        if user:
            confirm_login(user)
            logger.info('User: %s - login auth success.' % (request.form['username']))
            return redirect(url_for('user_home', username=user.username))
        else:
            logger.info('User: %s - login auth failure.' % (request.form['username']))
            error = 'Invalid username or password.'
    return render_template('user/login.html', form=form, error=error)
示例#2
0
def login():
    error = None
    form = LoginForm()
    if form.validate_on_submit():
        user = User.auth_user(
                request.form['username'],
                request.form['password'])
        if user:
            login_user(user)
            logger.info('User: %s - login auth success.' % (request.form['username']))
            return redirect(url_for('user_home', username=request.form['username']))
        else:
            logger.info('User: %s - login auth failure.' % (request.form['username']))
            error = 'Invalid username or password.'

    return render_template('user/login.html', form=form, error=error)