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)
def GET(self): if is_logined(): raise web.seeother('/') redirect_url = "" data = web.input() if 'redirect_to' in data: redirect_url = data.redirect_to form = login_form() req = web.ctx.req req.update({ 'form': form, 'redirect_url': redirect_url, }) return render.login(**req)