<s> """<STR_LIT>""" <EOL> from django import forms <EOL> from django . utils . translation import ugettext as _ , ugettext_lazy <EOL> from passwords . fields import PasswordField <EOL> from modoboa . core . models import User <EOL> from modoboa . lib import parameters <EOL> class LoginForm ( forms . Form ) : <EOL> """<STR_LIT>""" <EOL> username = forms . CharField ( <EOL> label = ugettext_lazy ( "<STR_LIT>" ) , <EOL> widget = forms . TextInput ( attrs = { "<STR_LIT:class>" : "<STR_LIT>" } ) <EOL> ) <EOL> password = forms . CharField ( <EOL> label = ugettext_lazy ( "<STR_LIT>" ) , <EOL> widget = forms . PasswordInput ( attrs = { "<STR_LIT:class>" : "<STR_LIT>" } ) <EOL> ) <EOL> rememberme = forms . BooleanField ( <EOL> initial = False , <EOL> required = False <EOL> ) <EOL> class ProfileForm ( forms . ModelForm ) : <EOL> """<STR_LIT>""" <EOL> oldpassword = forms . CharField ( <EOL> label = ugettext_lazy ( "<STR_LIT>" ) , required = False , <EOL> widget = forms . PasswordInput ( attrs = { "<STR_LIT:class>" : "<STR_LIT>" } ) <EOL> ) <EOL> newpassword = PasswordField ( <EOL> label = ugettext_lazy ( "<STR_LIT>" ) , required = False , <EOL> widget = forms . PasswordInput ( attrs = { "<STR_LIT:class>" : "<STR_LIT>" } ) <EOL> ) <EOL> confirmation = PasswordField ( <EOL> label = ugettext_lazy ( "<STR_LIT>" ) , required = False , <EOL> widget = forms . PasswordInput ( attrs = { "<STR_LIT:class>" : "<STR_LIT>" } ) <EOL> ) <EOL> class Meta : <EOL> model = User <EOL> fields = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> widgets = { <EOL> '<STR_LIT>' : forms . TextInput ( attrs = { '<STR_LIT:class>' : '<STR_LIT>' } ) , <EOL> '<STR_LIT>' : forms . TextInput ( attrs = { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> } <EOL> def __init__ ( self , update_password , * args , ** kwargs ) : <EOL> super ( ProfileForm , self ) . __init__ ( * args , ** kwargs ) <EOL> if not update_password : <EOL> del self . fields [ "<STR_LIT>" ] <EOL> del self . fields [ "<STR_LIT>" ] <EOL> del self . fields [ "<STR_LIT>" ] <EOL> def clean_oldpassword ( self ) : <EOL> if self . cleaned_data [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> return self . cleaned_data [ "<STR_LIT>" ] <EOL> if parameters . get_admin ( "<STR_LIT>" ) != "<STR_LIT>" : <EOL> return self . cleaned_data [ "<STR_LIT>" ] <EOL> if not self . instance . check_password ( self . cleaned_data [ "<STR_LIT>" ] ) : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return self . cleaned_data [ "<STR_LIT>" ] <EOL> def clean_confirmation ( self ) : <EOL> newpassword = self . cleaned_data [ "<STR_LIT>" ] <EOL> confirmation = self . cleaned_data [ "<STR_LIT>" ] <EOL> if newpassword != confirmation : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return self . cleaned_data [ "<STR_LIT>" ] <EOL> def save ( self , commit = True ) : <EOL> user = super ( ProfileForm , self ) . save ( commit = False ) <EOL> if commit : <EOL> if self . cleaned_data . get ( "<STR_LIT>" , "<STR_LIT>" ) != "<STR_LIT>" : <EOL> user . set_password ( <EOL> self . cleaned_data [ "<STR_LIT>" ] , <EOL> self . cleaned_data [ "<STR_LIT>" ] <EOL> ) <EOL> user . save ( ) <EOL> return user <EOL> class APIAccessForm ( forms . Form ) : <EOL> """<STR_LIT>""" <EOL> enable_api_access = forms . BooleanField ( <EOL> label = _ ( "<STR_LIT>" ) , required = False ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> user = kwargs . pop ( "<STR_LIT:user>" ) <EOL> super ( APIAccessForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ "<STR_LIT>" ] . initial = hasattr ( user , "<STR_LIT>" ) </s>
