Add checks for username and passwords, move checks to model.
This commit is contained in:
parent
1574be3c07
commit
87dc3b6344
3 changed files with 27 additions and 6 deletions
|
@ -3,6 +3,8 @@ import logging
|
|||
import dateutil.parser
|
||||
|
||||
from database import *
|
||||
from util.validation import (validate_email, validate_username,
|
||||
validate_password)
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -14,6 +16,15 @@ class DataModelException(Exception):
|
|||
|
||||
def create_user(username, password, email):
|
||||
pw_hash = bcrypt.hashpw(password, bcrypt.gensalt())
|
||||
|
||||
if not validate_email(email):
|
||||
raise DataModelException('Invalid email address: %s' % email)
|
||||
if not validate_username(username):
|
||||
raise DataModelException('Invalid username: %s' % username)
|
||||
if not validate_password(password):
|
||||
raise DataModelException('Invalid password, password must be at least ' +
|
||||
'8 characters and contain no whitespace.')
|
||||
|
||||
try:
|
||||
new_user = User.create(username=username, password_hash=pw_hash,
|
||||
email=email)
|
||||
|
|
Reference in a new issue