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, 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(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: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'This e-mail you used to register already exists.') except UserErrors.UserNotFoundError: print('email', email) print('password', password) print('hashpass', Utils.hash_password(password)) User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(cls, email: str, password: str) -> bool: """Attempts to register a new user account. Args: email: The user's email address. password: The user's plaintext password. Returns: True if the account was successfully registered. Raises: InvalidEmailError: If the email address is invalid. AlreadyRegisteredError: If there is already an account registered with this email address. """ if not Utils.validate_email(email): raise UserError.InvalidEmailError('Invalid email.') try: cls.find_by_email(email) raise UserError.AlreadyRegisteredError('There is already a user' ' registered with this' 'email.') except UserError.NotFoundError: User(email, Utils.hash_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(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 update_password(username, password, confirm_pass): if not password == confirm_pass: raise UserErrors.PasswordMatchError("Passwords don't match") Database.update_one("users", {"username": username}, {"password": Utils.hash_password(password)}) 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 UserErrors.InvalidEmailError( "The e-mail is not right formatted") try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( "The e-mail you tried 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) -> 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 forgot_password(_id): if request.method == 'POST': new_password = request.form.get('new_password') hashed_password = Utils.hash_password(new_password) User.change_password(hashed_password, _id) user = User.get_user_object(_id=_id) session['email'] = user.email return redirect(url_for('.forgot_password', _id=_id)) return render_template('user_dash_board.html')
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 is_login_valid(email, password): """This method verify that email and password is valid or not password is a ha512 hashed password will if valid else false otherwise""" user_data = Database.find_one(UserConstant.COLLECTION, {"email": email}) if user_data is None: # Tell the user that their email doesn't exist raise UserErrors.UserNotExistError("your User does not exist") if not Utils.hash_password(password, user_data['password']): # tell user that the password is wrong raise UserErrors.IncorrectPasswordError("your password is in correct ") 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(cls, email: str, password: str) -> bool: 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( 'The email you used to register already exists in the database' ) except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo()
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): 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, name: str, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( 'The e-mail does not have the correct format.') try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'The e-mail you used to register already exist') except UserErrors.UserNotFoundError: User(name, email, Utils.hash_password(password)).save_to_mongo() return True
def validate_register(cls, email: str, password: str) -> bool: if not Utils.validate_email(email): raise UserErrors.InvalidEmailError('Invalid e-mail format.') try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'There is an account already registered to that email.') except UserErrors.UserNotFoundError: if not Utils.validate_password(password): raise UserErrors.InvalidPasswordError( 'Invalid password format.') 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 e-mail does not have the right format.') try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'Email you are using is already registered') except UserErrors.UserNotFoundError: 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, password) -> bool: if not Utils.is_valid_email(email): raise UserErrors.InvalidEmailError( "The email address provided is not valid") try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError( "The User has already registered") 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): # 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) -> 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 change_password(): if request.method == 'POST': current_password = request.form['current'] user = User.find_by_email(session['email']) current_password_confirm = user.password new_password = request.form['new-password'] new_password_confirm = request.form['new-password-confirm'] if not Utils.check_hashed_password(current_password, current_password_confirm): flash('Incorrect password.', 'danger') elif new_password != new_password_confirm: flash('The passwords entered do not match.', 'danger') else: user.password = Utils.hash_password(new_password) user.save_to_firebase() return redirect(url_for('users.settings'))
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(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): """ 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(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