def register_user(email, password): """ This method registers a use using e-mail and password The password already comes hashed as sha-512 :param email: User's email (might be invalid) :param passowrd: sha512-hashed password :return: True if registered successfully, or False otherwise (exceptions can also be raised) """ user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: # Tell user they are already registered raise UserErrors.UserAlreadyRegistered( "The email you used to register already exists ") if not Utils.email_is_valid(email): # Tell user that their e-mail is not constructed properly raise UserErrors.InvalidEmailError( "The email does not have right format.") hash_password = Utils.hash_password(password) user = User(email, hash_password) user.save_to_db() #User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email,password,username): user_data = Database.find_one("users", {"email": email}) # Password in sha512 -> pbkdf if user_data is not None: raise UserErrors.UserAlreadyRegistered("The e-mail you registered already exists") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("The email does not have right format") User(email, Utils.hash_password(password), username).save_to_db() return True
def register_user(email, password): """ :param email: user emails :param password: password :return: Boolean true or false register """ user_data = Database.find_one("users", {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegistered( "Email already registered, please check your email to login.") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("Your email is not valid") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): """ This method registers user using email and pass The password already comes hashed as sha512 :param email: user email (might be invalid) :param password: sha-512 hashed password :return:True if registered successfully, or false otherwise (exceptions can be raised) """ user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegistered("Email already exists") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( "Email does not have valid format") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): """ This method registers a user using email and a password The password is already hashed using sha-512 :param email: user's e-mail address :param password: sha-512 hashed password :return: True is registered successfully else false """ user_data = Database.find_one(collection=UserConstants.COLLECTION, query={"email": email}) if user_data is not None: # Tell user they are already registered raise UserErrors.UserAlreadyRegistered( "The email provided is already registered") if not Utils.email_is_valid: # Tell user that their email is not contructed right raise UserErrors.InvalidEmailError( "The email address is not in the right format") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): ''' This method registers a user using email and password. The password already comes hashed as sha-512 :param email: user's e-mail (might be invalid) :param password: sha512-hashed password :return: True if registered successfully, or False otherwise (exceptions can also be raised) ''' user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: # user data exists in database therefore user exists. raise UserErrors.UserAlreadyRegistered("The user already exists") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("The email address you have provided is not valid") # no exceptions raised then the user is registered in the database. User(email, Utils.hash_password(password)).save_to_db() return True