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


Python forms.LoginForm类代码示例

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


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

示例1: login

def login(request):
	if request.user.is_authenticated():
		return redirect(reverse('home'))

	_request = None
	if request.method == 'POST':
		_request = request.POST.copy()
	else:
		_request = request.GET.copy()

	next_uri = _request.get('next', get_config('LOGIN_REDIRECT_URL',
		reverse('home')))
	# rescuing poor users from infinite redirection loop
	if next_uri == get_config('LOGIN_URL', reverse('login')):
		next_uri = get_config('LOGIN_REDIRECT_URL', reverse('home'))

	login_form = LoginForm()

	if request.method == 'POST':
		login_form = LoginForm(request.POST)
		if login_form.is_valid() and login_form.user:
			auth_login(request, login_form.user)
			messages.success(request, "Hello, {0}.".format(login_form.user))
			badges.possibly_award_badge("logged_in",
				user=login_form.user)
			return redirect(next_uri)

	return {
		'login_form': login_form,
		'next': next_uri,
	}
开发者ID:SushiTee,项目名称:teerace,代码行数:31,代码来源:views.py

示例2: login

def login(request):
	template = 'accounts/login.html'
	if request.user.is_authenticated():
		return HttpResponseRedirect(reverse('accounts:index'))
	else:
		if request.method == 'POST':
			form = LoginForm(request.POST)
			if form.is_valid():
				username = request.POST['login']
				password = request.POST['password']
				user = auth.authenticate(username=username, password=password)
				if user is not None:
					auth.login(request, user)					
					return HttpResponseRedirect(reverse('saisie:index'))
				else:
					return render(request, template, {
						'form': form,
						'error': 'La connexion a échouée.',
					})
			else:
				return render(request, template, {
					'form': form,
					'error': 'Veuillez remplir tous les champs correctement.',
				})
		else:
			form = LoginForm()

	return render(request, template, {
		'form': form,
	})
开发者ID:maximeloizeau,项目名称:absences,代码行数:30,代码来源:views.py

示例3: LoginView

class LoginView(TemplateView):
    template_name = "signin.html"

    def __init__(self):
        super(LoginView, self).__init__()
        self.form = LoginForm()

    def get_context(self, request, *args, **kwargs):
        context = {
            'form': self.form
        }
        return context

    def get(self, request, *args, **kwargs):
        return self.render_to_response(self.get_context(request))

    def post(self, request, *args, **kwargs):
        self.form = LoginForm(request.POST)
        if self.form.is_valid():
            self.form.save()
            user = auth.authenticate(
                email=self.form.user.email,
                password=self.form.str_password
            )
            auth.login(request, user)
            del request.POST['email']
            del request.POST['password']
            return redirect('index_page')
        else:
            return self.render_to_response(self.get_context(request))
开发者ID:andruwwwka,项目名称:super5,代码行数:30,代码来源:views.py

示例4: loginview

def loginview(request):
    if request.method == 'POST':
        form=LoginForm(request.POST)
        session_cart=getCart(request)
        try:
            next= request.POST['next']
        except:
            next='/'
        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:
                if user.is_active:
                    login(request, user)
                    user_cart=getCart(request)
                    cartMerge(user_cart, session_cart)
                    request.session['cart']={}
                    return HttpResponseRedirect(next)
    else:
        if '_auth_user_id' in request.session:
            return HttpResponseRedirect('/')
        else:
            form=LoginForm()
            try:
                next= request.GET['next']
            except:
                next='/'
    return render_to_response('login_form.html',
            {'form': form,
            'next': next},
             context_instance=RequestContext(request))
开发者ID:scotfu,项目名称:M,代码行数:32,代码来源:views.py

示例5: test_empty_password

 def test_empty_password(self):
     form = LoginForm({'username': 'test', 'password': ''})
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'password': [u'This field is required.']}
     )
开发者ID:imxiaohui,项目名称:django-todolist-1,代码行数:7,代码来源:tests.py

示例6: login_request

def login_request(request):
    if request.user.is_authenticated():
        return reverse(index)
    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 redirect(reverse('create'))
            else:
                # Invalid User or Pass
                messages.add_message(request, ERROR, 'You have provided invalid login information.')
                return render(request, 'login.html', {
                    'form':form
                })
        else:
            # Blank
            messages.add_message(request, ERROR, 'Please enter correct login information.')
            return render(request, 'login.html', {
                'form':form
            })
    else:
        # No POST, Show Form
        messages.add_message(request, INFO, 'Please login below.')
        return render(request, 'login.html', {
            'form':LoginForm(),
        })
开发者ID:harshalgalgale,项目名称:leaflet-1,代码行数:30,代码来源:views.py

示例7: test_wrong_username

	def test_wrong_username(self):
		data = self.data
		data['username'] = 'toastclient'
		form = LoginForm(data)
		self.assertFalse(form.is_valid())
		self.assertEqual(form.errors['__all__'],
			["Invalid username and/or password"])
开发者ID:SushiTee,项目名称:teerace,代码行数:7,代码来源:tests.py

示例8: login

def login(request):
  """Login. Looks up by username or email address."""
  if request.user.is_authenticated():
    return HttpResponseRedirect(reverse('index'))
  next_url = None
  if request.method == 'POST':
    form = LoginForm(request.POST)
    if form.is_valid():
      user = auth.authenticate(username=request.POST['username'],
                               password=request.POST['password'])
      if not user:
        try:
          email_user = User.objects.get(
              email__exact=request.POST['username'])
          user = auth.authenticate(username=email_user.username,
                                   password=request.POST['password'])
        except User.DoesNotExist:
          user = None
      if user:
        if user.is_active:
          auth.login(request, user)
          if 'next' in request.POST:
            return HttpResponseRedirect(request.POST['next'])
          else:
            return HttpResponseRedirect(reverse('index'))
        else:
          form.errors['username'] = 'This user is not active yet, please try later.'
      else:
        form.errors['username'] = (
            'username or email address not found and/or password wrong')
  else:
    form = LoginForm()
    next_url = urllib.unquote_plus(request.GET.get('next', '')).decode('utf8')
  return render(request, 'accounts/login.html', {'login_form': form,
                                                 'next': next_url})
