Example #1
0
 def register_user(cls, first_name: str, last_name: str, email: str, password: str):
     # check if email already exists
     try:
         cls.find_by_email(email)
         # email already exists
         raise CustomErrors.UserAlreadyRegisteredError('A user with that email has already been registered.')
     except CustomErrors.UserNotFoundError:
         # email not taken
         if Utils.validate_email(email):
             new_user = cls(first_name, last_name, email, Utils.hash_password(password))
             Database.insert(cls.COLLECTION, new_user.json())
         else:
             raise CustomErrors.InvalidEmailError('The email you have entered is invalid.')
Example #2
0
    def register_user(cls, email, password):
        if not Utils.email_is_valid(email):
            raise error.InvalidEmailError('Email format error')

        try:
            cls.find_by_email(email)
            raise error.UserAlreadyRegisteredError(
                "User already exits try forgot password if you''ve lost password."
            )
        except error.UserNotFoundError:
            User(email, Utils.hash_password(password)).save_to_mongo()

        return True