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


Python forms.UserLoginForm类代码示例

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


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

示例1: auth_login

def auth_login(request):
	print (request.user.is_authenticated())
	next = request.GET.get('next')
	title = "Login"
	form = UserLoginForm(request.POST or None)
	if form.is_valid():
		username = form.cleaned_data.get("username")
		password = form.cleaned_data.get('password')
		user = authenticate(username=username, password=password)
		if user is not None:
			login(request, user)
			if next:
				return HttpResponseRedirect(next)
			print (request.user.is_authenticated())

			#redirect url link comes in here
			return redirect("logged_in")
			action_url = reverse("login")
			extra_form_link = "Upgrade your account today <a href='%s'>here</a>!" %(reverse("account_upgrade"))

	context = {
		"form":form,
		"title":title,
	}
	return render(request, "form.html", context)
开发者ID:mathemartins,项目名称:python-django-blog-source-app,代码行数:25,代码来源:views.py

示例2: login

def login(request, success_url=None):

    if request.method == 'POST':

        form = UserLoginForm(request.POST)

        if form.is_valid():

            user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password'))

            if user is not None:

                auth.login(request, user)

                messages.error(request, "You have sucessfully logged in")

                return redirect(reverse('profile'))

            else:

                form.add_error(None, "Your email or password was not recognised")

    else:

        form = UserLoginForm()

    args = {'form':form}

    args.update(csrf(request))

    return render(request, 'login.html', args)
开发者ID:cdurri,项目名称:wearesocial,代码行数:31,代码来源:views.py

示例3: login

def login(request, success_url=None):



    if request.method == 'POST':

        form = UserLoginForm(request.POST)

        if form.is_valid():
            user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password'))

            if user is not None:
                auth.login(request, user)




                return redirect(profile)

            else:
                messages.error(request, "Unable to log you in! Please try again.")

                return redirect(register)

        else:

            messages.error(request, "Unable to log you in! Please try again.")

            return redirect(register)
开发者ID:ronanphiggins,项目名称:fleeky_notif,代码行数:29,代码来源:views.py

示例4: login

def login(request):
    loginForm = UserLoginForm()
    # Dealing with user authentication situation.
    if request.method == 'POST':
        loginForm = UserLoginForm(request.POST)
        context = { 'loginForm': loginForm }
        #print request.session.modified # False
        print request.user
        if loginForm.is_valid():
            username = request.POST.get('username', '')
            password = request.POST.get('password', '')
            user = auth.authenticate(username=username, password=password)
            #print request.session.modified # False
            if user is not None:
                auth.login(request, user)
                #print request.session.modified # True
                request.session.set_expiry(10)
                #print request.session.modified # True
                return redirect('player_loggedIn')
            else:
                context['playerDoesNotExist'] = 'Please check your username and/or password.'
                return render(request, 'login.html', context)
        else:
            return render(request, 'login.html', context)
    
    else:
        context = { 'loginForm': loginForm }
        return render(request, 'login.html', context)
开发者ID:tangcongyuan,项目名称:eric-django,代码行数:28,代码来源:views.py

示例5: login

def login(request):
    """
    This method checks for post method and if not displays a an empty login form. If it is a POST then the form is
    populated and checked for validity before authentication.
    :param request:
    :return:
    """
    if request.method == 'POST':
        form = UserLoginForm(request.POST)
        if form.is_valid():
            user = auth.authenticate(email=request.POST.get('email'),
                                     password=request.POST.get('password'))

            if user is not None:
                auth.login(request, user)
                messages.error(request, "You have successfully logged in")
                return redirect(reverse('profile'))
            else:
                form.add_error(None, "Your email or password was not recognised")

    else:
        form = UserLoginForm()

    args = {'form': form}
    args.update(csrf(request))
    return render(request, 'login.html', args)
开发者ID:Code-Institute-Org,项目名称:full_stack_solutions,代码行数:26,代码来源:views.py

示例6: login

