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): """ This method registers a user using email and password. The password already comes hashed as sha-512. :param email: email :param password: sha-512 hashed password :return: True if registered successfully, or False otherwise (exceptions can also be raised) """ user_data = Database.find_one( UserConstants.COLLECTION, {"email": email}) # Password in sha512 -> pbkdf2_sha512 if user_data is not None: # Tell users they are already registered raise UserErrors.UserAlreadyRegisteredError( "The email you used to register already exists.") if not Utils.email_is_valid(email): # Tell user their email is not constructed properly raise UserErrors.InvalidEmailError( "The email does not have the right format.") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(name, last_name, employee_num, email, password): """ This method registers a user e-mail and password. The password already comes hashed as sha-512 :param email: user's email (might be invalid) :param password: sha-512 hashed password :param name: :param last_name: :param employee_num: :return: True if registered successfully, or False otherwise (exception can also be raised) """ user_data = Database.find_one(UserConstants.COLLECTIONS, {"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, last_name, employee_num, email, Utils.hash_password(password)).save_to_db() return True
def create_account(user_id, password, user_type, school): """ This method registers a user using user id and password. The password already comes hashed as sha-512. :param user_id: user's id (might be invalid) :param password: user's password in plain text :param user_type: user's type (can be admin, teacher, or student) :return: """ sql = """ SELECT * FROM accounts WHERE user_id = (%s) """ user_data = Database.query(sql, user_id) if user_data: # Tell user they are already registered raise ValueError( "The user id you used to register already exists.") if not User.is_valid_user_id(user_id, user_type): raise ValueError('Invalid user id!') try: Account(user_id, Utils.hash_password(password, user_id), user_type, school).save_to_db() except pymysql.Error as error: raise error
def register_user(email, password): """ This method regsters a user using email and password Password already comes hashed as sha-512 :param email: user's e-mail (might be invalid) :param password: sha512-hashed password :return: True is registered successfully, or False otherwise (exceptions can also be raised) """ user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) # if user is already registered if user_data is not None: # tell user they are already registered raise UserErrors.UserAlreadyRegisteredError( "The e-mail you used to register already exist.") # if e-mail is invalid 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.") # set email and encrypted password to User attributes # then save to database 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 comes hashed sha512 :param email: user's email (might be invalid) :param password: sha512 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: #Tell user they are already registered raise UserErrors.UserAlreadyRegisteredError( "The email you used to register already exists") if not Utils.email_is_valid(email): #Tell user their email is not constructed properly raise UserErrors.InvalidEmailError( "The email does not have the proper format.") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): """ This method registers an user with email and password The password already comes sha512 :param email: user's email -- to be check is not already in the database :param password: sha512 hashed password to be converted into pbkdf2-sha512 :return: True if user is registered, and False otherwise """ # check the db for the email provided user_data = Database.find_one(UserConstants.COLLECTION, query={'email': email}) # if we got a not None result if user_data is not None: # tell the user that he email provided is already in the db raise UserErrors.UserAlreadyRegisteredError( 'The email provided already exists.') if not Utils.email_is_valid(email): # tell the suer that the email is not formatted as an email raise UserErrors.InvalidEmailError( 'The email has not a proper format.') # if everything is OK, save the new user to the db User(email, Utils.hash_password(password)).save_to_db() return True
def test_check_poor_password(init_db): new_user = User("*****@*****.**", ) auth_code = Utils.generate_auth_code() new_user.password = Utils.hash_password(auth_code) with pytest.raises(UserErrors.PoorPasswordError): new_user.check_registration_password_same_as_auth_code( auth_code, new_user.password) new_user.delete_by_email()
def register_admin(email, password): user_data = Database.find_one(AdminConstants.COLLECTION, {"email": email}) if user_data is not None: raise AdminErrors.AdminAlreadyRegisteredError("The email you used to register already exists.") if not Utils.email_is_valid(email): raise AdminErrors.InvalidEmailError("Not a valid email format.") Admin(email, Utils.hash_password(password)).save_to_mongo()
def register_user(email, password, fName, age): user_data = User.get_by_email(email) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError("You already have an account with this email address.") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("This is an invalid email address!") User(email, Utils.hash_password(password), fName, age).save_to_mongo() return True
def register_user(email, password, name): user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError("Email already exists") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("The email address is invalid") User(email, Utils.hash_password(password), name).save() return True
def register_user(cls, email, password): user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) cls.check_registration_password_same_as_auth_code( password, user_data['password']) user_data = User(email, password, _id=user_data['_id']) user_data.active = True user_data.password = Utils.hash_password(password) user_data.update_user_in_db() return True
def register_user(email, password): 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_db() return True
def register_user(username, password, email, image): user_data = Database.find_one(UserConstant.COLLECTION, {'username':username}) if user_data is not None: raise UserError.UserIsExist("The user is existing in the database") if not Utils.email_is_valid(email): raise UserError.EmailNotValid("Email is not valid") password = Utils.hash_password(password) user = User(username, password, email, image) user.save_to_mongo() return True
def register_user(email, password): user_data = Database.find_one('users', {'email': email}) if user_data is not None: raise UserAlreadyRegisteredError("The email you used has already been used.") if not Utils.email_is_valid(email): raise InvalidEmailError("The email does not have the right format.") User(email, Utils.hash_password(password)).save_to_mongo() return True
def register_user(email, password): user_data = Database.find_one(collection=UserConstant.COLLECTION, query={"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError( "User already registered") if not User.email_is_valid(email): raise UserErrors.InvalidEmailError("The email format is invalid") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(username, password): user_data = Database.find_one(UserConstant.COLLECTION, {'username': username}) if user_data is not None: raise UserError.UserAlreadyHasError( "User is already existing, please use another username") password = Utils.hash_password(password) user = User(username, password) user.save_to_mongo() return True
def register_user(email, password): user_data = User.from_db_by_email(email) if user_data is not None: raise UserErrors.UserAlreadyRegisterError("Email is already registered.") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("Email is invalid.") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: raise UserErrors.UserAlredyRegError("User exists") if not Utils.emial_is_valid(email): raise UserErrors.InvalidEmailError("Email format is invalid") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError("The email that was used is already registered.") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("Invalid email format.") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): user_data = Database.find_one(UserConstant.COLLECTION, {'email':email}) if user_data is not None: raise UserError.UserAlreadyHasError("User is existing, please try again") if not Utils.email_is_valid(email): raise UserError.InvalidEmailError("Email is invalid, please enter another email") User(email, Utils.hash_password(password)).save_to_mongo() return True
def register(cls, email: str, password: str) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError(f"{email} is not a valid email.") try: cls.find_by_email(email) raise UserErrors.UserAlreadyRegisteredError(f"{email} has already been registered.") except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_mongo() cls.welcome(email) return True
def register(cls, email, password) -> bool: if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError( 'The email does not have the right format.') try: cls.get_by_email(email) raise UserErrors.UserAlreadyRegisteredError( 'The email you used to register already exits.') except UserErrors.UserNotFoundError: User(email, Utils.hash_password(password)).save_to_db() return True
def register(email, sha512_password): user_data = Database.find_one(collection='users', query={'email': email}) if user_data: raise UserErrors.UserAlreadyExistsError("User already registered.") if not Utils.email_is_valid(email): raise UserErrors.IncorrectEmailFormat("Invalid email.") User(email, Utils.hash_password(sha512_password)).save_to_database() return True
def is_registered(cls, username, password): """ This method register user using an email and password password comes already in hashed as sHa_512 :param email:user's email (might be invalid) :param password: sha_512 password :return:True if registration successful else false otherwise exception can be raised """ Retailer(username=username, password=Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): user_data = Database.find_one("users", {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError( "The User is already registered with the given Email.") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailFormatError( "The specified email format is incorrect.") User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password): user_data = Database.find_one("users", {"email": email}) if user_data is not None: pass if not Utils.email_is_valid(email): pass User(email, Utils.hash_password(password)).save_to_db() return True
def register_user(email, password, name, age): query = "SELECT * FROM appusers WHERE email = \'{}\'".format(email) user_data = Database.find_one(query) 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), name, age).save_to_db() return True
def register_user(email, password): user = db.find_one(UserConstraints.Collection, {'email': email}) if user is not None: raise exc.UserAlreadyRegisterError( "The email you used to register is already exists.") if not Utils.email_is_valid(email): raise exc.InvalidEmailError( "The email doesn't have a valid format.") User(email, Utils.hash_password(password)).save_database() 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 correct format') try: user = cls.find_by_email(email) 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 modify_account(user_id, password, user_type, school): sql = """ SELECT * FROM accounts WHERE user_id = (%s) """ account_data = Database.query(sql, user_id) if account_data: Account(user_id, Utils.hash_password(password, user_id), user_type, school).save_to_db() return True else: return False
def reset_with_token(token): try: email = ts.loads(token, salt="recover-key", max_age=86400) except: abort(404) if request.method == 'POST': user = User.get_user_by_email(email) user.password = Utils.hash_password(request.form['pword']) user.save_to_mongo() return redirect(url_for('users.login_user')) return render_template('users/reset_with_token.jinja2', token=token)
def register_user(email, password): user_data = Database.find_one(UserConstant.COLLECTION, {'email': email}) if user_data is not None: raise UserError.UserAlreadyHasError( "User is existing, please try again") if not Utils.email_is_valid(email): raise UserError.InvalidEmailError( "Email is invalid, please enter another email") 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 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_db() return True
def reset_password(username): user = User.find_by_username(username) if request.method == 'POST': origin = request.form['origin'] new = request.form['new'] re_password = request.form['re_password'] if Utils.check_hashed_password(origin, user.password): if new == re_password: user.password = Utils.hash_password(new) user.save_to_mongo() return redirect(url_for('.index')) else: raise UserError.RetypePassword("Your new password and re-type password are not the same") else: raise UserError.PasswordIncorrect("Your origin password is not correct") return render_template('users/reset_password.html')
def register_user(email, password): ''' this method register a user using email and password. The password already comes hashed as sha512 :param email: user's email (might bbe invalid) :param password: sha512-hashed password :return: True if registered succefully, 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('That email already exists') if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError('The email has not 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 email (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: # 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") User(email, Utils.hash_password(password)).save_to_db() return True