def register_user(email, password, nick_name): """ This method registers a user using e-mail and password The password already comes hashed as sha-512 :param email: user's email (might be invalid) :param password: sha512-hashed password :return: True if registered successfully, of 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.UserAlreadyRegisteredError( "The e-mail 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 e-mail does not have the right format.") if nick_name == '' or nick_name == None: User(email, Utils.hash_password(password), nick_name=None).save_to_mongo() else: User(email, Utils.hash_password(password), nick_name=nick_name).save_to_mongo() return True
def register_user(email, password, name, address, ph_no, card_no): user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError( "The email you used to register already exists.") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( "The email does not have the right format.") User(name, email, Utils.hash_password(password), address, ph_no, card_no).save_to_db() return True
def register_user(email, password): """ Registers user using Email and Password :param email: users email id (can be invalid) :param password: sha512-hashed password :return: True if registered succesfully """ user_data = Database.find_one('users', {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError( "The e-mail already Exists") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( "This e-mail 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 e-mail and password. The password already comes hashed as sha-512. :param email: user's e-mail (may be invalid) :param password: sha512-hashed password :return: True if registered successfully, False otherwise (exceptions can also be raised) """ user_data = Database.find_one('users', {"email": email}) if user_data is not None: # if user exists raise UserErrors.UserAlreadyRegisteredError("This email already exists!") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("The email does not have correct format.") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email: str, password: str) -> bool: """ This method registers a user using e-mail 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("users", {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError( "The e-mail you used to register already exists.") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( "The e-mail does not have the right format.") User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(email, password, name, phone_no, gender, dob): """ This method registers a user to the database using the entered details. The password already comes in a sha512 hashed format :param email: Email entered by the user :param password: sha512 hashed password :return: True if registration is successful, an exception is raised otherwise """ # user_data = Database.find_one(COLLECTION, {'email': email}) user_data = Database.find_user_email(email) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError( 'This email is already registered with us.') if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( 'The email is not of a valid format') User(email, Utils.hash_password(password), name, phone_no, gender, dob).save_to_database() return True
def register_user(email, password, domains, memberlevel, token, APIkey, config, name, paid, paymentdue, ads, products, company, address, city, state, zip, phone): """ This method registers a user using e-mail 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("users", {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError( "The e-mail you used to register already exists.") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( "The e-mail does not have the right format.") User(email, Utils.hash_password(password), domains, memberlevel, token, APIkey, config, name, paid, paymentdue, ads, products, company, address, city, state, zip, phone).save_to_db() return True
def register_user(email, password, nick_name, file=None): el = Elasticsearch(port=port) """ This method registers a user using e-mail and password The password already comes hashed as sha-512 :param email: user's email (might be invalid) :param password: sha512-hashed password :return: True if registered successfully, of False otherwise (exceptions can also be raised) """ try: user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: # Tell user they are already registered raise UserErrors.UserAlreadyRegisteredError( "The e-mail 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 e-mail does not have the right format.") if nick_name == '' or nick_name == None: user = User(email, Utils.hash_password(password), nick_name=None, picture=file) user.save_to_mongo() doc = { 'email': email, 'nick_name': nick_name, 'user_id': user._id, } else: user = User(email, Utils.hash_password(password), nick_name=nick_name, picture=file) user.save_to_mongo() doc = { 'email': email, 'nick_name': nick_name, 'user_id': user._id, } el.index(index="users", doc_type='user', body=doc, id=user._id) return True except TypeError: if not Utils.email_is_valid(email): # Tell user that their e-mail is not constructed properly. raise UserErrors.InvalidEmailError( "The e-mail does not have the right format.") user_id = User.find_by_email(email)._id if nick_name == '' or nick_name == None: User(email, Utils.hash_password(password), nick_name=None, picture=file).save_to_mongo() doc = { 'email': email, 'nick_name': nick_name, 'user_id': user_id, } else: User(email, Utils.hash_password(password), nick_name=nick_name, picture=file).save_to_mongo() doc = { 'email': email, 'nick_name': nick_name, 'user_id': user_id, } el.index(index="users", doc_type='user', body=doc, id=user_id) return True