Exemple #1
0
class UpdateUsername(Resource):
    @account_api.expect(create_model(
        'Username update data',
        {'username': fields.String(description='The new username.')}),
                        validate=True)
    @account_api.response(
        code=200,
        description='Updated Successfully.',
        model=create_model(
            'token',
            model={'token': fields.String(description='Access token.')}))
    @account_api.response(code=404, description='Username already exists')
    @account_api.doc(security='KwikkerKey')
    @authorize
    def put(self, authorized_username):
        """ Updates the user's username. """
        data = request.get_json()
        is_updated = actions.update_user_username(authorized_username,
                                                  data['username'])
        if is_updated:
            token = actions.create_token(
                data['username'],
                actions.get_user_by_username(data['username'])['password'])
            token = token.decode('utf-8')
            return {'token': token}, 200
        else:
            abort(404, message='Username already exists')
        pass
Exemple #2
0
class UpdatePassword(Resource):
    @account_api.expect(create_model(
        'New Password', {
            'password': fields.String(description='The new password.'),
        }),
                        validate=True)
    @account_api.response(
        code=200,
        description='Updated Successfully.',
        model=create_model(
            'token',
            model={'token': fields.String(description='Access token.')}))
    @user_api.response(code=401, description='Unauthorized access.')
    @user_api.response(code=404, description='Update failed.')
    @account_api.doc(security='KwikkerKey')
    @authorize
    def put(self, authorized_username):
        """ Updates the user's password. """
        data = request.get_json()
        is_updated = actions.update_user_password(authorized_username,
                                                  data['password'])
        if is_updated:
            token = actions.create_token(authorized_username, data['password'])
            token = token.decode('utf-8')
            return {'token': token}, 200
        else:
            abort(404)
        pass
Exemple #3
0
class Login(Resource):
    @account_api.response(
        code=200,
        description='Logged in successfully.',
        model=create_model(
            'token',
            model={'token': fields.String(description='Access token.')}))
    @account_api.response(
        code=404,
        description='A user with matching credentials does not exist.')
    @account_api.expect(create_model(
        'User Credentials', {
            'username':
            fields.String(description='The username of the user logging in.'),
            'password':
            fields.String(description='The password of the user logging in.')
        }),
                        validate=True)
    def post(self):
        """ Authenticates user and provide an access token for Kwikker. """
        data = request.get_json()
        is_verified = actions.verify(data['username'], data['password'])
        if not is_verified:
            abort(404,
                  message='A user with matching credentials does not exist.')
        else:
            token = actions.create_token(data['username'], data['password'])
            token = token.decode('utf-8')
            return {'token': token}, 200
        pass
Exemple #4
0
class Notifications(Resource):
    @notifications_api.response(
        code=200,
        description='Notifications returned successfully.',
        model=create_model(
            'Notifications',
            model={
                'unseen_count':
                fields.Integer('The number of unseen notifications.'),
                'Notifications':
                fields.List(fields.Nested(Notification.api_model))
            }))
    @notifications_api.response(code=401, description='Unauthorized access.')
    @notifications_api.response(code=404,
                                description="Notification id does not exist.")
    @notifications_api.response(code=500,
                                description='An error occurred in the server.')
    @notifications_api.response(code=400, description='Invalid ID provided.')
    @notifications_api.param(
        name='last_notification_retrieved_id',
        type="str",
        description=
        'Nullable. Normally the request returns the first 20 notifications when null. '
        'To retrieve more send the id of the last retrieved notification.')
    @notifications_api.marshal_with(
        create_model('Notifications',
                     model={
                         'unseen_count':
                         fields.Integer('The number of unseen notifications.'),
                         'Notifications':
                         fields.List(fields.Nested(Notification.api_model))
                     }))
    @notifications_api.doc(security='KwikkerKey')
    @authorize
    def get(self, authorized_username):
        """ Retrieves a list of user's notifications. """
        last_notification_retrieved_id = request.args.get(
            'last_notification_retrieved_id')
        try:
            notifications = actions.get_notifications(
                authorized_username, last_notification_retrieved_id)
            if notifications is None:
                abort(404,
                      message=
                      'A notification with the provided ID does not exist.')
            else:
                if len(notifications) == 0:
                    return {'unseen_count': 0, 'Notifications': []}
                unseen_count = actions.get_notifications_unseen_count(
                    authorized_username)
                actions.set_notifications_as_seen(authorized_username)
                return {
                    'unseen_count': unseen_count,
                    'Notifications': notifications
                }
        except TypeError:
            abort(500, message='An error occurred in the server.')
        except ValueError:
            abort(400, message='Invalid ID provided.')
Exemple #5
0
class Registration(Resource):
    @account_api.response(
        code=201,
        description='User registered successfully, email confirmation pending.'
    )
    @account_api.response(code=403,
                          description='Username or email already exists.',
                          model=create_model(
                              'Registration Failure', {
                                  'username_already_exists': fields.Boolean,
                                  'email_already_exists': fields.Boolean
                              }))
    @account_api.response(code=404,
                          description='Empty field(s). or Invalid email.')
    @account_api.expect(create_model(
        'User Registration Data', {
            'username':
            fields.String(description='The username of the new user.'),
            'password':
            fields.String(description='The password of the new user.'),
            'email':
            fields.String(description='The email of the new user.'),
            'screen_name':
            fields.String(description='The screen name of the new user.'),
            'birth_date':
            fields.Date(description='The birth-date of the new user.')
        }),
                        validate=True)
    def post(self):
        """ Register a new user. The user then is required to confirm their email address. """
        data = request.get_json()
        if data['password'] == "" or data['username'] == "" or data['email'] == "" or data['birth_date'] == "" \
                or data['screen_name'] == "":
            abort(404, message='Empty field(s).')
        is_valid_email = actions.validate_email(data['email'])
        if not is_valid_email:
            abort(404, message='Invalid email.')
        user_exist, email_exist = actions.add_user(data['username'],
                                                   data['password'],
                                                   data['email'])
        if not (user_exist or email_exist):
            create_profile(data['username'], data['screen_name'],
                           data['birth_date'])
            html = '<p>Confirming your account will give you </p> <b>full access to Kwikker</b>'
            subject = 'Confirm your Kwikker account, ' + data['username']
            # (email, username, password, subject, url, html, confirm)
            actions.send_email(data['email'], data['username'],
                               data['password'], subject, '/confirm/', html,
                               True)
            return "", 201
        else:
            return {
                'username_already_exists': user_exist,
                'email_already_exists': email_exist
            }, 403
        pass
Exemple #6
0
class UserProfile(Resource):
    @user_api.response(code=200, description='Profile updated.')
    @user_api.response(code=404, description='Update failed.')
    @user_api.response(code=401, description='Unauthorized access.')
    @user_api.expect(create_model('Profile', model={
        'bio': NullableString(description='Nullable if unchanged. The biography of the user.'),
        'screen_name': NullableString(description='Nullable if unchanged. The name shown on profile screen.')
    }), validate=True)
    @user_api.doc(security='KwikkerKey')
    @authorize
    def patch(self, authorized_username):
        """ Update the biography or screen name in user profile."""
        data = request.get_json()
        bio = data.get('bio')
        screen_name = data.get('screen_name')
        response = actions.update_user_profile(authorized_username, bio, screen_name)
        if response == - 1:
            abort(404, message='update failed.')
        if response == 0:
            return abort(400, 'pay load is empty or equal to null no update happened')
        return 'profile updated', 200

    @user_api.response(code=200, description='User profile returned successfully.', model=UserProfile.api_model)
    @user_api.response(code=404, description='User does not exist.')
    @user_api.response(code=401, description='Unauthorized access.')
    @user_api.response(code=400, description='Parameters type does not match.')
    @user_api.response(code=403, description='Profile of a blocking user.', model=create_model('Blocking profile', model={
                                'username': fields.String(description='The user name.'),
                                'screen_name': fields.String(description='The name shown on profile screen.'),
                                'profile_banner_url': fields.String(description='Url for profile banner'),
                                'profile_image_url': fields.String(description='Url for profile image.')
                            }))
    @user_api.marshal_with(UserProfile.api_model, as_list=True)
    @user_api.param(name='username', type='str', required=True, description='The username.')
    @user_api.doc(security='KwikkerKey')
    @authorize
    def get(self, authorized_username):
        """ Retrieve the profile of a specific user. """
        username = request.args.get('username')
        response = actions.get_user_profile(authorized_username, username)
        if response == - 1:
            return abort(404, message='User does not exist.')
        if response == Exception:
            return abort(409, message='conflict happened.')
        check_block = user_interaction_query_factory.if_blocked(username, authorized_username)['count']
        if check_block == 1:
            print(response)
            return response, 403
        return response, 200
Exemple #7
0
class UpdateEmail(Resource):
    @user_api.expect(create_model(
        'New Email', {
            'email': fields.String(description='The new email.'),
        }),
                     validate=True)
    @user_api.response(code=200, description='Email updated.')
    @user_api.response(code=401, description='Unauthorized access.')
    @user_api.doc(security='KwikkerKey')
    @authorize
    def put(self, authorized_username):
        """ Updates the user's email."""
        data = request.get_json()
        is_valid_email = actions.validate_email(data['email'])
        if not is_valid_email:
            abort(404, message='Invalid email.')
        is_updated = actions.update_user_email(authorized_username,
                                               data['email'])
        if is_updated:
            return "", 200
        else:
            abort(404, message='Email already exists.')
        pass

    @user_api.response(
        code=200,
        description='Email returned successfully.',
        model=create_model(
            'Email',
            model={
                'email':
                fields.String(
                    description='Holds the value of Email requested.')
            }))
    @user_api.response(
        code=404,
        description=
        'An unconfirmed user with the given confirmation code does not exist.')
    @user_api.response(code=401, description='Unauthorized access.')
    @user_api.response(code=404, description='Invalid username')
    @user_api.doc(security='KwikkerKey')
    @authorize
    def get(self, authorized_username):
        """ Get the user email"""
        user = actions.get_user_by_username(authorized_username)
        if not user:
            abort(404, message='Invalid username. Please login again.')
        return {"email": user['email']}, 200
        pass
Exemple #8
0
class Follow(Resource):
    @interactions_api.response(code=201,
                               description='User followed successfully.')
    @interactions_api.response(code=404, description='User does not exist.')
    @interactions_api.response(code=400,
                               description='Parameters type does not match.')
    @interactions_api.response(code=401, description='Unauthorized access.')
    @interactions_api.expect(
        create_model(
            'Username',
            model={
                'username':
                fields.String(
                    description="The username of the user to be followed.")
            }))
    def post(self):
        """ Follow a certain user using their username. """
        pass

    @interactions_api.response(code=204,
                               description='User unfollowed successfully.')
    @interactions_api.response(code=404, description='User does not exist.')
    @interactions_api.response(code=400,
                               description='Parameters type does not match.')
    @interactions_api.response(code=401, description='Unauthorized access.')
    @interactions_api.param(
        name='username',
        type='str',
        required=True,
        description='The username of the user to be unfollowed.')
    def delete(self):
        """ Unfollow a certain user using their username. """
Exemple #9
0
class ResetPassword(Resource):
    @account_api.expect(create_model(
        'Reset Password Data', {
            'password': fields.String(description='The new password.'),
        }),
                        validate=True)
    @account_api.response(code=200, description='Reset Successfully.')
    @account_api.response(code=403, description='code is missing.')
    @account_api.response(code=404,
                          description='New password is empty or reset failed')
    @account_api.response(
        code=401,
        description='unauthorized code. Invalid, expired or user not found')
    @account_api.doc(security='KwikkerCode')
    def put(self):
        """ Updates the user's password. """
        data = request.get_json()
        code = None
        if 'CODE' in request.headers:
            code = request.headers['CODE']
        else:
            abort(403, message='Code is missing.')
        username, password = actions.get_user(code)
        if data['password'] == '':
            abort(404, message='New password is empty')
        is_updated = actions.update_user_password(username, data['password'])
        if is_updated:
            return "", 200
        else:
            abort(404, message='Reset failed.')
        pass
Exemple #10
0
class ConversationersUnseen(Resource):
    @messages_api.response(
        code=200,
        description='number of unseen conversations returned successfully.')
    @messages_api.response(code=401, description='Unauthorized access.')
    @messages_api.response(code=500,
                           description='An error occurred in the server.')
    @messages_api.doc(security='KwikkerKey')
    @authorize
    def get(self, authorized_username):
        """ Retrieves a number of unseen conversations. """
        unseen_count = actions.get_unseen_conversations(authorized_username)
        if unseen_count is None:
            abort(500, message='An error occurred in the server.')
        return {'unseen_count': unseen_count}

    @messages_api.response(code=200, description='success.')
    @messages_api.response(code=401, description='Unauthorized access.')
    @messages_api.response(code=404, description='User does not exist.')
    @messages_api.expect(
        create_model('to_user',
                     model={'to_user': fields.String(description='to user')}))
    @messages_api.doc(security='KwikkerKey')
    @authorize
    def post(self, authorized_username):
        data = request.get_json()
        to_username = data["to_user"]
        actions.acknowledge(authorized_username, to_username)
        return {'message': 'success'}, 200
