Esempio n. 1
0
    def log_user_out(self, token):
        validate_type(token, str, 'Type of token must be str')

        try:
            self.users_interface.log_user_out(token)
        except InvalidToken as error:
            raise error
Esempio n. 2
0
    def delete_user(self, token):
        validate_type(token, str, 'Type of token must be str')

        try:
            self.users_interface.delete_user(token)
        except (InvalidToken, TokenExpired) as error:
            raise error
Esempio n. 3
0
    def get_user_shortlinks_table(self, user_token):
        validate_type(user_token, str, 'Type of user_token must be str')

        try:
            table = self.users_links_interface.get_user_shortlinks_table(user_token)
            return table
        except (InvalidToken, TokenExpired) as error:
            raise error
Esempio n. 4
0
    def change_user_password(self, token, new_password):
        validate_type(token, str, 'Type of token must be str')
        validate_type(new_password, str, 'Type of new_password must be str')

        try:
            self.users_interface.change_user_password(token, new_password)
        except (InvalidToken, TokenExpired) as error:
            raise error
Esempio n. 5
0
    def delete_link(self, user_token, shortlink):
        validate_type(user_token, str, 'Type of user_token must be str')
        validate_type(shortlink, str, 'Type of shortlink must be str')

        try:
            self.users_links_interface.delete_link(user_token, shortlink)
        except (InvalidToken, TokenExpired, ShortLinkNotExists) as error:
            raise error
Esempio n. 6
0
    def create_user(self, email, password):
        validate_type(email, str, 'Type of email must be str')
        validate_type(password, str, 'Type of password must be str')

        try:
            self.users_interface.create_user(email, password)
        except EmailAlreadyTaken as error:
            raise error
Esempio n. 7
0
    def log_user_in(self, email, password):
        validate_type(email, str, 'Type of email must be str')
        validate_type(password, str, 'Type of password must be str')

        try:
            return self.users_interface.log_user_in(email, password)
        except (UserNotExists, WrongPassword) as error:
            raise error
Esempio n. 8
0
    def change_user_email(self, user_token, new_email):
        validate_type(user_token, str, 'Type of user_token must be str')
        validate_type(new_email, str, 'Type of new_email must be str')

        try:
            self.users_links_interface.change_user_email(user_token, new_email)
        except (InvalidToken, TokenExpired, EmailAlreadyTaken) as error:
            raise error
Esempio n. 9
0
 def __init__(self, links_interface, users_interface):
     validate_type(
         links_interface, LinksInterface,
         'Type of links_interface should be derived from LinksInterface')
     validate_type(
         users_interface, UsersInterface,
         'Type of users_interface should be derived from UsersInterface')
     self.links_interface = links_interface
     self.users_interface = users_interface
Esempio n. 10
0
    def get_longlink_from_shortlink(self, shortlink, password=''):
        validate_type(shortlink, str, 'Type of shortlink must be str')
        validate_type(password, str, 'Type of password must be str')

        try:
            longlink = self.links_interface.get_longlink_from_shortlink(shortlink, password)
            return longlink
        except (ShortLinkNotExists, IncorrectPasswordForShortLink) as error:
            raise error
Esempio n. 11
0
def validate_link_password(password):
    validate_type(password, str, 'Type of password must be str')

    shortlink_length = len(password)
    if shortlink_length > 30:
        raise ValidationError('Password\'s length must be in range(0, 30)')

    if not check_for_required_characters(
            password,
            'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_'):
        raise ValidationError('Invalid characters for link\'s password')
