Exemple #1
0
 def get(self):
     # get the post data
     post_data = request.json
     data, status = Auth.check_user_credentials(data=post_data)
     if (status == 200):
         return "test succesufle"
     return "test faiilud"
 def post(self):
     """
     Receive Authorization token given user credentials
     Limited to 10 requests per 1 minute.
     """
     post_data = request.json
     return Auth.login_user(data=post_data)
Exemple #3
0
def registerUserRoomID(request_object):
    print(request_object)
    user, remain_sec = Auth.socket_logged_in_user(request_object)
    room_public_id = request_object.get('room_public_id')
    room = get_a_room(room_public_id)

    response_object = {
        'status': 'fail',
        'message': 'Fail to authenticate'
    }

    if room is None:
        response_object = {
            'status': 'fail',
            'message': 'Room not found'
        }
    else:
        if user is not None:
            # save pair of session id with user id
            result = save_user_id_room_id_with_sid(session_id=request.sid, user_id=user.id, room_id=room.id, remain_sec=remain_sec)

            if result == True:
                # join private room with specific name room is user with public id
                join_room(room=user.public_id, namespace='/')
                join_room(room=room_public_id, namespace='/rooms')
                # Notify user is authenticate successfully
                response_object = {
                    'status': 'success',
                    'message': 'Authenticate successfully'
                }
        
    emit('response_login_with_room', response_object, broadcast=False, namespace='/rooms')
def update_user(data, request):
    user, status, error = Auth.get_logged_in_user(request)

    if not user:
        response_object = {'status': 'error', 'message': error}
        return response_object, status

    try:
        fields = validate_update(model=user, data=data)

        # assign fields with extra validation for some attributes
        for field, value in fields.items():
            if field == 'email':
                User.validate_email(user, key='email', email=data['email'])
            setattr(user, field, data[field])

        save_changes()
    except AssertionError as error:
        response_object = {'status': 'error', 'message': str(error)}
        return response_object, 400

    response_object = {
        'status': 'success',
        'message': 'User updated.',
    }
    return response_object, 200
 def get(self):
     response, status = Auth.get_logged_in_user(request)
     if status == 200:
         response_object = {'id': response.get('data').id}
         return response_object
     else:
         api.abort(404, 'User not found')
Exemple #6
0
 def get(self, getpage):
     """read csv file in container folder"""
     response = Auth.get_logged_in_user(new_request=request)
     user_profile = response[0].get('data')
     id_user = user_profile.get('user_id')
     int_page = int(getpage)
     return read_data_csv(id_user,int_page)
def add_remove_like(post_id):
    post = get_a_post(post_id)
    user_id = Auth.get_logged_in_user(request)[0]['data']['user_id']

    if post.author == user_id:
        response_object = create_response(
            'fail', 'You Cant Like Your Own Post')
        return response_object

    like = Like.query.filter_by(post_id=post.id, user_id=user_id).first()

    if not like:
        like = Like(post_id=post.id, user_id=user_id)
        db.session.add(like)
    else:
        db.session.delete(like)
    db.session.commit()

    if not like:
        response_object = create_response(
            'fail', 'Somthing Whent Rong When we Trying To Add Your Support For This Post')
    else:
        response_object = create_response('success', 'Every Thing Done')

    return response_object
Exemple #8
0
def save_thumbnail(args):

    user_id = Auth.get_logged_in_user(request)[0]['data']['user_id']
    check_user = User.query.filter_by(id=user_id).first()
    if not check_user:
        response_object = create_response('fail', 'please login first')
        return response_object

    img = args['thumbnail']
    img_type = img.mimetype

    img_name = ''

    if img_type == 'image/jpeg':
        img_name = thumbnail_resize(img)

    if img_name:
        old_image = check_user.thumbnail
        check_user.thumbnail = img_name
        db.session.commit()
        if old_image:
            full_old_path = f"{thumbnail_loc}\\{old_image}"
            if os.path.isfile(full_old_path):
                os.remove(full_old_path)
        response_object = create_response('success', 'your thumbnail updated')
        return response_object

    response_object = create_response(
        'fail', 'please make shoure ur image type is jpg/jpeg')
    return response_object
Exemple #9
0
    def get(self):
        """ response info file csv was selected"""
        response = Auth.get_logged_in_user(new_request=request)
        user_profile = response[0].get('data')
        id_user = user_profile.get('user_id')

        return jsonify(info_data_csv(id_user))
