Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. def validate(self, **kw):
  2.         params = dict(username=kw['username'], email=kw['email'])
  3.         if (self.valid_username(kw['username'], params) and
  4.             self.valid_email(kw['email'], params) and
  5.             self.valid_password(kw['password'], kw['verify'], params)):
  6.            return True, params
  7.         else:
  8.            return False, params
  9.  
  10.     def valid_username(self, username, params):
  11.         if username and re.match(r"^[a-zA-Z0-9_-]{3,20}$", username):
  12.             return True
  13.         else:
  14.             params['error_username'] = "username is wrong"
  15.  
  16.     def valid_password(self, password, verify, params):
  17.         if password and re.match(r"^.{3,20}$", password):
  18.             if not (password == verify):
  19.                 params['error_verify'] = "passwords should be the same"
  20.                 return
  21.             return True
  22.         else:
  23.             params['error_password'] = "password is wrong"
  24.  
  25.     def valid_email(self, email, params):
  26.         if not email or re.match(r'^[\S]+@[\S]+\.[\S]+$', email):
  27.             return True
  28.         else:
  29.             params['error_email'] = "that's not a valid email"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement