• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python forms.LoginForm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: post

    def post(self, request):
        error_messages = []
        # # # Esto peta cuando cambiamos el name de l formulario
        # # username = request.POST['usr']
        # # password = request.POST['pwd']
        # username = request.POST.get('usr')
        # password = request.POST.get('pwd')
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('usr')
            password = form.cleaned_data.get('pwd')
            user = authenticate(username=username, password=password)
            if user is None:
                error_messages.append("Nombre de usuario o contraseña incorrectos")
            else:
                if user.is_active:
                    lojin(request, user)
                    return redirect(request.GET.get("next", 'photos_home'))
                else:
                    error_messages.append("El usuario no está activo")

        context = {
            'errors': error_messages,
            'login_form': form
        }
        return render(request, 'users/login.html', context)
开发者ID:snooze6,项目名称:django-example,代码行数:26,代码来源:views.py


示例2: logon

def logon(request):
    d = {}
    d["url"] = "/login"
    d["sub"] = "Login"
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            user = authenticate(username=username,password=password)
            if user is not None:
                login(request,user)
                return HttpResponseRedirect("/")
            else:
                d["form"] = form
                d["text"] = "Invalid login credentials"
                return render(request,"register.html",d)


        else:
            d["form"] = form
            return render(request,"register.html",d)

    else:
        d["form"] = LoginForm()
        return render(request,"register.html",d)
开发者ID:aswinm,项目名称:assigneval,代码行数:26,代码来源:views.py


示例3: login_user

def login_user(request):
    """Verify user login and password work."""
    msg = []
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect(reverse('users.user_page',
                                                args=[request.user.username]))
                else:
                    msg.append("You have entered a disabled account")
                    return jingo.render(request, 'users/login.html',
                                       {'errors': msg, 'form': form})
        else:
            msg.append("Invalid form")
            return jingo.render(request, 'users/login.html',
                               {'errors': msg, 'form': form})
    else:
        form = LoginForm()
    return jingo.render(request, 'users/login.html',
                       {'errors': msg, 'form': form})
开发者ID:sowink,项目名称:sowink-interns,代码行数:26,代码来源:views.py


示例4: users_login

def users_login(request):
  page_title = "Randora Login"
  form = LoginForm(request.POST or None)
  errors = []

  context = {
    "page_title": page_title,
    "form": form,
    "errors": errors,
  }

  if request.user.is_authenticated():
    return HttpResponseRedirect(reverse('profile', kwargs={'username': request.user.username}))

  if request.method == 'POST':
    if form.is_valid():
      username = request.POST['username']
      password = request.POST['password']
      user = authenticate(username=username, password=password)
      if user:
        if user.is_active:
          login(request,  user)
          return HttpResponseRedirect(reverse('profile', kwargs={'username': request.user.username}))
        else:
          errors.append("Your account has been disabled.")
          return render(request, 'users_login.html', context)
      else:
        errors.append("Invalid login.")
        return render(request, 'users_login.html', context)
  else:
    return render(request, 'users_login.html', context)
开发者ID:jayands,项目名称:randora_website,代码行数:31,代码来源:views.py


示例5: login

def login(request):
    if request.POST:
        form = LoginForm(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)
                    #resp = {'response': 'Ok'}
                    resp = {'code': 0}
                    resp = json.dumps(resp)
                    return HttpResponse(resp, content_type='application/json')
                else:
                    #resp = {'response': 'fail', 'error': u"Этот аккаунт еще не активирован"}
                    resp = {'code': 1, 'error': u"Этот аккаунт еще не активирован"}
                    resp = json.dumps(resp)
                    return HttpResponse(resp, content_type='application/json')
            else:
                resp = {'code': 2, 'error': u"Неправильный пароль или логин"}
                resp = json.dumps(resp)
                return HttpResponse(resp, content_type='application/json')
    form = LoginForm()
    return render(request, "signin.html", {'form': form})
