Exemplo n.º 1
0
def save_new_team(data, token):
    try:
        coach_id = decode_auth_token(token)
        coach = Coach.query.filter_by(id=coach_id).first()
        if coach:
            new_team = Team(
                name=data['name'],
                # pass an object here for foreign key
                coach=coach,
                logo=data['logo'],
                public_id=str(uuid.uuid4()),
                invite_code=''.join(random.choices(string.ascii_uppercase + string.digits, k=5)),
                created_at=datetime.datetime.utcnow()
            )
            save_to_db(new_team)
            response_object = {
                'status': 'success',
                'message': 'team successfully created'
            }
            return response_object, 201
        else:
            response_object = {
                'status': 'fail',
                'message': 'invalid owner id, please login as coach'
            }
            return response_object, 401
    except Exception as e:
        return e
Exemplo n.º 2
0
 def get_logged_in_user(new_request):
     auth_token = new_request.headers.get('Authorization')
     role = new_request.headers.get('Role')
     if auth_token:
         resp = decode_auth_token(auth_token)
         if not isinstance(resp, str):
             if role == 'coach':
                 obj = Coach()
             else:
                 obj = Athlete()
             user = obj.query.filter_by(id=resp).first()
             response_object = {
                 'status': 'success',
                 'data': {
                     'user_pid': user.public_id,
                     'email': user.email,
                     'registered_on': str(user.registered_on)
                 }
             }
             return response_object, 200
         else:
             response_object = {'status': 'fail', 'message': resp}
         return response_object, 401
     else:
         response_object = {
             'status': 'fail',
             'message': 'Provide a valid Auth token.'
         }
         return response_object, 401
Exemplo n.º 3
0
 def logout_user(data):
     if data:
         auth_token = data
     else:
         auth_token = ""
     if auth_token:
         resp = decode_auth_token(auth_token)
         if not isinstance(resp, str):
             return save_token(auth_token)
         else:
             response_object = {'status': 'fail', 'message': resp}
             return response_object, 401
     else:
         response_object = {
             'status': 'fail',
             'messsage': 'please provide a valid token.'
         }
         return response_object, 403
Exemplo n.º 4
0
def save_a_memo(data, token):
    try:
        coach_id = decode_auth_token(token)
        team = Team.query.filter_by(public_id=data['team']).first()
        coach = Coach.query.filter_by(id=coach_id).first()
        new_memo = Memo(type=data['type'],
                        duration=data['duration'],
                        date=data['date'],
                        location=data['location'],
                        coach=coach,
                        team=team)
        save_to_db(new_memo)
        response_object = {
            'status': 'success',
            'message': 'memo successfully created'
        }
        return response_object, 201
    except Exception as e:
        return e
Exemplo n.º 5
0
def get_owned_team(token):
    owner_id = decode_auth_token(token)
    return Team.query.filter_by(owner_id=owner_id).all()