<commit_before># -*- coding: utf-8 -*-
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from modoboa.lib import events
import modoboa.admin
from forms import LoginForm
from modoboa.auth.lib import *

def dologin(request):
    error = None
    if request.method == "POST":
        form = LoginForm(request.POST)
        user = authenticate(username=request.POST["username"], 
                            password=request.POST["password"])
        if user:
            if user.is_active:
                login(request, user)
            
                if request.user.id != 1:
                    request.session["password"] = <PASSWORD>(request.POST["password"])

                request.session["django_language"] = \
                    parameters.get_user(request.user, "LANG", app="general")

                events.raiseEvent("UserLogin", request=request, 
                                  username=request.POST["username"],
                                  password=request.POST["password"])

                next = request.POST["next"]
                if next == "None":
                    next = reverse(modoboa.admin.views.domains)
                return HttpResponseRedirect(next)
            else:
                error = _("Account is disabled.")
        error = _("Your username and password didn't match. Please try again.")
    else:
        form = LoginForm()
    next = request.GET.has_key("next") and request.GET["next"] or None
    return render_to_response("registration/login.html", {
            "form" : form, "error" : error, "next" : next
            }, context_instance=RequestContext(request))

def dologout(request):
    events.raiseEvent("UserLogout", request=request)
    logout(request)

    return HttpResponseRedirect(reverse(dologin))
<commit_msg>I think it should fix the problem... I was unable to reproduce it but I know it exists somewhere :-)<commit_after># -*- coding: utf-8 -*-
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from modoboa.lib import events
import modoboa.admin
from forms import LoginForm
from modoboa.auth.lib import *

def dologin(request):
    error = None
    if request.method == "POST":
        form = LoginForm(request.POST)
        user = authenticate(username=request.POST["username"], 
                            password=request.POST["password"])
        if user:
            if user.is_active:
                login(request, user)
            
                if request.user.id != 1:
                    request.session["password"] = encrypt(request.POST["password"])

                request.session["django_language"] = \
                    parameters.get_user(request.user, "LANG", app="general")

                events.raiseEvent("UserLogin", request=request, 
                                  username=request.POST["username"],
                                  password=request.POST["password"])

                next = request.POST["next"]
                if next.strip() in ["", "None"]:
                    next = reverse(modoboa.admin.views.domains)
                return HttpResponseRedirect(next)
            else:
                error = _("Account is disabled.")
        error = _("Your username and password didn't match. Please try again.")
    else:
        form = LoginForm()
    next = request.GET.has_key("next") and request.GET["next"] or None
    return render_to_response("registration/login.html", {
            "form" : form, "error" : error, "next" : next
            }, context_instance=RequestContext(request))

def dologout(request):
    events.raiseEvent("UserLogout", request=request)
    logout(request)

    return HttpResponseRedirect(reverse(dologin))

{'fraction_non_alphanumeric': 0.10473457675753228, 'fraction_numerical': 0.0009564801530368245, 'mean_word_length': 2.3041074249605056, 'pattern_counts': {'":': 3, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6364502', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1032, 'n_words': 268}