Exemplo n.º 1
0
    def login(self, username, password, **options):
        """
        logs in the provided user and gets a valid token.

        :param str username: username.
        :param str password: password.

        :raises InvalidUserInfoError: invalid user info error.
        :raises UserNotFoundError: user not found error.
        :raises UserIsNotActiveError: user is not active error.

        :returns: a valid token.
        :rtype: str
        """

        if username is None or password is None:
            raise InvalidUsernameOrPasswordError(_('Username or password is invalid.'))

        store = get_current_store()
        user = store.query(UserEntity).filter(UserEntity.username == username).one_or_none()

        fail_message = _('User not found, make sure that '
                         'username and password are correct.')
        if user is None:
            raise UserNotFoundError(fail_message)

        if hashing_services.is_match(password, user.password_hash) is not True:
            raise UserNotFoundError(fail_message)

        if user.is_active is False:
            raise UserIsNotActiveError(_('User [{user_id}] is not active.'
                                         .format(user_id=user.id)))

        user.last_login_date = datetime_services.now()
        store.add(user)
        payload = DTO(user_id=user.id)

        return DTO(access_token=toke_services.generate_access_token(payload, is_fresh=True),
                   refresh_token=toke_services.generate_refresh_token(payload))
Exemplo n.º 2
0
class PersonIMDBPageValidator(HTTPSValidator):
    """
    person imdb page validator class.
    """

    regex = r'^https://www.imdb.com/name/nm[\d]+/$'
    default_minimum_length = 30
    default_maximum_length = 150
    default_allow_blank = False
    default_allow_whitespace = False
    default_nullable = True

    pattern_not_match_message = _('The provided value for [{param_name}] '
                                  'is not a valid imdb person page.')
Exemplo n.º 3
0
    def get(self, id):
        """
        gets actor with given id.

        it raises an error if actor does not exist.

        :param int id: person id.

        :raises ActorDoesNotExistError: actor does not exist error.

        :rtype: PersonEntity
        """

        entity = self._get(id)
        if entity is None:
            raise ActorDoesNotExistError(_('Actor with id [{id}] does not exist.')
                                         .format(id=id))
        return entity
Exemplo n.º 4
0
    def get(self, id):
        """
        gets genre with given id.

        it raises an error if genre does not exist.

        :param int id: genre id.

        :raises GenreDoesNotExistError: genre does not exist error.

        :rtype: GenreEntity
        """

        entity = self._get(id)
        if entity is None:
            raise GenreDoesNotExistError(
                _('Genre with id [{id}] does not exist.').format(id=id))
        return entity
Exemplo n.º 5
0
    def get(self, id):
        """
        gets language with given id.

        it raises an error if language does not exist.

        :param int id: language id.

        :raises LanguageDoesNotExistError: language does not exist error.

        :rtype: LanguageEntity
        """

        entity = self._get(id)
        if entity is None:
            raise LanguageDoesNotExistError(_('Language with id [{id}] does not exist.')
                                            .format(id=id))
        return entity
Exemplo n.º 6
0
    def get(self, province_id, **options):
        """
        gets the specified province.

        :param int province_id: province id to get its info.

        :raises ProvinceNotFoundError: province not found error.

        :returns: dict(int id,
                       str name)

        :rtype: dict
        """

        store = get_current_store()
        province = store.query(ProvinceEntity).get(province_id)

        if province is None:
            raise ProvinceNotFoundError(_('Province [{province_id}] not found.'
                                          .format(province_id=province_id)))

        return province.to_dict()
Exemplo n.º 7
0
    def get(self, city_id, **options):
        """
        gets the specified city.

        :param int city_id: city id to get its info.

        :raises CityNotFoundError: city not found error.

        :returns: dict(int id,
                       str name,
                       int province_id: province id)

        :rtype: dict
        """

        store = get_current_store()
        city = store.query(CityEntity).get(city_id)

        if city is None:
            raise CityNotFoundError(
                _('City [{city_id}] not found.'.format(city_id=city_id)))

        return city.to_dict()