Exemple #11
0
class Hashtag:
    api_model = create_model(
        'Hashtag', {
            'id':
            fields.String(description='The unique id of the trend.'),
            'indices':
            fields.List(
                fields.Integer,
                description=
                'The indices of the beginning and ending of the hashtag in the kweek.'
            ),
            'text':
            fields.String(description='The body of the hashtag.')
        })

    def __init__(self, json):
        self.id = json['id']
        self.indices = (json['indices'][0], json['indices'][1])
        self.text = (json['text'])

    def __repr__(self):
        return "<id:%s indices:%s text:%s >" % \
               (self.id, self.indices, self.text)

    def to_json(self):
        return {
            'id': self.id,
            'indices': [self.indices[0], self.indices[1]],
            'text': self.text
        }
Exemple #12
0
class Mention:
    api_model = create_model(
        'Mention', {
            'username':
            fields.String(description='The username of the mentioned user.'),
            'indices':
            fields.List(
                fields.Integer,
                description=
                'The indices of the beginning and ending of the mention in the kweek.'
            )
        })

    def __init__(self, json):
        self.username = json['username']
        self.indices = (json['indices'][0], json['indices'][1])

    def __repr__(self):
        return "<username:%s indices:%s  >" % \
               (self.username, self.indices)

    def to_json(self):
        return {
            'username': self.username,
            'indices': [self.indices[0], self.indices[1]]
        }
Exemple #13
0
class ForgetPassword(Resource):
    @account_api.expect(create_model(
        'Email - Forget Password', {
            'email':
            fields.String('The email of the user requesting a password reset.')
        }),
                        validate=True)
    @account_api.response(code=200,
                          description='A new password was sent successfully.')
    @account_api.response(
        code=404,
        description=
        'A user with the provided email does not exist. or Invalid email.')
    def post(self):
        """ Sends email to the user which give him access to change the password. """
        data = request.get_json()
        user = actions.get_user_by_email(data['email'])
        if user is None:
            abort(404,
                  message='A user with the provided email does not exist.')
        is_valid_email = actions.validate_email(data['email'])
        if not is_valid_email:
            abort(404, message='Invalid email.')
        html = '<p>To reset your password </p>'
        subject = 'Request for changing password, ' + user['username']
        actions.send_email(data['email'], user['username'], user['password'],
                           subject, '/reset_password/', html, True)
        return "", 200
        pass
Exemple #14
0
class Media(Resource):
    @media_api.response(
        code=201,
        description='Image has been uploaded successfully',
        model=create_model(
            'Media ID',
            model={
                'media_id':
                fields.String(description='The id of the uploaded image.')
            }))
    @media_api.response(code=404,
                        description='Media not found. Uploading failed.')
    @media_api.response(code=401, description='Unauthorized access.')
    @media_api.response(code=400, description='Not allowed extensions.')
    @media_api.param(name='file',
                     description='image file.',
                     required=True,
                     type='file',
                     _in='form-Data')
    @media_api.doc(security='KwikkerKey')
    @authorize
    def post(self, authorized_username):
        """
        Post a new media file. and return id of the file without extension
        """
        print(request)
        if 'file' not in request.files:
            return abort(404, message='No image file')
        file = request.files['file']
        response = actions.save_file(file)
        if response == 'No selected file':
            return abort(404, message=response)
        if response == 'not allowed extensions':
            return abort(400, message=response)
        return {"media_id": response}, 200
Exemple #15
0
class Conversation:
    api_model = create_model(
        'Conversation', {
            'user':
            fields.Nested(
                User.api_model,
                description='The user information a.k.a mini-user information.'
            ),
            'last_message':
            fields.Nested(DirectMessage.api_model,
                          description='Last message information.'),
            'is_seen':
            fields.Boolean(description='Is the conversation seen ')
        })

    def __init__(self, json):
        self.user = json['user'],
        self.last_message = json['last_message'],
        self.is_seen = json['is_seen']

    def to_json(self):
        return {
            'user': self.user[0],
            'last_message': self.last_message[0],
            'is_seen': self.is_seen
        }