开发者ID:lbedford,项目名称:accounts,代码行数:35,代码来源:views.py

示例9: signin

def signin(request):
	error = []
	if request.user.is_authenticated():
		return HttpResponseRedirect('/profile/')
	if request.method =="POST":
		form = LoginForm(request.POST) #pass the form the request.post values
		if form.is_valid():
			username = form.cleaned_data['username']
			password = form.cleaned_data['password']
			userprofile = authenticate(username=username, password=password) #if passwords are valid
			if userprofile is not None: #if all went well
				if userprofile.is_active:
					login(request, userprofile) #login the request as this particular user
					return HttpResponseRedirect('/a/profile/')
				else:
					errors.append('User %s is disabled' % userprofile.username)
			else:
				error.append('Username and password combination did not match.')
				return render_to_response('accounts/login.html', {'form':form, 'error':error}, context_instance=RequestContext(request)) #wrong credentials, go back and look at errors
		else:
			return render_to_response('accounts/login.html', {'form':form}, context_instance=RequestContext(request))
				
			
			
			
	else:
		""" nothing has been done, show the form"""
		form = LoginForm()
		context = {'form': form, 'errors':error,}
		return render_to_response('accounts/login.html', context, context_instance=RequestContext(request))
开发者ID:FrantzdyRomain,项目名称:peekd-django-project,代码行数:30,代码来源:views.py

示例10: mylogin

def mylogin(request):
	form = LoginForm(request.POST or None)
	
	if form.is_valid():
		username = form.cleaned_data['username']
		password = form.cleaned_data['password']
		
		try :
			the_user = MyUser.objects.get(username=username)
			user = authenticate(username=the_user.username,password=password)
		except :
			user = None

		if user is not None:

			# user = authenticate(username=the_user.username,password=password)

			if user.is_active:
				login(request,user)
				messages.success(request, 'Vous êtes maintenant connecté')	

			else:
				messages.success(request, "Votre compte est en attente d'activation")
				pass
		else:
			return redirect('/register/')

	context = {'form':form}
	return render(request,"registration/login.html",context)
开发者ID:rogilesor,项目名称:myBlog,代码行数:29,代码来源:views.py

示例11: view_account

def view_account(request):
    if request.method != 'POST':
        return HttpResponse(json.dumps({'success': False, 'message': 'POST requests only'}), mimetype='application/json')
    form = LoginForm(request.POST)

    if not form.is_valid():
        return HttpResponse(json.dumps({'success': False, 'message': form.errors}), mimetype='application/json')

    email = form.cleaned_data.get('email', None)
    password = form.cleaned_data.get('password', None)
    create = form.cleaned_data.get('create', False)

    if email is None or password is None:
        return HttpResponse(json.dumps({'success': False, 'message': 'Missing required parameters email or password'}), mimetype='application/json')

    user = accounts.user_for_email(email)
    success_message = 'Login Successful'
    if user is None and create is True:
        success_message = 'Account Creation Successful'
        user = PushUser.objects.create_user(username=email, email=email, password=password)

    user = authenticate(username=email, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            return HttpResponse(json.dumps({'success': True, 'message': success_message}), mimetype='application/json')
    return HttpResponse(json.dumps({'success': False, 'message': 'Invalid Login'}), mimetype='application/json')
开发者ID:DTML,项目名称:ChatSecure-Push-Server,代码行数:27,代码来源:account.py

示例12: login

def login(request):
    login_form = LoginForm()
    register_form = RegistrationForm()
    
    next = request.REQUEST.get('next', settings.LOGIN_REDIRECT_URL)
    # Special case next urls that will lead us into redirect loops
    if next == settings.LOGIN_URL:
        next = settings.LOGIN_REDIRECT_URL
    
    if 'kind' in request.POST:
        if request.POST['kind'] == 'register':
            register_form = RegistrationForm(request.POST)
            if register_form.is_valid():
                _backend_hackend(request, register_form.save())
                return HttpResponseRedirect(next)
        elif request.POST['kind'] == 'login':
            login_form = LoginForm(request.POST)
            if login_form.is_valid() and login_form.user:
                _backend_hackend(request, login_form.user)
                return HttpResponseRedirect(next)
    context = {
        'login_form': login_form,
        'register_form': register_form,
        'next': next,
    }
    return render_to_response('accounts/login.html', context,
        context_instance=RequestContext(request))
开发者ID:ariel17,项目名称:servertail,代码行数:27,代码来源:views.py

示例13: test_too_long_username

 def test_too_long_username(self):
     form = LoginForm(self.too_long_username)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'username': [u'Ensure this value has at most 64' +
                       ' characters (it has 65).']}
     )
开发者ID:imxiaohui,项目名称:django-todolist-1,代码行数:8,代码来源:tests.py

示例14: login

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,代码行数:58,代码来源:views.py

示例15: login

def login():
    next = request.values.get('next', '/')
    form = LoginForm()
    form.next.data = next
    if form.validate_on_submit():
        session['user_id'] = unicode(form.user.pk)
        flash(u'Login successfully', 'success')
        return redirect(next)
    return render_template('accounts/login.html', form=form)
开发者ID:sdadlani311,项目名称:shivdadlani.com,代码行数:9,代码来源:views.py


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