I made a register function that save in mongodb a new user. But when I try to login authenticate function return always None and I've got my personnal return 'invalid password'.
def register(request):
if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password']
try:
user = User.objects.get(email=email)
emailUsed = True
except User.DoesNotExist:
user = User(username=username, email=email)
user.set_password(password)
user.save()
reussi = True
else:
form = UserForm()
return render(request, 'myapp/index.html', locals())
registration works.
def login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
password = form.cleaned_data['password']
user = authenticate(email=email, password=password)
if user is not None:
if user.is_active:
login(request, user)
msg = 'you are connected'
else:
msg = 'your account have been desactivate'
else:
msg = 'invalid password'
else:
form = LoginForm()
return render(request, 'myapp/login.html', locals())
Everytime I try to connect I only got 'invalid password'. I can't figure where is the problem and I don't know how to debug it
Here is my settings just in case:
import os
from mongoengine import *
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = 'g(ht#57%e&@5h=&2ge_ngzz66ji#m%d6q=ziwztnezimwjs--j'
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mongoengine.django.mongo_auth',
'myapp',
)
AUTH_USER_MODEL = 'mongo_auth.MongoUser'
MONGOENGINE_USER_DOCUMENT = 'mongoengine.django.auth.User'
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'blog.urls'
WSGI_APPLICATION = 'blog.wsgi.application'
DATABASES = {
'default': {
'ENGINE': '',
}
}
connect('tumblelog')
SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'
AUTHENTIFICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
)