Esempio n. 12
0
def validate_shortlink(shortlink):
    validate_type(shortlink, str, 'Type of shortlink must be str')

    shortlink_length = len(shortlink)
    if shortlink_length < 4 or shortlink_length > 40:
        raise ValidationError('Shortlink\'s length must be in range(4, 40)')

    if not check_for_required_characters(
            shortlink,
            'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
        raise ValidationError('Invalid characters for shortlink')
Esempio n. 13
0
    def change_user_email(self, token, new_email):
        validate_type(new_email, str, 'Type of new_email must be str')

        try:
            self.users_interface.change_user_email(token, new_email)
            try:
                self.log_user_out(token)
            except InvalidToken:
                pass
        except (EmailAlreadyTaken, InvalidToken) as error:
            raise error
Esempio n. 14
0
def validate_longlink(longlink):
    validate_type(longlink, str, 'Type of longlink must be str')

    shortlink_length = len(longlink)
    if shortlink_length < 1 or shortlink_length > 400:
        raise ValidationError('Longlink\'s length must be in range(1, 400)')

    if not check_for_required_characters(
            longlink,
            'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/:?=&_@#.'
    ):
        raise ValidationError('Invalid characters for longlink')
Esempio n. 15
0
    def add_link(self, user_token, shortlink, longlink, password=''):
        validate_type(user_token, str, 'Type of user_token must be str')
        validate_type(shortlink, str, 'Type of shortlink must be str')
        validate_type(longlink, str, 'Type of longlink must be str')
        validate_type(password, str, 'Type of password must be str')

        try:
            self.users_links_interface.add_link(user_token, shortlink, longlink, password)
        except (InvalidToken, TokenExpired, ShortLinkAlreadyTaken) as error:
            raise error
Esempio n. 16
0
    def modify_shortlink(self, user_token, old_shortlink, new_shortlink):
        validate_type(user_token, str, 'Type of user_token must be str')
        validate_type(old_shortlink, str, 'Type of old_shortlink must be str')
        validate_type(new_shortlink, str, 'Type of new_shortlink must be str')

        try:
            self.users_links_interface.modify_shortlink(user_token, old_shortlink, new_shortlink)
        except (InvalidToken, TokenExpired, ShortLinkNotExists, ShortLinkAlreadyTaken) as error:
            raise error
Esempio n. 17
0
    def modify_password(self, user_token, shortlink, new_password):
        validate_type(user_token, str, 'Type of user_token must be str')
        validate_type(shortlink, str, 'Type of shortlink must be str')
        validate_type(new_password, str, 'Type of new_password must be str')

        try:
            self.users_links_interface.modify_password(user_token, shortlink, new_password)
        except (InvalidToken, TokenExpired, ShortLinkNotExists) as error:
            raise error
Esempio n. 18
0
    def add_random_link(self, user_token, longlink, password=''):
        validate_type(user_token, str, 'Type of user_token must be str')
        validate_type(longlink, str, 'Type of longlink must be str')
        validate_type(password, str, 'Type of password must be str')

        try:
            shortlink = self.users_links_interface.add_random_link(user_token, longlink, password)
            return shortlink
        except (InvalidToken, TokenExpired) as error:
            raise error
Esempio n. 19
0
 def set_expiration_date(self, expiration_date):
     validate_type(expiration_date, [datetime.date, None],
                   'Type of expiration_date must be datetime.date or None')
     self.expiration_date = expiration_date
Esempio n. 20
0
 def set_if_belongs_to_user(self, belongs_to_user):
     validate_type(belongs_to_user, bool,
                   'Type of belongs_to_user must be bool')
     self.does_exist = belongs_to_user
Esempio n. 21
0
 def set_if_need_password(self, need_password):
     validate_type(need_password, bool,
                   'Type of need_password must be bool')
     self.does_exist = need_password
Esempio n. 22
0
 def set_does_exist(self, does_exist):
     validate_type(does_exist, bool, 'Type of does_exist must be bool')
     self.does_exist = does_exist
Esempio n. 23
0
    def add_anonymous_shortlink(self, longlink, password=''):
        validate_type(longlink, str, 'Type of longlink must be str')
        validate_type(password, str, 'Type of password must be str')

        self.links_interface.add_anonymous_shortlink(longlink, password)
Esempio n. 24
0
 def __init__(self, users_interface):
     validate_type(users_interface, UsersInterface,
                   'Type of users_interface should be derived from UsersInterface')
     self.users_interface = users_interface
Esempio n. 25
0
    def get_shortlink_data(self, shortlink):
        validate_type(shortlink, str, 'Type of shortlink must be str')

        data = self.links_interface.get_shortlink_data(shortlink)
        return data