Exemplo n.º 1
0
    def validate_password(self):
        if not re.match(FormValidator.password_regex, self._arguments['password']):
            self._errors.append(Alert('<b>%s!</b> Password is too easy.' % get_random_magic_word()))

        if 'repeat_password' in self._arguments.keys():
            if self._arguments['password'] != self._arguments['repeat_password']:
                self._errors.append(Alert('<b>%s!</b> Passwords don\'t match.' % get_random_magic_word()))
Exemplo n.º 2
0
 def validate_user(self):
     # user = authenticate(username=self._arguments['username'], password=self._arguments['password'])
     if not self._arguments['user']:
         # return the same page with errors if no
         self._errors.append(
                 Alert('<b>%s!</b> Wrong authentication data.' % (get_random_magic_word()), 'danger'))
     elif not self._arguments['user'].is_active:
         msg = Alert(
                 '<b>%s! Sorry!</b> This user is disabled. Contact <a href="mailto:%s">' % (
                     get_random_magic_word(), ADMIN_EMAIL) +
                 'admin</a> to resolve this issue.')
         self._errors.append(msg)
Exemplo n.º 3
0
    def validate_password(self):
        if not re.match(FormValidator.password_regex,
                        self._arguments['password']):
            self._errors.append(
                Alert('<b>%s!</b> Password is too easy.' %
                      get_random_magic_word()))

        if 'repeat_password' in self._arguments.keys():
            if self._arguments['password'] != self._arguments[
                    'repeat_password']:
                self._errors.append(
                    Alert('<b>%s!</b> Passwords don\'t match.' %
                          get_random_magic_word()))
Exemplo n.º 4
0
 def validate_user(self):
     # user = authenticate(username=self._arguments['username'], password=self._arguments['password'])
     if not self._arguments['user']:
         # return the same page with errors if no
         self._errors.append(
             Alert(
                 '<b>%s!</b> Wrong authentication data.' %
                 (get_random_magic_word()), 'danger'))
     elif not self._arguments['user'].is_active:
         msg = Alert(
             '<b>%s! Sorry!</b> This user is disabled. Contact <a href="mailto:%s">'
             % (get_random_magic_word(), ADMIN_EMAIL) +
             'admin</a> to resolve this issue.')
         self._errors.append(msg)
Exemplo n.º 5
0
 def validate_username(self):
     super(RegisterFormValidator, self).validate_username()
     if 'username' in self._arguments.keys():
         if self._arguments['username'] in [x.username for x in User.objects.all()]:
             self._errors.append(
                     Alert('<b>%s!</b> User with username "%s" already exists.' % (
                         get_random_magic_word(), self._arguments['username'])))
Exemplo n.º 6
0
 def validate_email(self):
     super(RegisterFormValidator, self).validate_email()
     if 'email' in self._arguments.keys():
         if self._arguments['email'] in [x.email for x in User.objects.all()]:
             self._errors.append(
                     Alert('<b>%s!</b> User with e-mail %s already exists.' % (
                         get_random_magic_word(), self._arguments['email'])))
Exemplo n.º 7
0
 def validate_email(self):
     if 'email' in self._arguments.keys():
         self._arguments['email'] = self._arguments['email'].strip()
         if not re.match(FormValidator.email_regex, self._arguments['email']):
             self._errors.append(
                     Alert('<b>%s!</b> E-mail "%s" is not valid.' % (
                         get_random_magic_word(), self._arguments['email'])))
Exemplo n.º 8
0
 def validate_username(self):
     if 'username' in self._arguments.keys():
         self._arguments['username'] = self._arguments['username'].strip()
         if not re.match(FormValidator.username_regex, self._arguments['username']):
             self._errors.append(Alert(
                     '<b>%s!</b> Username "%s" is not valid.' % (
                         get_random_magic_word(), self._arguments['username'])))
Exemplo n.º 9
0
 def validate_term_name(self):
     if 'name' in self._arguments.keys():
         if not (AddTermFormValidator.min_term_name_length <= len(
                 self._arguments['name']) <= AddTermFormValidator.max_term_name_length):
             msg = '<b>%s!</b> Term name should be from %i to %i characters long.' % (
                 get_random_magic_word(), AddTermFormValidator.min_term_name_length,
                 AddTermFormValidator.max_term_name_length)
             self._errors.append(Alert(msg))