开发者ID:bucherok,项目名称:Clap-1,代码行数:25,代码来源:views.py


示例6: post

    def post(self, request):
        error_messages = []

        form = LoginForm(request.POST)

        #con esto se valida que los datos cumplan con lo que se especifica en el modelo
        if form.is_valid():

            username = form.cleaned_data.get('usr')
            password = form.cleaned_data.get('pwd')

            user = authenticate(username=username, password=password)

            if user is None:
                error_messages.append('Nombre de usuario o contraseña incorrecta')
            else:
                if user.is_active:
                    django_login(request, user)
                    return redirect('posts_home')
                else:
                    error_messages.append('El usuario no está activo')
            context = {
                'errors': error_messages,
                'login_form': form
            }
            return render(request, 'users/login.html', context)
开发者ID:a-rodriguez296,项目名称:Django-Homework,代码行数:26,代码来源:views.py


示例7: vista_login

def vista_login(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('items:items'))
    else:
        if request.method=='POST':
            form=LoginForm(request.POST)
            if form.is_valid():
                username=form.cleaned_data['username']
                password=form.cleaned_data['password']
                seguent=request.GET.get('next',default=None)
                user=authenticate(username=username,password=password)
                if user is not None:
                    if user.is_active:
                        login(request,user)
                        if bool(seguent):
                            return HttpResponseRedirect(seguent)
                        else:
                            return HttpResponseRedirect(reverse('items:items'))
                    else:
                        messages.error(request,'Usuari desactivat')
                        return HttpResponseRedirect(reverse('login'))
                else:
                    messages.error(request,'Error, usuari i/o contrasenya són/és incorrectes/e/a')
                    return HttpResponseRedirect(reverse('login'))
            else:
                messages.error(request,'Hi ha errors en el formulari')
        else:
            form=LoginForm()

    form.helper=FormHelper()
    form.helper.form_class='form-horizontal'
    form.helper.add_input(Submit('submit','Login'))

    return render(request,'forms/login.html',{'form':form})
开发者ID:Riusses,项目名称:SunDos,代码行数:34,代码来源:views.py


示例8: login_form

def login_form(request):
	errmsg = ""
	try: prevpage = smart_unicode(request.GET["next"])
	except KeyError: prevpage = "/"
	if request.method == "POST":
		form = LoginForm(request.POST)
		if form.is_valid():
			user = authenticate(
				username=form.cleaned_data["username"],
				password=form.cleaned_data["password"],
			)
			if form.cleaned_data["prevpage"] == "login":
				prevpage = "/"
			else:
				prevpage = form.cleaned_data["prevpage"]
			if user is not None:
				if user.is_active:
					login(request, user)
					return HttpResponseRedirect(prevpage)
				else:
					errmsg = "User is disabled"
		else:
			errmsg = "Invalid username/password"
	else:
		form = LoginForm(initial=dict(prevpage=prevpage))

	return render_to_response("users/login.html", {
		"errmsg":	errmsg,
		"form":		form,
	}, context_instance=RequestContext(request))
开发者ID:r3boot,项目名称:blacklist,代码行数:30,代码来源:views.py


示例9: post

    def post(self, request):
        error_messages = []


        form = LoginForm(request.POST)

        if form.is_valid():
            #forma segura de acceder a claves en un diccionario. Nunca acceder a un diccionario con la sintaxis de corchetes. POST['usr']
            username = form.cleaned_data.get('usr')
            password = form.cleaned_data.get('pwd')

            user = authenticate(username=username, password=password)

            if user is None:
                error_messages.append('Nombre de usuario o contraseña incorrecto')
            else:
                if user.is_active:
                    django_login(request, user)
                    return redirect('photos_home')
                else:
                    error_messages.append('El usuario no esta activo')
        context = {
            'errors': error_messages,
            'login_form': form
        }
        return render(request, 'users/login.html', context)
