コード例 #1
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
コード例 #2
0
ファイル: user.py プロジェクト: fdufay/udemy_price_chair
    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
コード例 #3
0
ファイル: user.py プロジェクト: ObedEG/complex_web
    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
コード例 #4
0
    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
コード例 #5
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
コード例 #6
0
ファイル: user.py プロジェクト: nmartinovic/price-of-chair
    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
コード例 #7
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
コード例 #8
0
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()
コード例 #9
0
ファイル: admin.py プロジェクト: jondanson/hbc_schedule
    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()
コード例 #10
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
コード例 #11
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
コード例 #12
0
 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
コード例 #13
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
コード例 #14
0
ファイル: user.py プロジェクト: jslvtr/FChat
 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
コード例 #15
0
ファイル: user.py プロジェクト: cuong19/PriceAlerts
    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
コード例 #16
0
ファイル: user.py プロジェクト: yiranchen1/price_alert
 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
コード例 #17
0
 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
コード例 #18
0
ファイル: user.py プロジェクト: tranngoctan18/pricing_alert
    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
コード例 #19
0
    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
コード例 #20
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
コード例 #21
0
ファイル: user.py プロジェクト: jslvtr/alert-my-wishlist
    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
コード例 #22
0
ファイル: user.py プロジェクト: Hongda-W/CovidAlert
    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
コード例 #23
0
 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
コード例 #24
0
ファイル: user.py プロジェクト: setijo01/Pangestoe_Web
    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
コード例 #25
0
 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
コード例 #26
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
コード例 #27
0
    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
コード例 #28
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
コード例 #29
0
    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
コード例 #30
0
ファイル: user.py プロジェクト: bpt2017/product-pricing
    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
コード例 #31
0
    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
コード例 #32
0
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)
コード例 #33
0
    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
コード例 #34
0
ファイル: user.py プロジェクト: AlinaKay/price-of-chair
    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
コード例 #35
0
ファイル: views.py プロジェクト: jslvtr/FChat
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')
コード例 #36
0
ファイル: user.py プロジェクト: FMGordillo/price_of_chair_web
    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
コード例 #37
0
ファイル: user.py プロジェクト: cmj123/price-of-chair-learn
    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