|
@@ -95,63 +95,3 @@ class AdminAuthenticationForm(AuthenticationForm):
|
|
|
def confirm_login_allowed(self, user):
|
|
|
if not user.is_staff:
|
|
|
raise forms.ValidationError(self.error_messages['not_staff'], code='not_staff')
|
|
|
-
|
|
|
-
|
|
|
-class GetUserForm(MisagoAuthMixin, forms.Form):
|
|
|
- email = forms.CharField()
|
|
|
-
|
|
|
- def clean(self):
|
|
|
- data = super(GetUserForm, self).clean()
|
|
|
-
|
|
|
- email = data.get('email')
|
|
|
- if not email or len(email) > 250:
|
|
|
- raise forms.ValidationError(_("Enter e-mail address."), code='empty_email')
|
|
|
-
|
|
|
- try:
|
|
|
- validate_email(email)
|
|
|
- except forms.ValidationError:
|
|
|
- raise forms.ValidationError(_("Entered e-mail is invalid."), code='invalid_email')
|
|
|
-
|
|
|
- try:
|
|
|
- user = UserModel.objects.get_by_email(data['email'])
|
|
|
- if not user.is_active:
|
|
|
- raise UserModel.DoesNotExist()
|
|
|
- self.user_cache = user
|
|
|
- except UserModel.DoesNotExist:
|
|
|
- raise forms.ValidationError(_("No user with this e-mail exists."), code='not_found')
|
|
|
-
|
|
|
- self.confirm_allowed(user)
|
|
|
-
|
|
|
- return data
|
|
|
-
|
|
|
- def confirm_allowed(self, user):
|
|
|
- """override this method to include additional checks"""
|
|
|
-
|
|
|
-
|
|
|
-class ResendActivationForm(GetUserForm):
|
|
|
- def confirm_allowed(self, user):
|
|
|
- username_format = {'user': user.username}
|
|
|
-
|
|
|
- if not user.requires_activation:
|
|
|
- message = _("%(user)s, your account is already active.")
|
|
|
- raise forms.ValidationError(message % username_format, code='already_active')
|
|
|
-
|
|
|
- if user.requires_activation_by_admin:
|
|
|
- message = _("%(user)s, only administrator may activate your account.")
|
|
|
- raise forms.ValidationError(message % username_format, code='inactive_admin')
|
|
|
-
|
|
|
-
|
|
|
-class ResetPasswordForm(GetUserForm):
|
|
|
- error_messages = {
|
|
|
- 'inactive_user': _(
|
|
|
- "You have to activate your account before "
|
|
|
- "you will be able to request new password."
|
|
|
- ),
|
|
|
- 'inactive_admin': _(
|
|
|
- "Administrator has to activate your account before "
|
|
|
- "you will be able to request new password."
|
|
|
- ),
|
|
|
- }
|
|
|
-
|
|
|
- def confirm_allowed(self, user):
|
|
|
- self.confirm_user_active(user)
|