def login(request, success_url=None):

    if request.user.is_authenticated():
        return redirect(reverse('profile'))

    if request.method == 'POST':
        form = UserLoginForm(request.POST)
        if form.is_valid():
            try:
                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password'))
                if user is not None:
                    auth.login(request, user)
                    messages.error(request, "You have successfully logged in")
                    return redirect(reverse('profile'))
                else:
                    subscription_not_ended = arrow.now() < arrow.get(user.subscription_end)

                    if not subscription_not_ended:
                        form.add_error(None,"Your subscription has now ended")

                    form.add_error(None,"Your email or password was not recognised")

            except SubscriptionEnded:
                form.add_error(None,"Your subscription has now ended")

    else:
        form = UserLoginForm()

    args = {'form':form}
    args.update(csrf(request))
    return render(request, 'login.html', args)
开发者ID:amcevoy83,项目名称:musichub,代码行数:32,代码来源:views.py

示例7: login_view

def login_view(request):
    next = request.GET.get("next")
    form = UserLoginForm(request.POST or None)
    title = "Login"
    if form.is_valid():
        username = form.cleaned_data.get("username")
        password = form.cleaned_data.get("password")
        user = authenticate(username=username, password=password)
        login(request, user)
        if next:
            return redirect(next)
        return redirect("/")

    context = {"form": form, "title": title}
    return render(request, "form.html", context)
开发者ID:Grass-man,项目名称:monday.api,代码行数:15,代码来源:views.py

示例8: post_list

def post_list(request): #list items #this one is for homepage
    today = timezone.now().date()
    queryset_list = Post.objects.active() #.order_by("-timestamp")
    print (request.user.is_authenticated())
    next = request.GET.get('next')
    title = "Login"
    form = UserLoginForm(request.POST or None)

    if request.user.is_staff: #or request.user.is_admin:
        queryset_list = Post.objects.all()
    paginator = Paginator(queryset_list, 1) # Show 1 blog(s) per page
    page_request_var = 'page'
    page = request.GET.get( page_request_var )
    try:
        queryset = paginator.page(page)
    except PageNotAnInteger:
    # If page is not an integer, deliver first page.
        queryset = paginator.page(1)
    except EmptyPage:
    # If page is out of range (e.g. 9999), deliver last page of results.
        queryset = paginator.page(paginator.num_pages)

    if form.is_valid():
        username = form.cleaned_data.get("username")
        password = form.cleaned_data.get('password')
        user = authenticate(username=username, password=password)
        if user is not None:
            login(request, user)
            if next:
                return HttpResponseRedirect(next)
            print (request.user.is_authenticated())

            #redirect url link comes in here
            return redirect("/")
            action_url = reverse("login")
            extra_form_link = "Upgrade your account today <a href='%s'>here</a>!" %(reverse("account_upgrade"))

    context = {
            "object_list":queryset,
            "title":"List",
            "form":form,
    		"title":title,
            "page_request_var":page_request_var,
            "today":today,
    }

    return render (request, "post_list.html", context)
开发者ID:mathemartins,项目名称:python-django-blog-source-app,代码行数:47,代码来源:views.py

示例9: login

def login(request):

    form = UserLoginForm()
    args = dict()
    args['form'] = form
    args['title'] = 'Login'

    if request.method == 'GET':
        return render(request, 'accounts/login.html', args)

    elif request.method == 'POST':
        form = UserLoginForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            user = auth.authenticate(email=email, password=password)
            if user is not None:
                if user.is_active:
                    auth.login(request, user)
                    return redirect('accounts:profile', user.pk)
                else:
                    form.add_error(None, u'Користувач заблокований')
            else:
                form.add_error(None, u'Невірний логін або пароль')
        args['form'] = form
        return render(request, 'accounts/login.html', args)
开发者ID:AlexVoitenko,项目名称:vanga,代码行数:26,代码来源:views.py

示例10: login