开发者ID:a-rodriguez296,项目名称:Django-Tutorial,代码行数:26,代码来源:views.py


示例10: post

    def post(self, request):
        error_messages = []

        # Using form instade of direct request.POST
        # username = request.POST.get('usr', '')
        # password = request.POST.get('pwd', '')
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('usr')
            password = form.cleaned_data.get('pwd')

            user = authenticate(username=username, password=password)
            if user is None:
                error_messages.append('Nombre de usuario o clave incorrectos')
            else:
                if user.is_active:
                    django_login(request, user)
                    return redirect(request.GET.get('next','photos_home'))
                else:
                    error_messages.append('El usuario no esta activo')

        context = {
            'errors': error_messages,
            'login_form': form
        }
        return render(request, 'users/login.html', context)
开发者ID:krainet,项目名称:Frikr,代码行数:26,代码来源:views.py


示例11: post

    def post(self, request):
        error_message = []
        form = LoginForm()
        # paso al formulario los datos con la petición.
        form = LoginForm(request.POST)

        if form.is_valid():

            # recupero los datos del usuario del formulario. en cleaned_data, tengo los campos normalizados.
            username = form.cleaned_data.get('usr')
            password = form.cleaned_data.get('pwd')

            # busco el usuario, si existe, me devuelve el usuario o un nulo en caso de que no lo encuentre.
            user = authenticate(username=username, password=password)
            if user is None:
                error_message.append('El usuario o la contraseña es incorrecta')
            else:
                if user.is_active:
                    # El usuario existe y está activo así que lo autentifico.
                    django_login(request, user)
                    # Por si he llegado al login desde una pagina que usa el decorador, me voy donde
                    # me indica el parametro 'next'
                    return redirect(request.GET.get('next', 'home'))
                else:
                    error_message.append('El usuario no está activo')

        context = {
            'errors': error_message,
            'login_form': form
        }
        return render(request, 'users/login.html', context)
开发者ID:walnow78,项目名称:wordplese,代码行数:31,代码来源:views.py


示例12: hello

def hello(request, template="users/login.html"):
    cc = {}

    login_form = LoginForm()
    registration_form = RegistrationForm()

    if request.method == "POST" and "login_submit" in request.POST:
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            user = authenticate(
                username=login_form.cleaned_data["username"], password=login_form.cleaned_data["password"]
            )
            login(request, user)
            messages.add_message(request, messages.SUCCESS, "Zostałeś zalogowany.")
            if "next" in request.GET:
                return HttpResponseRedirect(request.GET["next"])
            else:
                return HttpResponseRedirect(reverse("index"))
    elif request.method == "POST" and "registration_submit" in request.POST:
        registration_form = RegistrationForm(request.POST)
        if registration_form.is_valid():
            user_profile = registration_form.save()
            user = authenticate(
                username=registration_form.cleaned_data["username"],
                password=registration_form.cleaned_data["password1"],
            )
            # send_registration_mail(request.LANGUAGE_CODE, registration_form.cleaned_data['email'], user_profile.activation_key)
            return registered(request)

    cc["login_form"] = login_form
    cc["registration_form"] = registration_form
    return render(request, template, Context(cc))
开发者ID:fjern,项目名称:piosenka,代码行数:32,代码来源:views.py


示例13: test_user_submits_invalid_data

 def test_user_submits_invalid_data(self):
     from users.forms import LoginForm
     for email in ('[email protected]', '[email protected]'):
         form = LoginForm({'email': email, 'password': 'empty'})
         self.assertFalse(form.is_valid())
         self.assertTrue(form.errors)
         self.assertTrue(form.errors.get('email'))
开发者ID:harivenkata,项目名称:glodata,代码行数:7,代码来源:users_forms_tests.py


示例14: index

