Exemple #1
0
    def init_data(self, type_str, table):
        current_row = table.currentRow()
        column_count = table.columnCount()

        data = list()
        if type_str == 'account':
            for i in range(column_count - 2):
                item = table.item(current_row, i)
                if Utils.check_qt_item(item):
                    value = item.text()
                    value = int(value) if i == 2 else value
                    data.append(value)
                else:
                    data.append(None)

        elif type_str == 'course':
            for i in range(column_count - 2):
                item = table.item(current_row, i)
                if Utils.check_qt_item(item):
                    value = item.text()
                    value = int(value) if i == 0 else value
                    data.append(value)
                else:
                    data.append(None)
        else:
            for i in range(column_count - 2):
                item = table.item(current_row, i)
                if Utils.check_qt_item(item):
                    data.append(item.text())
                else:
                    data.append(None)

        return data
Exemple #2
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
Exemple #3
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
Exemple #4
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
Exemple #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
Exemple #6
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
Exemple #7
0
    def register_user(email, password):
        """
        This method registers a use using e-mail and password
        The password already comes hashed as sha-512
        :param email: User's email (might be invalid)
        :param passowrd: 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.UserAlreadyRegistered(
                "The email 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 email does not have right format.")
        hash_password = Utils.hash_password(password)
        user = User(email, hash_password)
        user.save_to_db()
        #User(email, Utils.hash_password(password)).save_to_db()

        return True
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()
Exemple #9
0
    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()
Exemple #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
Exemple #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
Exemple #12
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
Exemple #13
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
Exemple #14
0
    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
Exemple #15
0
    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
Exemple #16
0
 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
Exemple #17
0
    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
Exemple #18
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
    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
Exemple #20
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
Exemple #21
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
Exemple #22
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
Exemple #23
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
Exemple #24
0
 def register_user(email, password):
     user_data = Database.find_one(UserConstants.COLLECTION,
                                   {"email": email})
     if user_data is not None:
         # Tell User they are already registered
         raise err.UserAlreadyRegister("The email you used already exists")
     if not Utils.email_is_valid(email):
         # Tell user that their email is not constructed properly
         raise err.InvalidEmailError(
             "The email does not have the right format")
     User(email, Utils.hash_pasword(password)).save_to_db()
     return True
Exemple #25
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
Exemple #26
0
    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
Exemple #27
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
Exemple #28
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
Exemple #29
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 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
Exemple #30
0
    def register_user(email,password):

        user_data=Database.find_one('users',{'email':email})

        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError("The email u entered already exists.")

        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError("Your email has a invalid format.")


        User(email,Utils.hashed_password(password)).save_to_db()
        return True
    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
Exemple #32
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
Exemple #33
0
    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
Exemple #34
0
 def check_before_save(cls, username, password, firstname, lastname,
                       location, abonementtype, abonementstartdate, active):
     if Utils.isBlank(username) or Utils.isBlank(password) or Utils.isBlank(
             firstname) or Utils.isBlank(lastname) or Utils.isBlank(
                 location) or Utils.isBlank(active) or Utils.isBlank(
                     abonementtype) or Utils.isBlank(abonementstartdate):
         raise StudentErrror.StudentWrongInputDataException(
             "one of the input parameters is wrong. Please check ...")
Exemple #35
0
def index():
    news = [article for article in Database.find("articles",
                                                 {"page_id": uuid.UUID('{00000000-0000-0000-0000-000000000000}')},
                                                 sort='date',
                                                 direction=pymongo.DESCENDING,
                                                 limit=3)]
    events = [event for event in Database.find("events", {}, sort='start', direction=pymongo.DESCENDING, limit=3)]

    for article in news:
        article['summary'] = Utils.clean_for_homepage(article['summary'])
    for event in events:
        event['description'] = Utils.clean_for_homepage(event['description'])

    return render_template('home.html',
                           events=events,
                           news=news)
Exemple #36
0
    def register_user(email, password):
        if not Utils.email_is_valid(email):
            return False
        if User.find_by_email(email) is not None:
            return False

        encrypted_password = sha256(password.encode("utf-8"))
        user = User(email, encrypted_password.hexdigest(), permissions=Permissions.default().name)
        user.data.update(
            {"points": {"action": 0, "practice": 0, "theory": 0, "networking": 0, "virtual": 0, "project": 0}}
        )
        user.data.update(
            {
                "country": "",
                "university": "",
                "school": "",
                "firstname": "",
                "lastname": "",
                "year": "",
                "level": "",
                "subject": "",
            }
        )

        user.save_to_db()
        return True
Exemple #37
0
 def is_valid_login(username, password):
     user_data = Database.find_one(UserConstant.COLLECTION, {'username':username})
     if user_data is None:
         raise UserError.UserNotExist("User is not existing in the database")
     if not Utils.check_hashed_password(password, user_data['password']):
         raise UserError.PasswordIncorrect("Password is not correct")
     return True
Exemple #38
0
def events_list_page():
    events = [event for event in Database.find("events", {}, sort='start', direction=pymongo.DESCENDING)]

    for event in events:
        event['description'] = Utils.clean_for_homepage(event['description'])

    return render_template('items/events-list.html',
                           events=events)
Exemple #39
0
    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
Exemple #40
0
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')
Exemple #41
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
Exemple #42
0
    def is_login_valid(email, password):
        user_data = Database.find_one("users", {"email": email}) # Password is in sha512 -> pbdkf2_sha512
        if user_data is None:
            raise UserErrors.UserNotExistsError("Your user does not exist.")

        if not Utils.check_hashed_password(password,user_data['password']):
            raise UserErrors.IncorrectPasswordError("Your password was wrong.")

        return True
Exemple #43
0
    def is_login_valid(email,password):

        user_data=Database.find_one('users',{'email':email})
        if user_data is None:
            raise UserErrors.UserNotExistsError(" User does not exist!")

        elif  not Utils.check_hashed_password(password,user_data['password']):
            raise UserErrors.IncorrectPasswordError("Incorrect Password")
        else:
            return True
Exemple #44
0
def news_page(page_id=None):
    if page_id is None:
        page_id = uuid.UUID('{00000000-0000-0000-0000-000000000000}')
    news = [article for article in Database.find("articles",
                                                 {"page_id": page_id},
                                                 sort='date',
                                                 direction=pymongo.DESCENDING)]

    for article in news:
        article['summary'] = Utils.clean_for_homepage(article['summary'])

    return render_template('news.html',
                           news=news)
Exemple #45
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 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
Exemple #46
0
    def is_login_valid(email, password):

        user_data = Database.find_one(UserConstant.COLLECTION, {'email':email})

        if user_data is None:

            raise UserError.UserNotExistError("User doesn't exist")

        if not Utils.check_hashed_password(password, user_data['password']):

            raise UserError.IncorrectPasswordError("Password is not correct")

        return True
Exemple #47
0
def get_page(title):
    try:
        page = Page.get_by_title(title)
        news = []
        if page.get_feed():
            news = [article for article in Database.find("articles",
                                                         {"page_id": page.get_id()},
                                                         sort='date',
                                                         direction=pymongo.DESCENDING,
                                                         limit=3)]
            for article in news:
                article['summary'] = Utils.clean_for_homepage(article['summary'])
        return render_template('page.html', page=page.to_json(), news=news)
    except NoSuchPageExistException as e:
        abort(401)
Exemple #48
0
    def is_login_valid(email, password):
        user_data = Database.find_one(AdminConstants.COLLECTION, {"email": email})

        if user_data is None:
            raise AdminErrors.AdminNotExistError("Your email or password is wrong. <br>"
                                                 "Contact your admin if you need help"
                                                 "accessing your account.")
            pass
        if not Utils.check_hashed_password(password, user_data['password']):
            raise AdminErrors.AdminPasswordNotCorrect("Your email or password is wrong. "
                                                      "Contact your admin if you need help"
                                                      "accessing your account.")
            pass

        return True
Exemple #49
0
def register_user():
    email=request.form['email']
    password=request.form['password']
    if (email is "") or (password is ""):
        flash("Please fill email id and password")
    else:
        user_data = Database.find_one('users', {'email': email})
        if not Utils.email_is_valid(email):
            flash("Your email has a invalid format.")
        elif user_data is not None:
            flash("User email id already exists!")
        else:
            User.register(email,password)
            return render_template('profile.html', email=session['email'])

    return render_template('register.html')
Exemple #50
0
    def is_login_valid(email, password):
        """
        This method verifies that an e-mail/password combo (as sent by the site forms) is valid or not.
        Checks that the e-mail exists, and that the password associated to that e-mail is correct.
        :param email: The user's email
        :param password: A sha512 hashed password
        :return: True if valid, False otherwise
        """
        user_data = Database.find_one("users", {"email": email})  # Password in sha512 -> pbkdf2_sha512
        if user_data is None:
            # Tell the user that their e-mail doesn't exist
            raise UserErrors.UserNotExistsError("Your user does not exist.")
        if not Utils.check_hashed_password(password, user_data['password']):
            # Tell the user that their password is wrong
            raise UserErrors.IncorrectPasswordError("Your password was wrong.")

        return True
Exemple #51
0
    def is_login_valid(email, password):
        '''
        This method verifies that the email-password combo (as sent by the site forms) is valid or not
        Check that email exists, and that the password associate to that email is correct
        :param email: the user's email
        :param password: a sha512 hashed password
        :return: True if valid, False otherwise
        '''

        user_data = Database.find_one(UserConstants.COLLECTION, {'email': email}) # password in sha512 -> pbkdf2_sha512
        if user_data is None:
            #tell the user their password doesn't exists
            raise UserErrors.UserNotExistsError("Your user doesn't exists") # lo levantamos y lo podemos catchear desde donde se lo llame
        if not Utils.check_hashed_password(password, user_data['password']):
            # Tell the  user that their password is wrong
            raise UserErrors.IncorrectPasswordError("Your password was wrong")
        return True
Exemple #52
0
    def register_member(first_name, last_name, email, cell_phone):
        """
        Registers a Member. The Admin will have to create
        himself as a general user for scheduling purposes.
        :param first_name:
        :param last_name:
        :param email:
        :param cell_phone:
        :return:
        :return: True if registered successfully or False if otherwise (exceptions can be raised)
        """
        member_data = Database.find_one(MemberConstants.COLLECTION, {"email": email})

        if DEBUG is False:
            if member_data is not None:
                raise MemberErrors.MemberEmailAlreadyUsed("THe email address you used is already in use.")
        if not Utils.email_is_valid(email):
            raise MemberErrors.InvalidEmailError("Not a valid email format.")

        Member(first_name, last_name, email, cell_phone).save_to_mongo()

        return True
Exemple #53
0
 def test_remove_image(self):
     self.assertFalse('img' in str(Utils._remove_images(self.html)))
Exemple #54
0
 def test_paragraphs(self):
     self.assertFalse('img' in Utils._limit_characters(self.html, 5))
     self.assertFalse('h2' in Utils._limit_characters(self.html, 5))
     self.assertFalse('Hello, world!' in Utils._limit_characters(self.html, 5))
     self.assertTrue('Hello' in Utils._limit_characters(self.html, 5))