示例#1
0
def login(request):
    if authenticated_userid(request):
        return HTTPFound(location=request.route_url('overview'))
    bootstrap_responsive_css.need()
    trans = get_localizer(request).translate
    form = login_form(request)
    if request.POST and form.validate():
        login = form.username.value
        password = form.password.value
        user = DBSession.query(User).filter_by(username=login).first()  # returns user or None
        if user is not None and user.check_password(password):
            headers = remember(request, login)
            request.session.flash(trans(_('Succesfully logged in')), 'success')
            return HTTPFound(location=request.route_url('overview'),
                             headers=headers)
        log.debug('Login failed {0}'.format(form.username.value))
        #clear password as it was wrong
        form.data['LoginForm--password'] = ''
        request.session.flash(trans(_(u'Login failed<br />Please try again')), 'error')

    return dict(
        form=form,
        logged_in=authenticated_userid(request),
    )
示例#2
0
def _need():
    bootstrap.need()