def index(request):
    if request.method == 'POST':
        if 'register_form' in request.POST:
            user_register = UserRegisterForm(request.POST)
            if user_register.is_valid():
                User.objects.create_user(username=user_register.cleaned_data['username'],
                                             email=user_register.cleaned_data['email'],
                                             password=user_register.cleaned_data['password'],
                                           #tipo=user_register.cleaned_data['tipo'],
                                         )
                LogIn(request, user_register.cleaned_data['username'],
                          user_register.cleaned_data['password'])
                return redirect('home')
        if 'login_form' in request.POST:
            login_form = LoginForm(request.POST)
            if login_form.is_valid():
                LogIn(request, login_form.cleaned_data['username'],
                                   login_form.cleaned_data['password'])
                user = User.objects.get(username = login_form.cleaned_data['username'])
                #user = User.objects.filter(request.user.username == login_form.cleaned_data['username'])
                return redirect('/')

    user_register = UserRegisterForm()
    login_form = LoginForm()
    return render(request, 'index.html', {'user_register': user_register, 'login_form': login_form })
开发者ID:AlejandroGA,项目名称:SRTodo001,代码行数:25,代码来源:views.py


示例15: login_view

def login_view(request):
    url = '/login'
    sub='Login'
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            em = form.cleaned_data['username']
            pwd = form.cleaned_data['password']
            user =  authenticate(
                username=em,
                password=pwd
            )
            if user is not None and user.is_active:
                u = OjUser.objects.get(username=user.username)
                if u.is_loggedin:
                    text = 'This user is already logged in'
                    return render(request,'register.html',{'sub':sub,'url':url,'form':LoginForm(),'text':text})

                login(request,user)
                u.is_loggedin = True
                u.save()
                return HttpResponseRedirect('/')
            else:
                text='Email and password do not match'
		return render(request,"register.html",{'form':LoginForm(),'text':text,'url':url,'sub':sub})
        else:

            return render(request,'register.html',{'url':url,'form':form,'sub':sub})
    else:
		   return render(request,'register.html',{'url':url,'form':LoginForm(),'sub':sub})
开发者ID:aswinm,项目名称:onlinejudge,代码行数:30,代码来源:views.py


示例16: user_login

def user_login(request):
    if request.method == 'POST':
        form = LoginForm(data=request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['username'],
                                email=form.cleaned_data['email'],
                                password=form.cleaned_data['password'],
                                )
            if user is not None:
                if user.is_active:
                    login(request, user)
                    print("%s, %s, %s" %(user.username, user.email, user.password))
                    cursor = connection.cursor()
                    if Manager.objects.filter(
                            manager__email=user.email).exists():
                        return redirect('/manager/')
                    if Bartender.objects.filter(
                            bartender__email=user.email).exists():
                        return redirect('/bartender/')
                    if Waiter.objects.filter(
                            waiter__email=user.email).exists():
                        return redirect('/waiter/')

                else:
                    return redirect("/logout/")

            else:
                return redirect("/logout/")

    else:
        form = LoginForm(data=request.POST)
    variables = RequestContext(request, {'form': form})

    return render_to_response('login_form.html', variables,)
开发者ID:irin4eto,项目名称:Bar-Management,代码行数:34,代码来源:views.py


示例17: index

def index(request):
    if request.method == 'POST':
        if 'myForm' in request.POST:
            user_register = UserRegisterForm(request.POST)
            if user_register.is_valid():
                User.objects.create_user(username=user_register.cleaned_data['username'],
                                             email=user_register.cleaned_data['email'],
                                             password=user_register.cleaned_data['password'])
                LogIn(request, user_register.cleaned_data['username'],
                          user_register.cleaned_data['password'])
                return redirect('home')
        if 'login_form' in request.POST:
            login_form = LoginForm(request.POST)
            if login_form.is_valid():
                LogIn(request, login_form.cleaned_data['username'],
                                   login_form.cleaned_data['password'])
                user = User.objects.get(username = login_form.cleaned_data['username'])
                #user = User.objects.filter(request.user.username == login_form.cleaned_data['username'])
                return redirect('/')
    # casas = Casas.objects.order_by('fecha_publicacion')[:3]
    # bodegas = Bodega.objects.order_by('fecha_publicacion')[:3]
    # inflables = Inflable.objects.order_by('fecha_publicacion')[:3]
    # combis = Combi.objects.order_by('fecha_publicacion')[:3]



    user_register = UserRegisterForm()
    login_form = LoginForm()
    return render(request, 'index.html', {'user_register': user_register, 'login_form': login_form})
