@@ -35,7 +35,7 @@ def __init__(self, request, model, *args, **kwargs):
35
35
def clean_current_password (self ):
36
36
current_password = self .cleaned_data .get ('current_password' , '' )
37
37
if not self .request .user .check_password (current_password ):
38
- raise forms .ValidationError (_ (u'Invalid password! ' ))
38
+ raise forms .ValidationError (_ (u'Invalid password' ))
39
39
40
40
def save (self ):
41
41
if not self .user :
@@ -101,26 +101,32 @@ class QuestionForm(BasicForm):
101
101
question = forms .CharField (label = _ ('Question' ), required = True )
102
102
code = forms .CharField (label = _ ('code' ), required = True , max_length = 16 )
103
103
104
- def __init__ (self , * args , ** kwargs ):
104
+ def __init__ (self , request , * args , ** kwargs ):
105
105
self .decrypt ('code' , ** kwargs )
106
106
self .decrypt ('question' , ** kwargs )
107
- super (QuestionForm , self ).__init__ (* args , ** kwargs )
107
+ super (QuestionForm , self ).__init__ (request , * args , ** kwargs )
108
108
109
- if kwargs .get ('initial' ) or (args [2 ] and args [2 ].get ('code' )):
110
- self .fields ['code' ].widget = forms .HiddenInput ()
111
109
self .fields ['code' ].label = _ ('Answer' )
112
110
111
+ try :
112
+ UserAuthQuestion .objects .get (user = request .user )
113
+ self .fields .pop ('code' )
114
+ except UserAuthQuestion .DoesNotExist :
115
+ pass
116
+
113
117
def save (self ):
114
118
model = super (QuestionForm , self ).save ()
115
119
return model .set_data (
116
120
self .cleaned_data .get ('question' ), self .cleaned_data .get ('code' ))
117
121
118
122
119
- class PasswordCheckForm (forms .ModelForm ):
123
+ class BaseSettingsForm (forms .ModelForm ):
124
+ enabled = forms .BooleanField (label = _ ('Enabled' ), required = False )
125
+
120
126
def __init__ (self , request , * args , ** kwargs ):
121
127
self .request = request
122
128
123
- super (PasswordCheckForm , self ).__init__ (* args , ** kwargs )
129
+ super (BaseSettingsForm , self ).__init__ (* args , ** kwargs )
124
130
125
131
if CHECK_PASSWORD is True :
126
132
self .fields ['current_password' ] = forms .CharField (
@@ -129,16 +135,16 @@ def __init__(self, request, *args, **kwargs):
129
135
def clean_current_password (self ):
130
136
current_password = self .cleaned_data .get ('current_password' , '' )
131
137
if not self .request .user .check_password (current_password ):
132
- raise forms .ValidationError (_ (u'Invalid password! ' ))
138
+ raise forms .ValidationError (_ (u'Invalid password' ))
133
139
134
140
135
- class NotificationForm (PasswordCheckForm ):
141
+ class NotificationForm (BaseSettingsForm ):
136
142
class Meta :
137
143
model = UserAuthNotification
138
144
exclude = ('user' ,)
139
145
140
146
141
- class LoggingForm (PasswordCheckForm ):
147
+ class LoggingForm (BaseSettingsForm ):
142
148
class Meta :
143
149
model = UserAuthLogging
144
150
exclude = ('user' ,)
@@ -184,7 +190,7 @@ def get_status(model):
184
190
def clean_current_password (self ):
185
191
current_password = self .cleaned_data .get ('current_password' , '' )
186
192
if not self ._request .user .check_password (current_password ):
187
- raise forms .ValidationError (_ (u'Invalid password! ' ))
193
+ raise forms .ValidationError (_ (u'Invalid password' ))
188
194
189
195
def save (self ):
190
196
def set_status (model , key ):
0 commit comments