here i guess i wrote Every thing to be able to log in by mail but it's
not working is there something missing please? and
AUTHENTICATION_BACKENDS = (
'mayapp.backends.EmailAuthBackend',
'django.contrib.auth.backends.ModelBackend'
)


backends.py


from django.conf import settings
from django.contrib.auth.backends import ModelBackend
from django.core.validators import email_re
from django.contrib.auth.models import User, check_password

# Overwrite the default backend to check for e-mail address
class EmailAuthBackend(object):
    """
    Email Authentication Backend

    Allows a user to sign in using an email/password pair rather than
    a username/password pair.
    """

    def authenticate(self, username=None, password=None):
        """ Authenticate a user based on email address as the user
name. """
        try:
            user = User.objects.get(email=username)
            if user.check_password(password):
                return user
        except User.DoesNotExist:
            return None

    def get_user(self, user_id):
        """ Get a User object from the user_id. """
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None


views.py



def login_user(request):
        state = "Please log in below..."
        username = password = ''
        if request.POST:
                if 'login' in request.POST:
                        username = request.POST.get('username')
                        password = request.POST.get('password')

                        user = authenticate(username=username, 
password=password)
                        if user is not None:
                                if user.is_active:
                                        login(request, user)
                                        state = "You're successfully logged in!"

                                        return 
render_to_response('master.html',RequestContext(request))
                                else:
                                        state = "Your account is not active, 
please contact the site
admin."
                        else:
                                state = "Your username and/or password were 
incorrect."
                elif 'signup' in request.POST:
                        form= SignUpForm()
                        context = {'form':form}
                        return
render_to_response('Sign_up_Employer.html',context,context_instance=RequestContext(request))



        return render_to_response('login.html',{'state':state, 'username':
username},RequestContext(request))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to