Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
    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
Exemplo n.º 15
0
    def register_user(cls, username: str, password: str) -> bool:
        """
        Register a new user.
        """
        if not Utils.username_is_valid(username):
            raise errors.InvalidUserNameError(
                'A username must start with a letter and can only contain alpha-numeric characters.'
            )

        if not Utils.password_is_valid(password):
            raise errors.InvalidPasswordError(
                'A password must (1) have at least one number. (2) have at least one uppercase and one lowercase character. (3) have at least one special character. (4) contain at least eight characters.'
            )

        try:
            # If find the username, it means the user already exists.
            cls.find_by_username(username)
            raise errors.UserAlreadyRegisteredError(
                'The username you used to register already exists.')
        except errors.UserNotFoundError:
            # Hash the password user entered before saving to mongndb
            User(username, Utils.hash_password(password)).save_to_mongo()
        return True