本文整理汇总了Python中users.forms.AuthenticationForm.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python AuthenticationForm.get_user方法的具体用法?Python AuthenticationForm.get_user怎么用?Python AuthenticationForm.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.forms.AuthenticationForm
的用法示例。
在下文中一共展示了AuthenticationForm.get_user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from users.forms import AuthenticationForm [as 别名]
# 或者: from users.forms.AuthenticationForm import get_user [as 别名]
def login(request):
if request.method == 'GET':
return {'logged_in': request.user.is_authenticated()}
from users.forms import AuthenticationForm
form = AuthenticationForm(data=request.POST)
if form.is_valid():
auth_login(request, form.get_user())
return {'ok': True}
else:
return {'form_errors': form.errors}
示例2: handle_signin
# 需要导入模块: from users.forms import AuthenticationForm [as 别名]
# 或者: from users.forms.AuthenticationForm import get_user [as 别名]
def handle_signin(request):
"""Helper function that signs a user in."""
auth.logout(request)
if request.method == 'POST':
form = AuthenticationForm(data=request.POST)
if form.is_valid():
auth.login(request, form.get_user())
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
return form
request.session.set_test_cookie()
return AuthenticationForm()
示例3: handle_login
# 需要导入模块: from users.forms import AuthenticationForm [as 别名]
# 或者: from users.forms.AuthenticationForm import get_user [as 别名]
def handle_login(request, only_active=True):
if request.method == 'POST':
form = AuthenticationForm(data=request.POST, only_active=only_active)
if form.is_valid():
auth.login(request, form.get_user())
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
return form
request.session.set_test_cookie()
return AuthenticationForm()
示例4: login
# 需要导入模块: from users.forms import AuthenticationForm [as 别名]
# 或者: from users.forms.AuthenticationForm import get_user [as 别名]
def login(request):
"""Try to log the user in."""
next_url = _clean_next_url(request) or settings.LOGIN_REDIRECT_URL
if request.user.is_authenticated():
return HttpResponseRedirect(next_url)
if request.method == 'POST':
form = AuthenticationForm(data=request.POST)
if form.is_valid():
auth.login(request, form.get_user())
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
return HttpResponseRedirect(next_url)
else:
form = AuthenticationForm(request)
request.session.set_test_cookie()
return jingo.render(request, 'users/login.html',
{'form': form, 'next_url': next_url})