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_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, 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) -> 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 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): 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 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): # 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: # 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): 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, 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: # 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(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(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} ] })