示例#1
0
    def register_user(user_name, email, password):
        """
        This method register a user using e-mail and password.
        the password already comes hashed as sha-512
        :param name: the user name
        :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})  # password in sha512 --> pdkdf2_sha512
        if user_data is not None:
            # need to tell the user are already exist
            raise UserErrors.UserAlreadyRegisteredError(
                "The user you tried to register is already exist")
        user_data = Database.find_one(UserConstants.COLLECTION,
                                      {"user_name": user_name})
        if user_data is not None:
            # need to tell the user are already exist
            raise UserErrors.UserAlreadyRegisteredError(
                "User with the same name is already exist")
        if not Utils.email_is_valid(email):
            # Tell the user his email is not constructed well
            raise UserErrors.InvalidEmailError(
                "The email you inserted is invalid")
        # Save the user to DB
        user = User(email, password, user_name)
        user.save_to_mongo()

        return True
示例#2
0
    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
示例#3
0
    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
示例#4
0
    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
示例#5
0
    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
示例#6
0
    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
示例#7
0
    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
示例#8
0
    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
示例#9
0
 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
示例#10
0
    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
示例#11
0
    def register_user(email, password):
        user_data = Database.find_one(collection=UserConstants.COLLECTION, query={'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 email does not have the correct format.")
        User(email, Utils.hash_pasword(password)).save_to_db()

        return True
示例#12
0
    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
示例#13
0
    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
示例#14
0
    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
示例#15
0
文件: user.py 项目: Akash1507/Notif
    def register_user(email, password):
        user_data = Database.find_one("users", {'email': email})

        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                "User is already registered")
        if not Utils.email_is_valid():
            raise UserErrors.InvalidEmailError("Email is Invalid")

        User(email, Utils.hashed_password(password)).save_to_db()

        return True
示例#16
0
    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
示例#17
0
    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 you used to register already Exists")
        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError("Invalid Email Address")

        User(email, Utils.hashed_password(password)).save_to_db()

        return True
示例#18
0
    def new_user_valid(email, password, password2):
        user_data = Database.find_one(UserConstants.COLLECTION, {
            "email": email,
            "admin_created": "No"
        })
        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                "This email is already registered. Please log in.  You can reset your password here if needed."
            )
        if password != password2:
            raise UserErrors.PasswordsNotMatch(
                "The passwords entered do not match.  Please try again.")

        return True
示例#19
0
    def register_user(username, email, password, active, permission):
        """
        This method registers a user using e-mail and password.
        The password already comes hashed as a sha-512
        :param email: user's e-mail (might be invalid
        :param password: sha512-hsahed password
        :return: True if registered successfully, or False otherwise(exceptions can also be raised)
        """
        user_data = User.query.filter_by(email=email).first()

        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_data = User.query.filter_by(username=username).first()
        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                "The username you used to register already exists.")
        User(username, email, Utils.hash_password(password), active,
             permission, False).save_to_db()
        return True
示例#20
0
 def register_user(email, password):
     """
     register a user using email and password
     :param email:
     :param password:
     :return: true if regsiters successfully
     """
     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)).save()
     return True
示例#21
0
文件: user.py 项目: dlautz/webtools
    def register_user(username, password, email):
        user_data = Database.find_one(UserConstants.COLLECTION,
                                      {"username": username})

        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                "Username taken.  Please choose another one.")
        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError("Invalid email format.")

        User(username, Utils.hash_password(password), email).save_to_mongo()
        notebook = Notebook("inbox", username)
        notebook.save_to_mongo()

        return True
示例#22
0
    def register_user(email, password):
        user_data = Database.find_one(UserConstants.COLLECTION,
                                      {"email": email})
        if user_data is not None:
            # Tell user that email already exist & can not register
            raise UserErrors.UserAlreadyRegisteredError(
                "The email is already registered")

        if not Utils.email_is_valid(email):
            #Tell user that their e-mail is not constructed properly
            raise UserErrors.InvalidEmailError(
                "The email is not in the right format")

        User(email, Utils.hash_password(password)).save_to_db()

        return True
示例#23
0
文件: user.py 项目: junw3i/carousell
 def register_user(email, password):
     """
     register user -- the password already comes hashed as sha-512
     :param email:
     :param password:
     :return:
     """
     user_data = Database.find_one(UserConstants.COLLECTION, {"email": email})
     if user_data is not None:
         # already registered
         raise UserErrors.UserAlreadyRegisteredError("Email already exists.")
     if not Utils.email_is_valid(email):
         # incorrect email format
         raise UserErrors.InvalidEmailError("Invalid email address.")
     User(email, Utils.hash_password(password)).save_to_db()
     return True
示例#24
0
 def register_user(email, password):
     """
     This method registers a user using an email and a password. The password already comes
     hashed as sha-512.
     :param email: user's email (might be valid)
     :param password: sha-512 hashed password
     :return: true if registed otherwise, false otherwise
     """
     user_data = Database.find_one('users', {'email': email})
     if user_data is not None:
         raise UserErrors.UserAlreadyRegisteredError(
             "The User already exists")
     if not Utils.email_is_valid(email):
         raise UserErrors.InvalidEmailError(
             "The Email does not have the right format")
     User(email, Utils.hash_password(password)).save_to_db()
     return True
示例#25
0
    def register_user(email, password):
        """
        This method registers users using email and password.
        password comes encrypt as sha512
        :param email: users's email
        :param password: password as sha512
        :return: true id registered, false otherwise
        """
        user_data = Database.find_one(UserConstants.COLLECTION,{"email":email})

        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError("You are already Registered")
        if not Utils.email_is_valid(email):
            raise  UserErrors.InvalidEmailError("Invalid e-mail id")
        User(email, Utils.hash_password(password)).save_to_db()

        return True
示例#26
0
    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
示例#27
0
    def register_user(email, password):
        """
        Registers a user using email and password
        password is hashed as sha-512
        :param email:
        :param password:
        :return:
        """
        user_data = Database.find_one("users", {"email": email})

        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError("The e-mail already registered")
        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError("Bad email format")

        User(email, Utils.hash_password(password))save_to_db()

        return True
示例#28
0
    def register_user(email, password):
        """
        This method registers user using email and password.
        Password is sent from form and is a sha512 password.
        It checks if the email is valid and is not already registered
        :param email: User's email
        :param password: Password entered by user
        :return: True if registration is successful, Else False
        """
        user_data = Database.find_one('users', {"email": email})
        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                "The email-id you used to register already exists")
        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError(
                "The email-id format is invalid")

        User(email, Utils.hash_password(password)).save_to_db()
        return True
示例#29
0
    def register_user(email, password):
        """
        This method registers an user, using email and password
        The password already comes as hashed as sha512.
        :param email: user's e-mail
        :param password: sha512-hashed password
        :return True, if regstered successfully, or False otherwise (exception can also be rised)
        """
        user_data = Database.find_one(UserConstants.COLLECTION,
                                      {'email': email})
        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                'The user with this e-mail is already registered')
        if not MyUtils.email_is_valid(email):
            raise UserErrors.InvalidEmailError(
                'The e-mail does not have a valid format')

        User(email, MyUtils.hash_password(password)).save_to_db()
        return True
示例#30
0
    def register_user(email, password):
        """
        
        :param email: 
        :param password: 
        :return: 
        """
        user_data = Database.find_one('users', {"email": email})

        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                'Your email has already been used.')
        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError(
                'You are not using a valid email.')

        User(email, Utils.hash_password(password)).save_to_db()

        return True