def login1(request,form_class=RegistrationFormUniqueEmail,template_name='registration/registration_form.html',extra_context=None):
   lform = LoginForm() 
   rform = RegistrationFormUniqueEmail()


   if request.method == 'POST':	
	lform = LoginForm(data=request.POST, files=request.FILES)
	if lform.is_valid():
		user = authenticate(username=lform.cleaned_data['login'], password=lform.cleaned_data['password'])
		if user is None:
			try:
				username=User.objects.get(email=lform.cleaned_data['login']).username
				user = authenticate(username=username, password=lform.cleaned_data['password'])	
			except:
				lform.non_field_errors="Your username or password was incorrect."
	
		if user is not None:           	   
		   if user.is_active: 						
				login(request,user)						
				return HttpResponseRedirect('/')
							
   if extra_context is None:
       extra_context = {}
   context = RequestContext(request)
   for key, value in extra_context.items():
        context[key] = callable(value) and value() or value
         
   return render_to_response(template_name, {'rForm':rform,'lForm':lform,'next':next},context_instance=context )
Exemple #2
0
def login1(request,
           form_class=RegistrationFormUniqueEmail,
           template_name='registration/registration_form.html',
           extra_context=None):
    lform = LoginForm()
    rform = RegistrationFormUniqueEmail()

    if request.method == 'POST':
        lform = LoginForm(data=request.POST, files=request.FILES)
        if lform.is_valid():
            user = authenticate(username=lform.cleaned_data['login'],
                                password=lform.cleaned_data['password'])
            if user is None:
                try:
                    username = User.objects.get(
                        email=lform.cleaned_data['login']).username
                    user = authenticate(
                        username=username,
                        password=lform.cleaned_data['password'])
                except:
                    lform.non_field_errors = "Your username or password was incorrect."

            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect('/')

    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value

    return render(request,
                  template_name=template_name,
                  context={
                      'rForm': rform,
                      'lForm': lform,
                      'next': next
                  })