Exemplo n.º 10
0
 def validate_email(self):
     if 'email' in self._arguments.keys():
         self._arguments['email'] = self._arguments['email'].strip()
         if not re.match(FormValidator.email_regex,
                         self._arguments['email']):
             self._errors.append(
                 Alert('<b>%s!</b> E-mail "%s" is not valid.' %
                       (get_random_magic_word(), self._arguments['email'])))
Exemplo n.º 11
0
 def validate_definition(self):
     if 'definition' in self._arguments.keys():
         if not (AddTermFormValidator.min_definition_length <= len(
                 self._arguments['definition']) <= AddTermFormValidator.max_definition_length):
             msg = '<b>%s!</b> Definition should be from %i to %i characters long.' % (
                 get_random_magic_word(), AddTermFormValidator.min_definition_length,
                 AddTermFormValidator.max_definition_length)
             self._errors.append(Alert(msg))
Exemplo n.º 12
0
 def validate_username(self):
     if 'username' in self._arguments.keys():
         self._arguments['username'] = self._arguments['username'].strip()
         if not re.match(FormValidator.username_regex,
                         self._arguments['username']):
             self._errors.append(
                 Alert('<b>%s!</b> Username "%s" is not valid.' %
                       (get_random_magic_word(),
                        self._arguments['username'])))
Exemplo n.º 13
0
 def validate_email(self):
     super(RegisterFormValidator, self).validate_email()
     if 'email' in self._arguments.keys():
         if self._arguments['email'] in [
                 x.email for x in User.objects.all()
         ]:
             self._errors.append(
                 Alert('<b>%s!</b> User with e-mail %s already exists.' %
                       (get_random_magic_word(), self._arguments['email'])))
Exemplo n.º 14
0
 def validate_definition(self):
     if 'definition' in self._arguments.keys():
         if not (AddTermFormValidator.min_definition_length <= len(
                 self._arguments['definition']) <=
                 AddTermFormValidator.max_definition_length):
             msg = '<b>%s!</b> Definition should be from %i to %i characters long.' % (
                 get_random_magic_word(),
                 AddTermFormValidator.min_definition_length,
                 AddTermFormValidator.max_definition_length)
             self._errors.append(Alert(msg))
Exemplo n.º 15
0
 def validate_term_name(self):
     if 'name' in self._arguments.keys():
         if not (AddTermFormValidator.min_term_name_length <= len(
                 self._arguments['name']) <=
                 AddTermFormValidator.max_term_name_length):
             msg = '<b>%s!</b> Term name should be from %i to %i characters long.' % (
                 get_random_magic_word(),
                 AddTermFormValidator.min_term_name_length,
                 AddTermFormValidator.max_term_name_length)
             self._errors.append(Alert(msg))
Exemplo n.º 16
0
 def validate_username(self):
     super(RegisterFormValidator, self).validate_username()
     if 'username' in self._arguments.keys():
         if self._arguments['username'] in [
                 x.username for x in User.objects.all()
         ]:
             self._errors.append(
                 Alert(
                     '<b>%s!</b> User with username "%s" already exists.' %
                     (get_random_magic_word(),
                      self._arguments['username'])))
Exemplo n.º 17
0
 def errors(self):
     necessary_parameters = (self._arguments['username'],
                             self._arguments['password'],
                             self._arguments['repeat_password'],
                             self._arguments['email'])
     if '' in necessary_parameters:
         self._errors.append(
             Alert('<b>%s!</b> Some of necessary fields left empty.' %
                   get_random_magic_word()))
     super(RegisterFormValidator, self).errors()
     return self._errors
Exemplo n.º 18
0
 def errors(self):
     necessary_parameters = (
         self._arguments['username'], self._arguments['password'], self._arguments['repeat_password'],
         self._arguments['email'])
     if '' in necessary_parameters:
         self._errors.append(Alert('<b>%s!</b> Some of necessary fields left empty.' % get_random_magic_word()))
     super(RegisterFormValidator, self).errors()
     return self._errors
Exemplo n.º 19
0
 def validate_category(self):
     if not self._arguments.get('category'):
         msg = Alert('<b>%s!</b> Can\'t find such category.' % (get_random_magic_word()))
         self._errors.append(msg)
Exemplo n.º 20
0
 def validate_category(self):
     if not self._arguments.get('category'):
         msg = Alert('<b>%s!</b> Can\'t find such category.' %
                     (get_random_magic_word()))
         self._errors.append(msg)