Exemplo n.º 1
0
    def register(self, username: str, password: str, repeat_password: str):
        """
            Register new user if user is new and passwords match
        :param username:
        :param password:
        :param repeat_password:
        :return:
        """
        response = {"flash_message": "Invalid Credentials"}

        new_user = User({
            "username": username,
            "password": password,
        })
        # Check if User exists
        is_existing_user = self.get_user(new_user.get_username())

        if is_existing_user and is_existing_user.get_username() == username:
            response["flash_message"] = "username already in use"

        elif password == repeat_password:
            # hashing user password before storing in DB
            new_user.hash_password()
            create = self.create_user(new_user)  # returns None if create works
            if create:
                response[
                    "flash_message"] = "There was a problem when trying to create this user, Try Again!"
            else:
                response["flash_message"] = "Registration Successful!"
        else:
            response["flash_message"] = "Passwords do not match"

        return response["flash_message"]
Exemplo n.º 2
0
 def test_hash_and_check_password(self):
     given_password = "******"
     new_user = User({
         "username": "******",
         "password": "******"
     })
     new_user.hash_password()
     self.assertTrue(self.user.check_password(given_password))