def get(self):
     trainer_email = get_jwt_identity()
     print(trainer_email)
     new_trainer = Trainer.find_by_email(trainer_email)
     if not new_trainer:
         return {'err': 'Authentication failed'}, 401
     else:
         return {'data': to_json_trainer(new_trainer)}, 200
 def get(self):
     data = trainer_by_id_parser.parse_args()
     trainer_uuid = data['id']
     new_trainer = Trainer.find_by_uuid(trainer_uuid)
     if not new_trainer:
         return {'msg': f"Trainer with uuid {trainer_uuid} not found"}, 401
     else:
         return {'msg': to_json_trainer(new_trainer)}
 def post(self):
     data = trainer_registration_parser.parse_args()
     # profile_picture = request.files['profile_picture']
     hashed_password = Trainer.hash_password(data['password'])
     trainer_uuid = str(uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org'))
     certifications = data['certifications']
     trainer_certifications = []
     if certifications:
         for certification in certifications:
             attempted_certification = Certification.find_by_name(certification)
             print(attempted_certification)
             if attempted_certification:
                 trainer_certifications.append(attempted_certification)
             else:
                 new_certification = Certification(name=certification, description="", score=0)
                 new_certification.save_to_db()
                 print(new_certification)
                 trainer_certifications.append(new_certification)
     print(trainer_certifications[0].name)
     new_trainer = Trainer(
         email=data['email'],
         password=hashed_password,
         first_name=data['first_name'],
         last_name=data['last_name'],
         trainer_uuid=trainer_uuid,
         certifications=trainer_certifications
     )
     try:
         new_trainer.save_to_db()
         access_token = create_access_token(identity=trainer_uuid)
         refresh_token = create_refresh_token(identity=trainer_uuid)
         return {'msg':
                 f'Trainer with name {new_trainer.first_name} {new_trainer.last_name} created',
                 'access_token': access_token,
                 'refresh_token': refresh_token
                 }
     except Exception as e:
         print(e)  # should be logged
         return {'err': 'Something went wrong'}, 401
    def post(self):
        data = trainer_login_parser.parse_args()
        current_trainer = Trainer.find_by_email(data['email'])
        if not current_trainer:
            return {'msg': f'Trainer {current_trainer} not found'}, 401

        if bcrypt.check_password_hash(current_trainer.password, data['password']):
            access_token = create_access_token(identity=data['email'])
            refresh_token = create_refresh_token(identity=data['email'])
            return {'message':
                    f'Trainer Logged in with email {current_trainer.email}',
                    'access_token': access_token,
                    'refresh_token': refresh_token,
                    'id': current_trainer.trainer_id,
                    'trainer': to_json_trainer(current_trainer)
                    }
        else:
            # create log for wrong credentials
            return {'msg': 'wrong credentials'}, 401
 def put(self):
     trainer_email = get_jwt_identity()
     new_trainer = Trainer.find_by_email(trainer_email)
 def get(self):
     return {'message': Trainer.return_all()}
def is_trainer(id):
    if (Trainer.find_by_uuid(id)):
        return True
    else:
        return False