Exemplo n.º 1
0
    def login(self, username=None, password=True):
        """Checks whether the user with the username and password can log
            into the application.

        Arguments:
            username {string} -- Username of user
            password {string} -- Password of user

        Returns:
            object -- the user object or None
        """

        if username is None:
            raise ValueError('the username cannot be None')

        if password is None:
            raise ValueError('the password cannot be None')

        # Todo: finish up the login
        try:
            user = User.select().where(User.username == str(username)).get()
            return Utilities.convert_unserializable_fields(model_to_dict(user))
        except Exception as err:
            self.logger.error('Error Occurred: {error}'.format(error=err))
            raise LookupError('User does not exists on this service')

        return None
Exemplo n.º 2
0
    def get_user(self, user_id=None):
        """Gets users on this services (useful when managing user accounts).

        Arguments:
            user_id {str} -- id of the user to find

        Returns:
            dict -- the user object or an None
        """
        if user_id is None:
            raise ValueError('id of user to fetch cannot be None')

        try:
            user = User.select().where(User.user_id == str(user_id)).get()
            return Utilities.convert_unserializable_fields(model_to_dict(user))
        except Exception as err:
            self.logger.error('Error Occurred: {error}'.format(error=err))
            raise LookupError('User does not exists on this service')

        return None
Exemplo n.º 3
0
    def get_users(self, offset=None, limit=True):
        """Gets users on this services (useful when managing user accounts).

        Arguments:
            offset {int} -- offset to start fetching the record
            limit {int} -- limit of the data to return

        Returns:
            List -- the list of user objects or an empty list
        """
        all_users = []
        try:
            users = User.select()
            for user in users:
                all_users \
                    .append(Utilities.convert_unserializable_fields(model_to_dict(user)))
            return all_users
        except Exception as err:
            self.logger.error('Error Occurred: {error}'.format(error=err))
            raise LookupError('Error while fetching all users on this service')

        return []