コード例 #1
0
 def clean(self):
     username = self.cleaned_data.get('username')
     password = self.cleaned_data.get('password')
     if not User.objects.filter(username=username).exists():
         raise forms.ValidationError(u'Usuário não cadastrado.')
     user = auth.authenticate(username=username, password=password)
     if user is not None:
         if user.active:
             user.permission_mapping = ''
             user.organization = None
             user.unit = None
             if self.scope == LoginForm.ORGANIZATION:
                 user.organization = self.cleaned_data.get('login_scope', self.organization)
                 is_organization_user = user.role_set.filter(organizations__in=(user.organization, 0)).exists()
                 if not is_organization_user:
                     raise forms.ValidationError(u'%s não é usuário de %s' % (username, user.organization))
             elif self.scope == LoginForm.UNIT:
                 user.unit = self.cleaned_data.get('login_scope', self.unit)
                 is_unit_user = user.role_set.filter(units__in=(user.unit, 0)).exists()
                 is_organization_user = loader.organization_model and user.role_set.filter(organizations__in=(user.unit.get_organization(), 0)).exists()
                 if not is_unit_user and not is_organization_user:
                     raise forms.ValidationError(u'%s não é usuário de %s' % (username, user.unit))
             user.save()
             auth.login(self.request, user)
             return self.cleaned_data
         else:
             raise forms.ValidationError(u'Usuário inativo.')
     else:
         raise forms.ValidationError(u'Senha não confere.')
コード例 #2
0
ファイル: forms.py プロジェクト: adelsonllima/djangoplus
 def clean(self):
     cleaned_data = super(RecoverPassowordForm, self).clean()
     qs = User.objects.filter(email=cleaned_data['email'])
     if qs.exists():
         qs.first().send_reset_password_notification()
         return cleaned_data
     else:
         raise forms.ValidationError(_('User not found.'))
コード例 #3
0
ファイル: forms.py プロジェクト: adelsonllima/djangoplus
 def clean(self):
     cleaned_data = super(LoginForm, self).clean()
     username = cleaned_data.get('username')
     password = cleaned_data.get('password')
     if not User.objects.filter(username=username).exists():
         raise forms.ValidationError(_('User not registered.'))
     user = auth.authenticate(username=username, password=password)
     if user is not None:
         if user.active:
             user.permission_mapping = ''
             user.organization = None
             user.unit = None
             if self.scope == LoginForm.ORGANIZATION:
                 user.organization = cleaned_data.get(
                     'login_scope', self.organization)
                 is_organization_user = user.role_set.filter(
                     scope__in=(user.organization, 0)).exists()
                 if not is_organization_user:
                     raise forms.ValidationError('{} {} {}'.format(
                         username, _('is not user of'), user.organization))
             elif self.scope == LoginForm.UNIT:
                 user.unit = cleaned_data.get('login_scope', self.unit)
                 is_unit_user = user.role_set.filter(
                     scope__in=(user.unit, 0)).exists()
                 is_organization_user = CACHE[
                     'ORGANIZATION_MODEL'] and user.role_set.filter(
                         scope__in=(user.unit.get_organization(),
                                    0)).exists()
                 if not is_unit_user and not is_organization_user:
                     raise forms.ValidationError('{} {} {}'.format(
                         username, _('is not user of'), user.unit))
             else:
                 roles = user.role_set.all()
                 if roles.count() == 1:
                     role = roles.first()
                     if role.scope:
                         user.scope = role.scope
             user.save()
             auth.login(self.request, user)
             return cleaned_data
         else:
             raise forms.ValidationError(_('User is inactive.'))
     else:
         raise forms.ValidationError(_('Password is incorrect.'))
コード例 #4
0
ファイル: forms.py プロジェクト: adelsonllima/djangoplus
 def clean_confirm_password(self):
     if not self.data.get('new_password') == self.data.get(
             'confirm_password'):
         raise forms.ValidationError(_('The passwords must be the same.'))
     return self.cleaned_data
コード例 #5
0
ファイル: forms.py プロジェクト: adelsonllima/djangoplus
 def clean(self):
     if not self.data['new_password'] == self.data['confirm_password']:
         raise forms.ValidationError(_('The passwords must be the same.'))
     return self.cleaned_data
コード例 #6
0
 def clean_confirm_password(self):
     if not self.data.get('new_password') == self.data.get('confirm_password'):
         raise forms.ValidationError(u'As senhas devem ser iguais.')
     return self.cleaned_data
コード例 #7
0
 def clean_mail(self):
     self.qs = User.objects.filter(email=self.cleaned_data['mail'])
     if self.qs.exists():
         return self.cleaned_data['mail']
     else:
         raise forms.ValidationError(u'E-mail não cadastrado.')
コード例 #8
0
 def clean(self):
     if not self.data['new_password'] == self.data['confirm_password']:
         raise forms.ValidationError(u'As senhas devem ser iguais.')
     return self.cleaned_data