def create_post(data):
    # check if author token exists
    user = Auth.get_logged_in_user(request)
    if (not valid.validate_length(data['title'], 10) or
            not valid.validate_length(data['body'], 30)):
        response_object = create_response('fail', 'The Minimum Length For Title 10 And body 30')
        return response_object

    post = Post.query.filter_by(title=data['title']).first()
    if not post:
        new_post = Post(
            title=data['title'],
            body=data['body'],
            author=user[0]['data']['user_id'])

        db.session.add(new_post)
        db.session.commit()

        if data['category']:
            for cat in data['category']:
                n_cat = add_category(cat)
                n_cat.categories.append(new_post)

            db.session.commit()
        response_object = create_response('success', 'your post created.')
        return response_object, 200
    else:
        response_object = create_response(
            'fail', 'post already exists. Please Choose Unique Title.')

    return response_object, 400
    def decorated(*args, **kwargs):
        data = request.args
        proprietary = js2python_bool(request.args.get('proprietary', False))

        if proprietary:
            ret, status = Auth.get_logged_in_user(
                request.headers.get('X-Token'))
            if status != 200:
                return ret, status
            kwargs['user'] = ret['data']
            user = User.objects(pk=user['user_id']).first()
            organization = None
            team = None

            org_id = data.get('organization', None)
            team_id = data.get('team', None)
            if team_id and team_id != 'undefined' and team_id != 'null':
                team = Team.objects(pk=team_id).first()
                if not team:
                    return response_message(ENOENT, 'Team not found'), 404
                if team not in user.teams:
                    return response_message(EINVAL,
                                            'Your are not a team member'), 400
            if org_id and org_id != 'undefined' and org_id != 'null':
                organization = Organization.objects(pk=org_id).first()
                if not organization:
                    return response_message(ENOENT,
                                            'Organization not found'), 404
                if organization not in user.organizations:
                    return response_message(
                        EINVAL, 'You are not an organization member'), 400
            kwargs['team'] = team
            kwargs['organization'] = organization

        return f(*args, **kwargs)
Exemple #12
0
    def get(self):
        response = Auth.get_logged_in_user(new_request=request)
        user_profile = response[0].get('data')
        id_user = user_profile.get('user_id')

        data_file_name = str(get_a_data(id_user))

        col_uid = request.args.get('uid', type=str)
        col_iid = request.args.get('iid', type=str)
        col_rati = request.args.get('rati', type=str)
        uid_value = request.args.get('value_uid', type=float)
        iid_value = request.args.get('value_iid', type=float)
        Algorthm = Predit()
        result = {}
        arr = []
        obj1 = {}
        obj1['data'] = Algorthm.chart_of_value(data_file_name, col_uid,
                                               col_iid, col_rati, uid_value)
        obj1['name'] = 'Values appear the same value ' + str(uid_value)
        arr.append(obj1)
        obj2 = {}
        obj2['data'] = Algorthm.chart_of_value(data_file_name, col_iid,
                                               col_uid, col_rati, iid_value)
        obj2['name'] = 'Values appear the same value ' + str(iid_value)
        arr.append(obj2)
        result['result'] = arr
        return result
 def decorated(*args, **kwargs):
     data, status = Auth.get_logged_in(request)
     # response object and status code returned
     token = data.get('data')
     if not token:
         return data, status
     return f(*args, **kwargs)
Exemple #14
0
    def get(self):
        #count time request
        g.request_start_time = time.time()
        response = Auth.get_logged_in_user(new_request=request)
        user_profile = response[0].get('data')
        id_user = user_profile.get('user_id')

        data_file_name = str(get_a_data(id_user))

        col_uid = request.args.get('uid', type=str)
        col_iid = request.args.get('iid', type=str)
        col_rati = request.args.get('rati', type=str)
        from_uid = request.args.get('from_uid', type=int)
        to_uid = request.args.get('to_uid', type=int)
        from_iid = request.args.get('from_iid', type=int)
        to_iid = request.args.get('to_iid', type=int)

        Algorthm = Predit()
        result = {}
        result['result'] = Algorthm.from_to(data_file_name, col_uid, col_iid,
                                            col_rati, from_uid, to_uid,
                                            from_iid, to_iid)
        g.request_time = lambda: "%.5fs" % (time.time() - g.request_start_time)
        result['time'] = g.request_time()
        return result
