本文整理汇总了Python中forms.LoginForm.get_form方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.get_form方法的具体用法?Python LoginForm.get_form怎么用?Python LoginForm.get_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.get_form方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import get_form [as 别名]
def login(request):
FORM_TITLE = _('Login')
localizer = get_localizer(request)
main = get_renderer(BASE_TEMPLATE).implementation()
login_form = LoginForm.get_form(localizer)
login_url = route_url('users.login', request)
referrer = request.url
if referrer == login_url:
referrer = route_url('staff.panel', request)
b64_caller = request.params.get('caller', None)
caller = base64.b64decode(b64_caller) if b64_caller is not None else referrer
if request.method == 'POST':
controls = request.POST.items()
try:
appstruct = login_form.validate(controls)
except deform.ValidationFailure, e:
return {'content':e.render(),
'main':main,
'form_stuff':{'form_title':FORM_TITLE},
'user':get_logged_user(request),
}
try:
user = request.rel_db_session.query(users.User).filter_by(username=appstruct['username']).one()
except NoResultFound:
request.session.flash(_("Username doesn't exist."))
else:
if SHA256.new(appstruct['password']).hexdigest() == user.password:
if not user.is_active:
request.session.flash(_("The username is not active. Check your email account for the activation instructions."))
else:
headers = remember(request, user.id)
return HTTPFound(location=caller, headers=headers)
else:
request.session.flash(_("Username/password doesn't match"))
示例2: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import get_form [as 别名]
def login(request):
FORM_TITLE = "Login"
localizer = get_localizer(request)
main = get_renderer(BASE_TEMPLATE).implementation()
login_form = LoginForm.get_form(localizer)
if "submit" in request.POST:
controls = request.POST.items()
try:
appstruct = login_form.validate(controls)
except deform.ValidationFailure, e:
return {"content": e.render(), "main": main, "form_title": FORM_TITLE, "user": get_user(request)}
try:
user = request.dbsession.query(User).filter_by(username=appstruct["username"]).one()
except NoResultFound:
request.session.flash(u"Username doesnot exist.")
return {
"content": login_form.render(appstruct),
"main": main,
"form_title": FORM_TITLE,
"user": get_user(request),
}
if SHA256.new(appstruct["password"]).hexdigest() == user.password:
headers = remember(request, user.id)
return HTTPFound(location="/", headers=headers)
else:
request.session.flash(u"Username/password doesnot match.")
return {
"content": login_form.render(appstruct),
"main": main,
"form_title": FORM_TITLE,
"user": get_user(request),
}