Exemplo n.º 1
0
    def POST(self):
        form = login_form()
        if not form.validates():
            return render.login(form=form)
        data = web.input()
        errcode, user = authenticate(data.username, data.password)
        req = web.ctx.req
        if errcode != ERR_OK:
            if errcode == ERR_USER_NOTEXISTS:
                req.err(u'用户未注册')
            elif errcode == ERR_PASSWORD_NOTCORRECT:
                req.err(u'密码错误')

            if 'redirect_to' in data:
                redirect_url = data.redirect_to
            req.update({
                'form': form,
                'redirect_url': redirect_url,
                })
            return render.login(**req)
        auth_login(user)
        redirect_url = data.redirect_to
        if redirect_url:
            raise web.seeother(redirect_url)
        else:
            raise web.seeother('/', True)
Exemplo n.º 2
0
    def POST(self):
        form = login_form()
        if not form.validates():
            return render.login(form=form)
        data = web.input()
        errcode, user = authenticate(data.username, data.password)
        req = web.ctx.req
        if errcode != ERR_OK:
            if errcode == ERR_USER_NOTEXISTS:
                req.err(u'用户未注册')
            elif errcode == ERR_PASSWORD_NOTCORRECT:
                req.err(u'密码错误')

            if 'redirect_to' in data:
                redirect_url = data.redirect_to
            req.update({
                'form': form,
                'redirect_url': redirect_url,
            })
            return render.login(**req)
        auth_login(user)
        redirect_url = data.redirect_to
        if redirect_url:
            raise web.seeother(redirect_url)
        else:
            raise web.seeother('/', True)
Exemplo n.º 3
0
def admin_authenticate(username, password):
    errcode, user = authenticate(username, password)
    if user is not None and not user.is_superuser:
        return ERR_NOTSUPERUSER, user
    return errcode, user
Exemplo n.º 4
0
def admin_authenticate(username, password):
    errcode, user = authenticate(username, password)
    if user is not None and not user.is_superuser:
        return ERR_NOTSUPERUSER, user
    return errcode, user