Exemple #15
0
def save_new_task(data):
    response, status = Auth.get_logged_in_user(request)
    if response['status'] != 'success':
        api.abort(401)
    user_id = response['data']['user_id']
    expires_on = None
    if 'expires_on' in data:
        expires_on = parser.parse(data['expires_on'])
    for required_value in ('description', 'name'):
        if required_value not in data:
            api.abort(400)
    public_task_id = str(uuid.uuid4())
    new_task = Task(
        public_task_id=public_task_id,
        name=data['name'],
        description=data['description'],
        user_id=user_id,
        expires_on=expires_on,
    )
    save_changes(new_task)
    response_object = {
        'status': 'success',
        'message': 'Successfully created.',
        'public_task_id': public_task_id
    }
    return response_object, 201
Exemple #16
0
    def decorated(*args, **kwrags):
        data, status = Auth.get_logged_in_user(request)
        token = data.get('data')

        if not token:
            return data, status
        return f(*args, **kwrags)
Exemple #17
0
    def decorated(*args, **kwargs):

        data, status = Auth.check_user_credentials(request.json)
        if status != 200:
            return data

        return f(*args, **kwargs)
    def decorated(*args, **kwargs):

        ret, status = Auth.get_logged_in_user(request.headers.get('X-Token'))
        if status != 200:
            return ret, status
        kwargs['user'] = ret['data']

        return f(*args, **kwargs)
Exemple #19
0
 def post(self):
     LOG.info('=================---------------------- logging in..')
     post_data = request.json
     result = Auth.login_user(api, data=post_data)
     if isinstance(result, dict):
         return result
     else:
         api.abort(401, result)
Exemple #20
0
    def decorated(*args, **kwargs):
        resp = Auth.get_logged_in_user(request)
        data = resp.json
        token = data.get('data')
        if not token:
            return resp

        return f(*args, **kwargs)
Exemple #21
0
    def post(self):
        """change password"""
        response = Auth.get_logged_in_user(new_request=request)
        user_profile = response[0].get('data')
        id_user = user_profile.get('user_id')

        new_pass = request.form['new_pass']
        return changes_password(id_user, new_pass)
Exemple #22
0
    def decorate(*args, **kwargs):
        data, status = Auth.get_logged_in_user(request)
        token = data.get("data")

        if not token:
            return data, status

        return func(*args, **kwargs)
 def get(self):
     """List all registered users"""
     # get auth token
     #auth_header = request.headers.get('Authorization')
     rsp = Auth.get_logged_in_user(request)
     if (rsp[1] != 200):
         return rsp
     return get_all_users()
Exemple #24
0
    def decorated(*args, **kwargs):
        data, status = Auth.get_logged_in_user(request)
        user = data.get('data')

        if not user:
            return data, status

        return f(*args, **kwargs)
    def decorated(*args, **kwargs):

        user, status, error = Auth.get_logged_in_user(request)

        if not user:
            response_object = {'status': 'error', 'message': error}
            return response_object, status

        return f(*args, **kwargs)
    def decorated(*args, **kwargs):
        auth_token = request.headers.get('Authorization')
        data, status = Auth.get_logged_in_user(auth_token)
        token = data.get('data')

        if not token:
            return data, status

        return f(*args, **kwargs)
Exemple #27
0
    def decorated(*args, **kwargs):
        data, status = Auth.get_logged_in_user(request)
        token = data.get('data')

        if not token:
            return data, status

        kwargs['user_id'] = token['user_id']
        return f(*args, **kwargs)
Exemple #28
0
    def post(self):
        response = Auth.get_logged_in_user(new_request=request)
        user_profile = response[0].get('data')
        id_user = user_profile.get('user_id')

        res = request.json

        result = describe_col_select_cout_value_csv(id_user, res)
        return result
Exemple #29
0
    def decorated(*args, **kwargs):

        data, status = Auth.check_login(request)
        token = data.get('data')

        if not token:
            return data, status

        return f(*args, **kwargs)
Exemple #30
0
    def post(self):
        # get auth token
        LOG.info('=================---------------------- logging out..')
        auth_header = request.headers.get('Authorization')

        if not auth_header:
            api.abort(403, 'Provide a valid auth token.')

        return Auth.logout_user(api, auth_header)