193 |
193 |
self.data._mutable = False
|
194 |
194 |
|
195 |
195 |
def clean(self):
|
196 |
|
if 'username' in self.fields or 'email' in self.fields:
|
|
196 |
if (self.instance.has_usable_password() and (
|
|
197 |
'username' in self.fields or
|
|
198 |
'email' in self.fields)):
|
197 |
199 |
if not self.cleaned_data.get('username') and \
|
198 |
200 |
not self.cleaned_data.get('email'):
|
199 |
201 |
raise forms.ValidationError(
|
... | ... | |
234 |
236 |
}
|
235 |
237 |
notification_template_prefix = \
|
236 |
238 |
'authentic2/manager/change-password-notification'
|
|
239 |
require_password = True
|
237 |
240 |
|
238 |
241 |
def clean_password2(self):
|
239 |
242 |
password1 = self.cleaned_data.get("password1")
|
... | ... | |
247 |
250 |
|
248 |
251 |
def clean(self):
|
249 |
252 |
super(UserChangePasswordForm, self).clean()
|
250 |
|
if not self.cleaned_data.get('generate_password') \
|
251 |
|
and not self.cleaned_data.get('password1') \
|
252 |
|
and not self.cleaned_data.get('send_password_reset'):
|
|
253 |
if (self.require_password and
|
|
254 |
not self.cleaned_data.get('generate_password') and
|
|
255 |
not self.cleaned_data.get('password1') and
|
|
256 |
not self.cleaned_data.get('send_password_reset')):
|
253 |
257 |
raise forms.ValidationError(
|
254 |
258 |
_('You must choose password generation or type a new'
|
255 |
259 |
' one or send a password reset mail'))
|
256 |
260 |
if (self.instance and self.instance.pk and not self.instance.email and
|
257 |
|
(self.cleaned_data.get('send_mail')
|
258 |
|
or self.cleaned_data.get('generate_password'
|
259 |
|
or self.cleaned_data.get('send_password_reset')))):
|
|
261 |
(self.cleaned_data.get('send_mail') or
|
|
262 |
self.cleaned_data.get('generate_password' or
|
|
263 |
self.cleaned_data.get('send_password_reset')))):
|
260 |
264 |
raise forms.ValidationError(
|
261 |
265 |
_('User does not have a mail, we cannot send the '
|
262 |
266 |
'informations to him.'))
|
... | ... | |
309 |
313 |
class UserAddForm(UserChangePasswordForm, UserEditForm):
|
310 |
314 |
css_class = "user-form"
|
311 |
315 |
form_id = "id_user_add_form"
|
|
316 |
require_password = False
|
312 |
317 |
|
313 |
318 |
notification_template_prefix = \
|
314 |
319 |
'authentic2/manager/new-account-notification'
|
... | ... | |
328 |
333 |
|
329 |
334 |
def clean(self):
|
330 |
335 |
super(UserAddForm, self).clean()
|
331 |
|
User = get_user_model()
|
332 |
|
|
333 |
|
if not self.cleaned_data.get('username') and \
|
334 |
|
not self.cleaned_data.get('email'):
|
|
336 |
# check if this account is going to be real online account, i.e. with a
|
|
337 |
# password, it it's the case complain that there is no identifiers.
|
|
338 |
has_password = (
|
|
339 |
self.cleaned_data.get('new_password1') or
|
|
340 |
self.cleaned_data.get('generate_password') or
|
|
341 |
self.cleaned_data.get('send_password_reset'))
|
|
342 |
|
|
343 |
if (has_password and
|
|
344 |
not self.cleaned_data.get('username') and
|
|
345 |
not self.cleaned_data.get('email')):
|
335 |
346 |
raise forms.ValidationError(
|
336 |
347 |
_('You must set a username or an email.'))
|
337 |
348 |
|
338 |
|
-
|