django mongoengine authenticate函数返回总是无

时间:2015-01-10 18:52:46

标签: python django mongodb authentication mongoengine

我做了一个寄存器功能,在mongodb中保存了一个新用户。但是当我尝试登录身份验证功能时,返回总是无,而且我的个人返回'无效密码'。

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())

注册工作。

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())

每次我尝试连接时,我都会收到“无效密码”。我无法确定问题出在哪里,我不知道如何调试它

以下是我的设置:

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',
)

0 个答案:

没有答案