mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Work in progress: * New domains admin page, all menus are now at the same level, * Views, models and forms partial refactoring (better code organization).
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from django import forms
|
|
from modoboa.admin.models import Mailbox
|
|
from modoboa.lib import _check_password
|
|
from django.contrib.auth.models import check_password
|
|
from django.utils.translation import ugettext as _
|
|
|
|
class ChangePasswordForm(forms.Form):
|
|
oldpassword = forms.CharField(label=_("Old password"),
|
|
widget=forms.PasswordInput)
|
|
newpassword = forms.CharField(label=_("New password"),
|
|
widget=forms.PasswordInput)
|
|
confirmation = forms.CharField(label=_("Confirmation"),
|
|
widget=forms.PasswordInput)
|
|
|
|
def __init__(self, target, *args, **kwargs):
|
|
super(ChangePasswordForm, self).__init__(*args, **kwargs)
|
|
self.target = target
|
|
|
|
def clean_oldpassword(self):
|
|
if not isinstance(self.target, Mailbox):
|
|
func = check_password
|
|
else:
|
|
func = _check_password
|
|
if not func(self.cleaned_data["oldpassword"],
|
|
self.target.password):
|
|
raise forms.ValidationError(_("Old password mismatchs"))
|
|
return self.cleaned_data["oldpassword"]
|
|
|
|
def clean_confirmation(self):
|
|
if self.cleaned_data["newpassword"] != self.cleaned_data["confirmation"]:
|
|
raise forms.ValidationError(_("Passwords mismatch"))
|
|
return self.cleaned_data["confirmation"]
|