def login(request, success_url=None):
    if request.method == "POST":
        form = UserLoginForm(request.POST)
        if form.is_valid():
            try:
                user = auth.authenticate(email=request.POST.get("email"), password=request.POST.get("password"))

                if user is not None:
                    auth.login(request, user)
                    messages.error(request, "You have successfully logged in")

                    return redirect(reverse("profile"))
                else:
                    form.add_error(None, "Your email or password was not recognised")

            except SubscriptionEnded:
                form.add_error(None, "Your subscription has ended")

    else:
        form = UserLoginForm()

    args = {"form": form}
    args.update(csrf(request))

    return render(request, "login.html", args)
开发者ID:DarraghB1992,项目名称:wearesocial,代码行数:25,代码来源:views.py

示例11: login

def login(request):
    """Return a login page"""
    if request.user.is_authenticated:
        return redirect(reverse('index'))
    if request.method == "POST":
        login_form = UserLoginForm(request.POST)
        
        if login_form.is_valid():
            user = auth.authenticate(username=request.POST['username'],
                                        password=request.POST['password'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully logged in")
                return redirect(reverse('index'))
            else: 
                login_form.add_error(None, "Your username or password is incorrect")
    else:
        login_form = UserLoginForm()
    return render(request, 'login.html', {"login_form": login_form})
开发者ID:sarahcrosby,项目名称:djangoproject,代码行数:19,代码来源:views.py

示例12: post

 def post(request):
     login_form = UserLoginForm(request.POST, request=request)
     if login_form.is_valid():
         user = authenticate(
             username=request.POST.get('username'),
             password=request.POST.get('password'),
         )
         if NEED_CONFIRM_EMAIL and not user.is_active:
             messages.success(request, u"账号需要激活, 请登陆您的邮箱激活, 或"
                                       u"点击<a href='" + DOMAIN +
                              reverse('accounts:resend_activate',
                                      kwargs={'username': request.POST.get('username')}) +
                              u"'>这里</a>重发激活邮件")
             return HttpResponseRedirect(reverse('accounts:index'))
         auth.login(request, user)
         messages.success(request, u'登录成功')
         if 'next' in request.GET:
             return HttpResponseRedirect(request.GET.get('next'))
         return HttpResponseRedirect(reverse('accounts:index'))
     else:
         return render(request, "accounts/form_tpl.html", {"form": login_form})
开发者ID:Shellbye,项目名称:django_basic_accounts,代码行数:21,代码来源:views.py

示例13: login

def login(request, success_url=None):



    if request.method == 'POST':

        form = UserLoginForm(request.POST)

        if form.is_valid():
            user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password'))

            if user is not None:
                auth.login(request, user)

                first_login = User.objects.filter(pk=request.user.id).values_list('first_login', flat=True)

                user_first_login = first_login[0]

                if user.date_joined.date() == user.last_login.date() and user_first_login:

                    User.objects.filter(pk=request.user.id).update(first_login = False)

                    return redirect(edit_profile)

                else:

                    return redirect(profile)

            else:
                messages.error(request, "Unable to log you in! Please try again.")

                return redirect(register)

        else:

            messages.error(request, "Unable to log you in! Please try again.")

            return redirect(register)
开发者ID:ronanphiggins,项目名称:fleekydeploy,代码行数:38,代码来源:views.py

示例14: login

def login(request):
    if request.method == 'POST':
        # if submitting form create instance of form class and populate
        form = UserLoginForm(request.POST)
        if form.is_valid():  # if login form is valid
            # authenticate user:
            # 'auth' will find our class 'EmailAuth' in backends.py via the
            # backend list in settings.py and then call the authenticate method.
            user = auth.authenticate(email=request.POST.get('email'),
                                     password=request.POST.get('password'))
            if user is not None:
                auth.login(request, user)  # login user. login() is a django method. Sets up a user session.
                messages.success(request, "You have successfully logged in.")
                return redirect(reverse('profile'))
            else:
                form.add_error(None, "Your email or password is not recognised.")

    else:
        # if login link has been clicked show the empty login form
        form = UserLoginForm()

    args = {'form': form}
    args.update(csrf(request))
    return render(request, 'login.html', args)
开发者ID:peterbristow,项目名称:codeinstitute-stream-three,代码行数:24,代码来源:views.py


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