예제 #1
0
def get_comparison_by_id(comparisonid):
    if comparisonid == 'undefined':
        abort(404, 'comparisonid of {} was not found'.format(comparisonid))

    _id = ObjectId(str(comparisonid))
    comparison = con.comparisons.find_one({'_id': _id})

    if comparison is None:
        abort(404, 'the specified comparison id {} was not found'.format(comparisonid))

    public = False
    if 'view_type' in comparison:
        public = True if comparison['view_type'] == 'public' else False

    if not public:
        verify_jwt()

    # if this isn't a public comparisons, then this athlete must be the originator
    if not public and current_user.athlete_id != comparison['athlete_id'] and not is_role('admin'):
        abort(404, 'the specified comparison id {} was not found'.format(comparisonid))

    comparison['athlete'] = get_athlete_dict(comparison['athlete_id'])
    comparison['compare_to_athlete'] = get_athlete_dict(comparison['compare_to_athlete_id'])
    comparison['id'] = str(comparison['_id'])
    comparison.pop('_id')
    comparison['url'] = request.path

    if 'state' not in comparison:
        comparison['state'] = 'Unknown'

    return Response(dumps(comparison),
        mimetype='application/json',
        headers={
           'cache-control': 'max-age=300' if comparison['state'] == 'Completed' else 'no-cache'
        })
예제 #2
0
def authorize():
  try:
    verify_jwt()
  except:
    return False
  if not current_user.can(READ, 'ApiDocs'):
    return False
  return True
예제 #3
0
def authorize():
    try:
        verify_jwt()
    except:
        return False
    if not current_user.can(READ, 'ApiDocs'):
        return False
    return True
예제 #4
0
 def progress(self):
     try:
         verify_jwt()
     except:
         pass
     if not current_user:
         return None
     return self.user_progress(current_user.user)
예제 #5
0
 def is_validated(self):
     try:
         verify_jwt()
     except:
         pass
     if not current_user:
         return None
     return self.is_validated_by_user(current_user.user)
예제 #6
0
 def test_is_unlocked(self):
     try:
         verify_jwt()
     except:
         pass
     if not current_user:
         return None
     return self.test_is_unlocked_by_user(current_user.user)
예제 #7
0
def get_track(track_id):
    """Get the Track_ with id ``track_id`` enveloped in a single-key JSON dictionary."""
    track = tracks.get_or_404(is_published__ne=False,id=track_id)

    try:
        verify_jwt()
    except:
        pass

    return track
예제 #8
0
def get_skill(skill_id):
    """Get the Skill_ with id ``skill_id`` enveloped in a single-key JSON dictionary."""

    skill = skills.get_or_404(is_published__ne=False,id=skill_id)

    try:
        verify_jwt()
    except:
        pass

    return skill
예제 #9
0
def load_user(*args, **kwargs):
    """
    Tries to verify jwt and load user, @jwt.required is a separate check.
    :param args:
    :param kwargs:
    :return: None
    """
    if is_anonymous():
        try:
            verify_jwt()
        except JWTError:
            pass
예제 #10
0
    def decorated_function(*args, **kwargs):
        # check if authorization header is set
        auth = request.headers.get('Authorization', None)

        # if it is, verify jwt
        if auth:
            verify_jwt()
            g.current_user_id = current_user.id

        # if not, use the default user
        else:
            user = session.query(User).filter_by(username="******").first()
            if user:
                g.current_user_id = user.id
            else:
                return jsonify(response="No default user defined!"), 401

        return func(*args, **kwargs)
예제 #11
0
def get_activities_by_comparison(comparison_id):
    if comparison_id == 'undefined':
        abort(404, 'comparisonid of {} was not found'.format(comparison_id))

    _id = ObjectId(str(comparison_id))
    comparison = con.comparisons.find_one({'_id': _id}, {'activity_ids': 1, 'athlete_id': 1, 'view_type': 1})

    if comparison is None:
        abort(404, 'the specified comparison id {} was not found'.format(comparison_id))

    public = False
    if 'view_type' in comparison:
        public = True if comparison['view_type'] == 'public' else False

    if not public:
        verify_jwt()

    # if this isn't a public comparisons, then this athlete must be the originator
    if not public and current_user.athlete_id != comparison['athlete_id'] and not is_role('admin'):
        abort(404, 'the specified comparison id {} was not found'.format(comparison_id))

    if 'activity_ids' not in comparison:
        abort(404, 'activities have not been identified yet')

    results = []
    sd = get_stravadao()
    for activity_id in comparison['activity_ids']:
        a = sd.get_activity(activity_id)

        if a is not None:
            results.append({
                'id': a.id,
                'name': a.name,
                'start_date_local': str(a.start_date_local),
                'distance': int(a.distance)
            })

    results.sort(key=lambda x: x['start_date_local'], reverse=True)

    return Response(dumps(results),
        mimetype='application/json',
        headers={
            'cache-control': 'max-age=120'
        })
예제 #12
0
def record_misc_analytic():
    """ Creates a new MiscActivity object which is used to track analytics on the platform
    :param misc_type: the type of the analytic
    """

    data = request.get_json()
    obj = misc_activities.new(**data)
    try:
        verify_jwt()
    except:
        pass
    else:
        obj.credentials = current_user._get_current_object()

    try:
        obj.save()
    except Exception as e:
        return jsonify(error=e.message), 400
    else:
        return obj, 201
예제 #13
0
 def decorator(*args, **kwargs):
     verify_jwt(realm)
     return fn(*args, **kwargs)
예제 #14
0
 def decorator(*args, **kwargs):
     try:
         verify_jwt(realm)
     except JWTError:
         pass
     return fn(*args, **kwargs)
예제 #15
0
 def decorator(*args, **kwargs):
     try:
         verify_jwt(realm)
     except JWTError:
         pass
     return fn(*args, **kwargs)
예제 #16
0
    def decorated_function(*args, **kwargs):
        verify_jwt()
        g.user = session.query(User).get(current_user.id)

        return func(*args, **kwargs)
예제 #17
0
    def decorated_function(*args, **kwargs):
        verify_jwt()
        g.user = session.query(User).get(current_user.id)

        return func(*args, **kwargs)