当前位置: 首页>>代码示例>>Python>>正文


Python LoginForm.get_user方法代码示例

本文整理汇总了Python中accounts.forms.LoginForm.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.get_user方法的具体用法?Python LoginForm.get_user怎么用?Python LoginForm.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在accounts.forms.LoginForm的用法示例。


在下文中一共展示了LoginForm.get_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

# 需要导入模块: from accounts.forms import LoginForm [as 别名]
# 或者: from accounts.forms.LoginForm import get_user [as 别名]
def login(request, template_name='signin.html'):
    if request.GET.get('next', None):
        request.session['POST_AUTH_URL'] = request.GET.get('next')
    if 'POST' == request.method:
        form = LoginForm(data=request.POST)
        if form.is_valid():
            auth.login(request, form.get_user())
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            if form.cleaned_data['keep_signed_in']:
                # Sessions expire in about ten years.
                request.session.set_expiry(datetime.timedelta(3650))
            else:
                # Session expires when user closes browser.
                request.session.set_expiry(0)
            if request.GET.get('ajax'):
                pass
                '''
                from utils import json
                return HttpResponse(
                    json.get_json(
                        request,
                        200,
                        ugettext(u'Login successful.'),
                        dict()
                    ),
                    content_type=json.get_response_mimetype(request)
                )
                '''
            else:
                return accounts.post_auth_redirect(request)
        else:
            if request.GET.get('ajax'):
                pass
                '''
                from utils import json
                return HttpResponse(
                    json.get_json(
                        request,
                        403,
                        ugettext(u'Authentication Failed. Access forbidden.'),
                        dict()
                    ),
                    content_type=json.get_response_mimetype(request)
                )
                '''
    else:
        form = LoginForm()

    context = dict(
        form=form
    )

    return render_to_response(
        template_name,
        context,
        context_instance=RequestContext(request)
    )
开发者ID:bloodpet,项目名称:PalsUnli,代码行数:60,代码来源:views.py

示例2: post

# 需要导入模块: from accounts.forms import LoginForm [as 别名]
# 或者: from accounts.forms.LoginForm import get_user [as 别名]
	def post(self, request):
		form = LoginForm(request.POST)
		if form.is_valid():
			user = form.get_user()
			if not user:
				return redirect('login')
			login(request, user)
			return redirect('dashboard:home')
		else:
			context = {'form': form}
			return render(request, 'dashboard/utility/login.html', context)
开发者ID:chicanymous,项目名称:migrawatch-mono,代码行数:13,代码来源:views.py

示例3: login_page

# 需要导入模块: from accounts.forms import LoginForm [as 别名]
# 或者: from accounts.forms.LoginForm import get_user [as 别名]
def login_page(request):
    if request.method == 'POST':
        redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '/')
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            login(request, login_form.get_user())
            print redirect_to
            return HttpResponseRedirect(redirect_to)
    login_form = LoginForm()
    return render_to_response("login_page.html", context_instance=RequestContext(
                request, {
                    "action": "login",
                    "form": login_form,
                    "errors": login_form.errors.values()
                }))
开发者ID:demonkit,项目名称:framework_test,代码行数:17,代码来源:views.py


注:本文中的accounts.forms.LoginForm.get_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。