开发者ID:dafma,项目名称:STR,代码行数:29,代码来源:views.py


示例18: view_login

def view_login(request, login_template, next=''):
    if request.method == 'POST':
        data = post_data(request)
        next = data.get('next') if not next else next 
        form = LoginForm(data)
        if form.is_valid():
            try:
                userprofile = UserProfile.objects.get(user__email=form.cleaned_data.get('email'),
                                                      user__is_active=True)
            except UserProfile.DoesNotExist:
                #from users.messages import USER_LOGIN_FAILURE
                #messages.error(request, USER_LOGIN_FAILURE)
                return response(request, login_template, {'form': form, 'next': next})
            if not userprofile.check_password(form.cleaned_data.get('password')):
                #from users.messages import USER_LOGIN_FAILURE
                #messages.error(request, USER_LOGIN_FAILURE)
                return response(request, login_template, {'form': form, 'next': next})
            #from users.messages import USER_LOGIN_SUCCESSFUL
            #messages.success(request, USER_LOGIN_SUCCESSFUL)
            return _let_user_login(request,
                                   userprofile.user,
                                   email=form.cleaned_data.get('email'),
                                   password=form.cleaned_data.get('password'),
                                   next=next)
    else:
        form = LoginForm()
    return response(request, login_template, {'form': form, 'next': next})
开发者ID:none-da,项目名称:iamtheresume,代码行数:27,代码来源:views.py


示例19: login

def login(request):
    login_form = LoginForm()
    register_form = RegistrationForm()
    next = request.REQUEST.get('next')
    if 'kind' in request.POST:
        if request.POST['kind'] == 'login':
            login_form = LoginForm(request.POST)
            if login_form.is_valid():
                username = login_form.get_username()
                request.session['username'] = username
                if next:
                    return HttpResponseRedirect(next)
                return HttpResponseRedirect('/')
        elif request.POST['kind'] == 'register':
            register_form = RegistrationForm(request.POST)
            if register_form.is_valid():
                username = register_form.save()
                request.session['username'] = username
                if next:
                    return HttpResponseRedirect(next)
                return HttpResponseRedirect('/')
    context = {
        'login_form': login_form,
        'register_form': register_form,
        'next': next,
    }
    return render_to_response(
        'users/login.html', context, context_instance=RequestContext(request))
开发者ID:Mondego,项目名称:pyreco,代码行数:28,代码来源:allPythonContent.py


示例20: login

def login(request):
    msg = None
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            mail = form.cleaned_data['email']
            password = form.cleaned_data['password']
            u = User.objects.filter(email=mail)

            if not u:
                msg = 'This email ID has not been registered'
            else:
                u = u[0]
                if u.password != password:
                    msg = 'Password does not match'
                else:
                    if u.blocked:
                        msg = 'You have already registered but not confirmed yet'
                    else:
                        set_session(request, u)
                        return HttpResponseRedirect(request.GET.get('next', '/'))
    else:
        form = LoginForm()

    return render_to_response('users/login.html', {'name': 'Login', 'list': menu, 'form': form, 'msg': msg, }, context_instance=RequestContext(request))
开发者ID:axitkhurana,项目名称:edc,代码行数:25,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python forms.ProfileForm类代码示例发布时间:2022-05-27
下一篇:
Python forms.AuthenticationForm类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap