Merge branch 'master' of https://bitbucket.org/yackob03/quay
This commit is contained in:
commit
038e9afc97
7 changed files with 68 additions and 4 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,8 +16,20 @@ class DataModelException(Exception):
|
|||
|
||||
def create_user(username, password, email):
|
||||
pw_hash = bcrypt.hashpw(password, bcrypt.gensalt())
|
||||
new_user = User.create(username=username, password_hash=pw_hash,
|
||||
email=email)
|
||||
|
||||
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)
|
||||
except Exception as ex:
|
||||
raise DataModelException(ex.message)
|
||||
return new_user
|
||||
|
||||
|
||||
|
|
Reference in a new issue