Exemple #16
0
class RegistrationResendEmail(Resource):
    @account_api.expect(create_model(
        'Email - Resend Confirmation Email', {
            'email':
            fields.String('The email of the user pending email confirmation.')
        }),
                        validate=True)
    @account_api.response(code=200, description='Email resent successfully.')
    @account_api.response(code=404, description='Invalid email.')
    @account_api.response(
        code=404, description='A user with the provided email does not exist.')
    def post(self):
        """ Re-sends an email to confirm the user registration. """
        data = request.get_json()
        user = actions.get_user_by_email(data['email'])
        if user is None:
            abort(404,
                  message='A user with the provided email does not exist.')
        is_valid_email = actions.validate_email(data['email'])
        if not is_valid_email:
            abort(404, message='Invalid email.')
        html = '<p>Confirming your account will give you </p> <b>full access to Kwikker</b>'
        subject = 'Confirm your Kwikker account, ' + user['username']
        actions.send_email(data['email'], user['username'], user['password'],
                           subject, '/confirm/', html, True)
        return "", 200
        pass
Exemple #17
0
class RekweekInfo:
    api_model = create_model(
        'Rekweek Info', {
            'rekweeker_name':
            fields.String(
                description=
                'The screen name of the user who rekweeked the kweek.'),
            'rekweeker_username':
            fields.String(
                description='The username of the user who rekweeked the kweek.'
            )
        })

    def __init__(self, json):
        self.rekweeker_name = json['rekweeker_name']
        self.rekweeker_username = json['rekweeker_username']

    def __repr__(self):
        return "<rekweeker_name:%s rekweeker_username:%s  >" % \
               (self.rekweeker_name, self.rekweeker_username)

    def to_json(self):
        return {
            'rekweeker_name': self.rekweeker_name,
            'rekweeker_username': self.rekweeker_username
        }
Exemple #18
0
class User:
    api_model = create_model(
        'User', {
            'username':
            fields.String(description='The user name.'),
            'screen_name':
            fields.String(description='The name shown on profile screen.'),
            'profile_image_url':
            fields.String(description='Url for profile image.'),
            'following':
            fields.Boolean(
                description=
                'Nullable. Does the authorized user follow this user? '
                'Null if the authorized user is the same as the user in the query.'
            ),
            'follows_you':
            fields.Boolean(
                description=
                'Nullable. Does this user follow the authorized user? '
                'Null if the authorized user is the same as the user in the query.'
            ),
            'blocked':
            fields.Boolean(
                description=
                'Nullable. Is this user blocked by the authorized user? '
                'Null if the authorized user is the same as the user in the query.'
            ),
            'muted':
            fields.Boolean(
                description=
                'Nullable. Is this user muted by the authorized user? '
                'Null if the authorized user is the same as the user in the query.'
            )
        })

    def __init__(self, json):
        self.username = json["username"]
        self.screen_name = json["screen_name"]
        self.profile_image_url = json["profile_image_url"]
        self.following = json["following"]
        self.follows_you = json["follows_you"]
        self.blocked = json["blocked"]
        self.muted = json["muted"]

    def to_json(self):
        return {
            'username': self.username,
            'screen_name': self.screen_name,
            'profile_image_url': self.profile_image_url,
            'following': self.following,
            'follows_you': self.follows_you,
            'blocked': self.blocked,
            'muted': self.muted
        }

    def __repr__(self):
        return "<Test username:%s screen_name:%s profile_image_url:%s following:%s follows_you:%s" \
               " blocked:%s muted:%s   >" % \
               (self.username, self.screen_name, self.profile_image_url, self.following, self.follows_you,
                self.blocked, self.muted)
Exemple #19
0
class Follow(Resource):
    @interactions_api.response(code=201,
                               description='User followed successfully.')
    @interactions_api.response(code=404, description='User does not exist.')
    @interactions_api.response(code=400,
                               description='Parameters type does not match.')
    @interactions_api.response(code=401, description='Unauthorized access.')
    @interactions_api.expect(
        create_model(
            'Username',
            model={
                'username':
                fields.String(
                    description="The username of the user to be followed.")
            }))
    @interactions_api.doc(security='KwikkerKey')
    @authorize
    def post(self, authorized_username):
        """ Follow a certain user using their username. """
        data = request.get_json()
        username = data.get('username')
        if not trends_actions.is_user(username):
            abort(404, message='A user with this username does not exist.')
        if username == authorized_username:
            abort(400, message='A bad request can not follow your self')
        response = actions.follow(username=username,
                                  authorized_username=authorized_username)
        if response is None:
            return 'User followed successfully', 200
        return response, 400

    @interactions_api.response(code=204,
                               description='User unfollowed successfully.')
    @interactions_api.response(code=404, description='User does not exist.')
    @interactions_api.response(code=400,
                               description='Parameters type does not match.')
    @interactions_api.response(code=401, description='Unauthorized access.')
    @interactions_api.param(
        name='username',
        type='str',
        required=True,
        description='The username of the user to be unfollowed.')
    @interactions_api.doc(security='KwikkerKey')
    @authorize
    def delete(self, authorized_username):
        """ Unfollow a certain user using their username. """
        if 'username' not in request.args.keys():
            abort(404, message='No username was sent.')
        username = request.args.get('username')
        if not trends_actions.is_user(username):
            abort(404, message='A user with this username does not exist.')
        if username == authorized_username:
            abort(400, message='A bad request can not unfollow your self')
        response = actions.unfollow(username=username,
                                    authorized_username=authorized_username)
        if response is None:
            return 'User unfollowed successfully', 200
        return response, 400
