Example #1
0
    def get(self, teacher_username):
        teacher = Teacher.get_by_teacher_username(
            teacher_username=teacher_username)

        if teacher is None:
            return {'message': 'teacher does not exist'}, HTTPStatus.NOT_FOUND

        current_teacher = get_jwt_identity()

        if current_teacher == teacher.teacher_id:
            data = teacher_schema.dump(teacher).data

        else:
            data = teacher_public_schema.dump(teacher).data

        return data, HTTPStatus.OK
Example #2
0
    def post(self):
        json_data = request.get_json()

        data, errors = teacher_schema.load(data=json_data)

        if errors:
            return {
                'message': 'Validation Errors',
                'errors': errors
            }, HTTPStatus.BAD_REQUEST

        if Teacher.get_by_teacher_username(data.get('teacher_username')):
            return {
                'message': 'Teacher already exists'
            }, HTTPStatus.BAD_REQUEST

        teacher = Teacher(**data)

        teacher.save()

        return teacher_schema.dump(teacher).data, HTTPStatus.CREATED
Example #3
0
    def post(self):
        json_data = request.get_json()
        teacher_username = json_data.get('teacher_username')
        teacher_password = json_data.get('teacher_password')

        teacher = Teacher.get_by_teacher_username(
            teacher_username=teacher_username)

        if not teacher or not check_password(teacher_password,
                                             teacher.teacher_password):
            return {
                'message': 'username or password is incorrect'
            }, HTTPStatus.UNAUTHORIZED

        teacher_access_token = create_access_token(identity=teacher.teacher_id,
                                                   fresh=True)
        teacher_refresh_token = create_refresh_token(
            identity=teacher.teacher_id)
        return {
            'teacher_access_token': teacher_access_token,
            'teacher_refresh_token': teacher_refresh_token
        }, HTTPStatus.OK