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(username, email, password, confirm_pass, user_type, institution=None): user_data = Database.find_one("users", {"username": username}) if user_data is not None: raise UserErrors.UserAlreadyExistsError( "This username already exists. Try using a different username") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailFormat("Wrong email format") if not password == confirm_pass: raise UserErrors.PasswordMatchError("Passwords don't match") if institution is None: Users(username, email, Utils.hash_password(password), user_type).save_to_db_user() elif institution is not None: Users(username, email, Utils.hash_password(password), user_type, institution).save_to_db_owner() return True
def register_user(cls, name: str, lastname: str, email: str, password: str) -> bool: """ This method registers a user using e-mail and password. :param email: user's e-mail (might be invalid) :param password: password :return: True if registered successfully, or False otherwise (exceptions can also be raised) """ if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( "The e-mail does not have the right format.") try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( "The e-mail you used to register already exists.") except UserErrors.UserNotFoundError: User(name, lastname, email, Utils.hash_password(password), create_date=now_string(), update_date=now_string()).save_to_mongo() return True
def register_user(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError('The e-mail does not have the right format.') try: user = cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError('The email you used to register already exists.') except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register(cls, email, password): user = cls.get_by_email(email) if user is not None: return f"{email} already exists" if not Utils.email_is_valid(email): return "Email is not in correct format" new_user = cls(email, password) new_user.save_to_mongo() return True
def login_valid(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise errors.InvalidEmail("The format of email is wrong") user = cls.get_by_email(email) if not Utils.check_hashed_passwords(password, user.passsord): raise errors.WrongPassword("The password is incorrect!") return True
def register_user(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError('Invalid email format') try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'The email already exists') except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise errors.InvalidEmail("The format of email is wrong") try: cls.get_by_email(email) raise errors.UserExists("This user is already registered!") except errors.UserNotFound: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, name: str, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("The e-mail does not have a right format!") try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError("The e-mail you used already exists!") except UserErrors.UserNotFoundError: User(name, email, password).save_to_mongo() return True
def register_user(cls, email:str, password:str): if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("The email does not have the right format.") try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError('A user with this email already exists.') except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( "The email is not correctly formatted") try: cls.find_by_email(email) session['email'] = email raise UserErrors.UserAlreadyRegisteredError("User already exists") except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError('Email incorrecto') try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'El email introducido ya existe') except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).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(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): # This shouldn't really be called because the form validation should catch if it is an email type raise UserErrors.InvalidEmailError( 'The email does not have the right format.') try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'The registering email already exists.') except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str): if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError('Email id is not valid') #try: user = cls.find_by_email(email) #for users in user: if len(user) > 0: raise UserErrors.UserAlreadyRegisteredError('User with this email {} is already registered'.format(email)) else: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str) -> bool: # Checking if e-mail format is correct if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("This e-mail does not have the right format ! ") # Trying to check if user already exists try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegistered("There is already a user registered in this e-mail id ! ") except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str) -> bool: # check that email is in correct format -- return invalid email error if not if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError('The e-mail does not have the correct format.') # if it is in the correct format, check if user already exists -- if so return error saying that user already exists try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError('The e-mail you used to register already exists.') # if the user does not exist, make a new one except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): # email is invalid raise errors.InvalidEmailError( 'The email does not have the right format.') try: cls.find_by_email(email) # this just checks it # email already exists raise errors.UserAlreadyExistsError( 'The email you used to register already exists.') except errors.UserNotFoundError: # success! User(email, Utils.hash_password(password)).register_model( User(email, Utils.hash_password(password))) return True
def register_user(email, password): """ This method register a user with email and sha-512 password :param email: user email :param password: already comes in sha_512 encryption :return: returns true if the credentials are valid Else return False """ user_data = Database.find_one(UserConstant.COLLECTION, {"email": email}) if user_data is not None: #Tell user that they are already registered raise UserErrors.UserAlreadyExist("The email you are trying to register already exist") if not Utils.email_is_valid(email): # Tell that there email is not valid raise UserErrors.InvalidEmail("The email your are trying to register is not valid") User(email, Utils.hashed_password(password)).save_to_db() return True
def register_user(cls, email: str, password: str) -> bool: # First verify that the email is a valid email address if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailERror( 'The email does not have the right format.') # Next check to see if the email address is already a registered user if (cls.find_by_email(email) != None): raise UserErrors.UserAlreadyRegisteredError( 'The email you used to register already exists.') else: user = User(email, Utils.hash_password(password)) print(user) User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(email, password): """ This method registers a user using e-mail and password. The password already come with sha-512 hash algorithm. :param email: user's email (might be invalid) :param password: sha512-hashed password :return: True if registered successfully, of False otherwise """ userData = Database.find_one("users", {'email': email}) if userData is not None: raise UserExistsError("user already existed!") #if email is invalid, then what? if not Utils.email_is_valid(email): raise UserEmailInvalid("invalid email!") #hash password, create new object, then insert to db User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError('The e-mail does not have the right format.') try: user = cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError('The e-mail you used to register already exists.') return True def json(self) -> Dict: return { '_id': self.id, 'email': self.email, 'password': self.password }
def register_user(email, password): """ This method registers a user using e-mail and password. The password already comes hashed as sha-512. """ user_data = Database.find_one("users", {"email": email}) if user_data is not None: flash( f'The e-mail {email} you used to register already exists. Try again or' ) redirect(url_for('login')) return False if not Utils.email_is_valid(email): flash('The e-mail does not have the right format. Try again!') redirect(url_for('signup')) return False User(email, Utils.hash_password(password)).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, 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 (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: 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 = User(email, Utils.hash_password(password)) user.save_to_db() return user
def register_user(cls, email: str, password: str) -> bool: """ This method registers a user using e-mail and password. :param email: user's e-mail (might be invalid) :param password: password :return: True if registered successfully, or False otherwise (exceptions can also be raised) """ if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( 'The e-mail does not have the right format.') try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'The e-mail is already registered.') except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() 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(cls, email: str, password: str) -> bool: """ Registers a :class:`.User`. Parameters ---------- email : str The email to register with. password : str The password to register with. Returns ------- bool True if :class:`.User` was successfully registered, False otherwise. Raises ------ UserErrors.InvalidEmailError If an invalid email was provided. UserErrors.UserAlreadyRegisteredError If the :class:`.User` has already been registered. UserErrors.UserNotFoundError If the :class:`.User` was not found. """ if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( "The e-mail does nothvae the right format.") try: user = cls.find_by_email(email) logger.debug(f"user already found: {user}") raise UserErrors.UserAlreadyRegisteredError( "The e-mail you used to register already exists.") except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str): if not Utils.email_is_valid(email): # email is invalid raise errors.InvalidEmailError('The email does not have the right format.') # try: # cls.find_by_email(email) # this just checks it # # email already exists # raise errors.UserAlreadyExistsError('The email you used to register already exists.') # except errors.UserNotFoundError: # # success! # try: Database.insert(email, { 'password': Utils.hash_password(password), 'timesSlouched': [ {'date': "2019-09-09", 'numSlouch': 7}, {'date': "2019-09-10", 'numSlouch': 13}, {'date': "2019-09-11", 'numSlouch': 15}, {'date': "2019-09-12", 'numSlouch': 10}, {'date': "2019-09-13", 'numSlouch': 7}, {'date': "2019-09-14", 'numSlouch': 11}, {'date': "2019-09-15", 'numSlouch': 0} ] })