Exemple #20
0
class Notification:
    api_model = create_model(
        'Notification',
        {
            'id':
            fields.String(
                description='A unique string representing the notification.'),
            'created_at':
            fields.String(
                description='The utc datetime of the notification when created.'
            ),
            'type':
            fields.String(
                description=
                'Type of the notification [possible values:follow,rekweek,like,reply, '
                'mentions].'),
            'username':
            fields.String(description='Username of the notification.'
                          ),  # involved_username
            'screen_name':
            fields.String(
                description='Handle that the user identifies themselves with.'
            ),
            'kweek_id':
            fields.String(
                description=
                'Nullable,a unique string representing the kweek id.',
                nullable=True),  # Nullable
            'kweek_text':
            fields.String(description='The text of the kweek.'),
            'profile_pic_url':
            fields.String(
                description=
                'The profile picture URL of the involved person who liked,'
                'followed,etc).')
        })

    def __init__(self, json):
        self.id = json['id']
        self.created_at = json['created_at']
        self.type = json['type']
        self.username = json['username']
        self.screen_name = json['screen_name']
        self.kweek_id = json['kweek_id']
        self.kweek_text = json['kweek_text']
        self.profile_pic_url = json['profile_pic_url']

    def to_json(self):
        return {
            'id': self.id,
            'created_at': self.created_at,
            'type': self.type,
            'username': self.username,
            'screen_name': self.screen_name,
            'kweek_id': self.kweek_id,
            'kweek_text': self.kweek_text,
            'profile_pic_url': self.profile_pic_url
        }
Exemple #21
0
class Rekweek(Resource):
    @kweeks_api.expect(create_model(
        'Kweek ID', {
            'id':
            fields.String(description='The id of the kweek to be rekweeked.')
        }),
                       validate=True)
    @kweeks_api.response(code=401, description='Unauthorized access.')
    @kweeks_api.response(code=400, description='Invalid kweek ID.')
    @kweeks_api.response(code=404, description='Kweek does not exist.')
    @kweeks_api.response(code=200,
                         description='Rekweek has been created successfully.')
    @kweeks_api.doc(security='KwikkerKey')
    @authorize
    def post(self, authorized_username):
        """
        Create a new Rekweek.
        """
        check, message, code = create_rekweek(request.get_json(),
                                              authorized_username)
        if check:
            return 'Rekweek has been created successfully.', 200
        else:
            abort(code, message)

    @kweeks_api.response(code=200,
                         description='Rekweek has been deleted successfully.')
    @kweeks_api.response(code=400, description='Invalid kweek ID.')
    @kweeks_api.response(code=404, description='Kweek does not exist.')
    @kweeks_api.response(code=401, description='Deletion is not allowed.')
    @kweeks_api.response(code=401, description='Unauthorized access.')
    @kweeks_api.param(name='id',
                      type='string',
                      description='Id of the rekweek to be deleted',
                      required=True)
    @kweeks_api.doc(security='KwikkerKey')
    @authorize
    def delete(self, authorized_username):
        """
        Delete an existing rekweek.
        """
        if not request.args.get('id'):
            abort(400, 'please provide the kweek id')
        check, message, code = delete_rekweek(request.args.get('id'),
                                              authorized_username)
        if check:
            return 'Rekweek has been deleted successfully.', 200
        else:
            abort(code, message)
Exemple #22
0
class Like(Resource):
    @kweeks_api.response(code=201,
                         description='Kweek has been liked successfully.')
    @kweeks_api.response(code=404, description='Kweek does not exist.')
    @kweeks_api.response(code=401, description='Unauthorized access.')
    @kweeks_api.expect(create_model(
        'Kweek ID',
        {'id': fields.String(description='The id of the kweek to be liked.')}),
                       validate=True)
    @kweeks_api.doc(security='KwikkerKey')
    @authorize
    def post(self, authorized_username):
        """
         Like a rekweek.
        """
        check, message = like_kweek(request.get_json(), authorized_username)
        if check:
            return 'success', 201
        else:
            abort(404, message)

    @kweeks_api.response(code=204,
                         description='Kweek has been unliked successfully.')
    @kweeks_api.response(code=404, description='Kweek does not exist.')
    @kweeks_api.response(code=401, description='Unauthorized access.')
    @kweeks_api.param(name='id',
                      type='str',
                      description='The id of the kweek to be disliked',
                      required=True)
    @kweeks_api.doc(security='KwikkerKey')
    @authorize
    def delete(self, authorized_username):
        """
        Dislike a rekweek.
        """
        if not request.args.get('id'):
            abort(400, 'please provide the kweek id')
        check, message = dislike_kweek(request.args.get('id'),
                                       authorized_username)
        if check:
            return 'success', 201
        else:
            abort(404, message)
Exemple #23
0
class Media(Resource):
    @media_api.param(name='image_file', description='Image file.', type='file')
    @media_api.response(
        code=201,
        description='Image has been uploaded successfully',
        model=create_model(
            'Media ID',
            model={
                'media_id':
                fields.String(description='The id of the uploaded image.')
            }))
    @media_api.response(code=404,
                        description='Media not found. Uploading failed.')
    @media_api.response(code=401, description='Unauthorized access.')
    def post(self):
        """
            Post a new media file .
            """
        pass
Exemple #24
0
class RegistrationConfirmation(Resource):
    @account_api.expect(create_model(
        'Confirmation Code', {
            'confirmation_code':
            fields.String('The confirmation code of the user.')
        }),
                        validate=True)
    @account_api.response(code=200, description='User confirmed.')
    @account_api.response(
        code=404,
        description=
        'An unconfirmed user with the given confirmation code does not exist.')
    def post(self):
        """ Confirm a user's registration and provide an access token. """
        data = request.get_json()
        username, password = actions.get_user(data['confirmation_code'])
        actions.confirm_user(username)
        return "", 200
        pass
Exemple #25
0
class UpdateEmail(Resource):
    @account_api.expect(create_model(
        'New Email', {
            'email': fields.String(description='The new email.'),
        }),
                        validate=True)
    @account_api.response(code=200, description='Email updated.')
    @account_api.response(code=404, description='Email already exists.')
    @user_api.response(code=401, description='Unauthorized access.')
    @account_api.doc(security='KwikkerKey')
    @authorize
    def put(self, authorized_username):
        """ Updates the user's email."""
        data = request.get_json()
        is_updated = actions.update_user_email(authorized_username,
                                               data['email'])
        if is_updated:
            return "", 200
        else:
            abort(404, message='Email already exists.')
        pass
Exemple #26
0
class Trend:
    api_model = create_model(
        'Trend', {
            'id':
            fields.String(description='The id of the trend.'),
            'text':
            fields.String(description='The text of the trend.'),
            'number_of_kweeks':
            fields.Integer(description='The number of kweeks in the trend.')
        })

    def __init__(self, json):
        self.id = json['id']
        self.text = json['text']
        self.number_of_kweeks = json['number_of_kweeks']

    def to_json(self):
        return {
            'id': self.id,
            'text': self.text,
            'number_of_kweeks': self.number_of_kweeks
        }
Exemple #27
0
class DirectMessage:
    api_model = create_model(
        'Direct Message',
        {
            'id':
            fields.String(
                description='A unique string representing the message.'),
            'from_username':
            fields.String(description='username who sent the message.'),
            'to_username':
            fields.String(
                description='username who wants to receive that message.'),
            'created_at':
            fields.String(
                description='The utc datetime of the message when created.'),
            'text':
            fields.String(description='The content of the message.'),
            'media_url':
            fields.String(description='Nullable. The url of the media.',
                          nullable=True)  # Nullable
        })

    def __init__(self, json):
        self.id = json['id']
        self.from_username = json['from_username']
        self.to_username = json['to_username']
        self.created_at = json['created_at']
        self.text = json['text']
        self.media_url = json['media_url']

    def to_json(self):
        return {
            'id': self.id,
            'from_username': self.from_username,
            'to_username': self.to_username,
            'created_at': self.created_at,
            'text': self.text,
            'media_url': self.media_url
        }
Exemple #28
0
class Block(Resource):
    @interactions_api.response(
        code=200,
        description='Blocked users returned successfully.',
        model=[User.api_model])
    def get(self):
        """ Retrieve a list of blocked users. """

    @interactions_api.response(code=201,
                               description='User blocked successfully.')
    @interactions_api.response(code=404, description='User does not exist.')
    @interactions_api.response(code=400,
                               description='Parameters type does not match.')
    @interactions_api.response(code=401, description='Unauthorized access.')
    @interactions_api.expect(
        create_model(
            'Username',
            model={
                'username':
                fields.String(
                    description="The username of the user to be blocked.")
            }))
    def post(self):
        """ Block a certain user using his username. """
        pass

    @interactions_api.response(code=204,
                               description='User unblocked successfully.')
    @interactions_api.response(code=404, description='User does not exist.')
    @interactions_api.response(code=400,
                               description='Parameters type does not match.')
    @interactions_api.response(code=401, description='Unauthorized access.')
    @interactions_api.param(
        name='username',
        type='str',
        required=True,
        description='The username of the user to be unblocked.')
    def delete(self):
        """ Unblock a certain user using his username. """
Exemple #29
0
class ReplyInfo:
    api_model = create_model(
        'Reply Info', {
            'reply_to_username':
            fields.String(
                description=
                'The username of the user who this kweek is a reply to.'),
            'reply_to_kweek_id':
            fields.String(
                description=
                'The kweek id of the kweek which this kweek is a reply to.')
        })

    def __init__(self, json):
        self.reply_to_username = json['reply_to_username']
        self.reply_to_kweek_id = json['reply_to_kweek_id']

    def to_json(self):
        return {
            'reply_to_username': self.reply_to_username,
            'reply_to_kweek_id': self.reply_to_kweek_id
        }
Exemple #30
0
class UserProfile:
    api_model = create_model(
        'User Profile', {
            'username':
            fields.String(description='The user name.'),
            'screen_name':
            fields.String(description='The name shown on profile screen.'),
            'bio':
            fields.String(description='The biography of the user'),
            'birth_date':
            fields.Date(description='The birth date of the user'),
            'created_at':
            fields.DateTime(description='Time created at'),
            'followers_count':
            fields.Integer(
                description='Integer indicates number of people follow you.'),
            'following_count':
            fields.Integer(
                description='Integer indicates number of people you follow.'),
            'kweeks_count':
            fields.Integer(
                description=
                'Integer indicates number of tweets which called kweeks.'),
            'likes_count':
            fields.Integer(description='Integer indicates number of likes.'),
            'profile_banner_url':
            fields.String(
                description='Url for profile banner which is cover photo.'),
            'profile_image_url':
            fields.String(description='Url for profile image.'),
            'following':
            fields.Boolean(
                description=
                'Nullable. Does the authorized user follow this user? '
                'Null if the authorized user is the same as the user in the query.'
            ),
            'follows_you':
            fields.Boolean(
                description=
                'Nullable. Does this user follow the authorized user? '
                'Null if the authorized user is the same as the user in the query.'
            ),
            'blocked':
            fields.Boolean(
                description=
                'Nullable. Is this user blocked by the authorized user? '
                'Null if the authorized user is the same as the user in the query.'
            ),
            'muted':
            fields.Boolean(
                description=
                'Nullable. Is this user muted by the authorized user? '
                'Null if the authorized user is the same as the user in the query.'
            )
        })

    def __init__(self, json):
        self.username = json["username"]
        self.screen_name = json["screen_name"]
        self.bio = json["bio"]
        self.birth_date = json["birth_date"]
        self.created_at = json["created_at"]
        self.followers_count = json["followers_count"]
        self.following_count = json["following_count"]
        self.kweeks_count = json["kweeks_count"]
        self.likes_count = json["likes_count"]
        self.profile_banner_url = json["profile_banner_url"]
        self.profile_image_url = json["profile_image_url"]
        self.following = json["following"]
        self.follows_you = json["follows_you"]
        self.blocked = json["blocked"]
        self.muted = json["muted"]

    def to_json(self):
        return {
            'username': self.username,
            'screen_name': self.screen_name,
            'bio': self.bio,
            'birth_date': self.birth_date,
            'created_at': self.created_at,
            'followers_count': self.followers_count,
            'following_count': self.following_count,
            'kweeks_count': self.kweeks_count,
            'likes_count': self.likes_count,
            'profile_banner_url': self.profile_banner_url,
            'profile_image_url': self.profile_image_url,
            'following': self.following,
            'follows_you': self.follows_you,
            'blocked': self.blocked,
            'muted': self.muted
        }