Пример #1
0
    def post(cls):
        """
        Gets data from parser to find user in database and checks password.
        Checks and returns access token.
        """
        try:
            user_json = request.get_json()
            user_data = user_schema.load(user_json,
                                         partial=("name", "company_name",
                                                  "email"))

            user = UserModel.find_by_username(user_data.username)

            if not user:
                return {"message": gettext("user_not_found")}, 404

            if check_encrypted_password(user_data.password, user.password):
                access_token = create_access_token(identity=user.id,
                                                   fresh=True)
                return {"access_token": access_token}, 200

            return {"message": gettext("user_invalid_credentials")}, 401

        except:
            return {"message": gettext("user_error_logging_in")}, 500
Пример #2
0
 def post(cls):
     try:
         jwt_id = get_raw_jwt()["jti"]
         user_id = get_jwt_identity()
         BLACKLIST.add(jwt_id)
         return {"message": gettext("user_logged_out")}, 200
     except:
         return {"message": gettext("user_error_logging_out")}, 500
Пример #3
0
 def delete(cls, user_id):
     try:
         user = UserModel.find_by_id(user_id)
         if user:
             user.delete_from_db()
             return {"message": gettext("user_deleted")}, 200
         return {"message": gettext("user_not_found")}, 404
     except:
         return {"message": gettext("user_error_deleting")}, 500
Пример #4
0
    def get(cls, user_id):

        try:
            user = UserModel.find_by_id(user_id)
            if user:
                return user_schema.dump(user), 200
            return {"message": gettext("user_not_found")}, 404
        except:
            return {"message": gettext("user_error_reading.")}, 500
    def delete(cls, file_id):
        """
        Delete a a watermarked pdf file by its ID.
        """
        try:
            file = PdfWatermarkModel.find_by_id(file_id)
            if file:
                file.delete_from_db()
                return {"message": gettext("file_deleted")}, 200
            return {"message": gettext("file_not_found")}, 404

        except Exception as err:
            raise err
Пример #6
0
    def post(cls):

        try:
            user = user_schema.load(request.get_json())

            if UserModel.find_by_username(user.username):
                return {"message": gettext("user_username_exists")}, 400

            user.password = encrypt_password(user.password)
            user.save_to_db()
            return {"message": gettext("user_registered")}, 201

        except:
            return {"message": gettext("user_error_creating")}, 500
Пример #7
0
    def post(self, person_id):
        if UserModel.find_by_person_id(person_id):
            return {
                "message":
                gettext("person_id_already_exists").format(person_id)
            }, 400

        user = UserModel(person_id=person_id)
        try:
            user.save_to_db()
        except:
            return {"message": gettext("person_id_error_inserting")}, 500

        return user_schema.dump(user), 201
Пример #8
0
    def put(cls, user_id):

        try:
            user_json = request.get_json()
            user = UserModel.find_by_id(user_id)

            if user:
                user.name = user_json["name"]
            else:
                return {"message": gettext("user_not_found")}, 404

            user.save_to_db()

            return user_schema.dump(user), 200

        except:
            return {"message": gettext("user_error_updating.")}, 500
Пример #9
0
    def post(self, survey_id):
        if SurveyModel.find_by_survey_id(survey_id):
            return {
                "message": gettext("survey_already_exists").format(survey_id)
            }, 400

        survey_json = request.get_json()
        survey_json["survey_id"] = survey_id
        for item in survey_json["questions"]:
            item["question_id"] = item["question"]["name"]
            item["question"] = item["question"]
            item["page_title"] = item["page_title"]
        survey = survey_schema.load(survey_json)
        try:
            survey.save_to_db()
        except:
            return {"message": gettext("survey_error_inserting")}, 500

        return survey_schema.dump(survey), 201
    def post(cls):
        """
        Upload, watermark store a pdf file in database.
        """
        try:
            file = request.files["inputWatermark"]
            mimetype = file.content_type

            if not mimetype == "application/pdf":
                return {
                    "message":
                    "File with the wrong type. Should be application/pdf"
                }

        except Exception as err:
            raise err

        try:
            timestamp = int(time.time())
            output = "{}_{}".format(timestamp, file.filename)
            path = os.path.join(UPLOAD_FOLDER, secure_filename(file.filename))
            file.save(path)

            pdf_watermarker(path, watermark, output)

        except Exception as err:
            raise err

        try:
            new_file = PdfWatermarkModel(name=file.filename,
                                         watermarked_file=file.read())

            if PdfWatermarkModel.find_by_name(new_file.name):
                return {"message": gettext("file_name_exists")}, 400

            new_file.save_to_db()

        except Exception as err:
            raise err

        return {"message": gettext("file_uploaded")}, 201
    def get(cls, file_id):
        """
        Retrieve a watermarked pdf file stored in database by its ID.
        """
        try:
            file = PdfWatermarkModel.find_by_id(file_id)
            if file:
                return file_schema.dump(file), 200
            return {"message": gettext("file_not_found")}, 404

        except Exception as err:
            raise err
Пример #12
0
    def post(self, score_type_id):
        if ScoreTypeModel.find_by_score_type_id(score_type_id):
            return {
                "message":
                gettext("score_type_already_exists").format(score_type_id)
            }, 400

        score_type_json = request.get_json()
        score_type_json["score_type_id"] = score_type_id
        if "survey_id" in score_type_json:
            survey = SurveyModel.find_by_survey_id(
                score_type_json["survey_id"])
            if survey:
                score_type_json["survey_id"] = survey.id
            else:
                return {"message": gettext("survey_not_found")}, 404
        score_type = score_type_schema.load(score_type_json)
        try:
            score_type.save_to_db()
        except:
            return {"message": gettext("score_type_error_inserting")}, 500

        return score_type_schema.dump(score_type), 201
    def put(cls, file_id):
        """
        Update and save a watermarked pdf file name by its ID.
        """
        try:
            file_json = request.get_json()
            file = PdfWatermarkModel.find_by_id(file_id)

            if file:
                file.name = file_json["name"]
            else:
                return {"message": gettext("file_not_found")}, 404

            file.save_to_db()

        except Exception as err:
            raise err

        return file_schema.dump(file), 200
Пример #14
0
 def get(self, score_type_id):
     score_type = ScoreTypeModel.find_by_score_type_id(score_type_id)
     if score_type:
         return score_type_schema.dump(score_type)
     return {"message": gettext("score_type_not_found")}, 404
Пример #15
0
 def get(cls):
     try:
         users = user_list_schema.dump(UserModel.find_all())
         return {"users": users}, 200
     except:
         return {"message": gettext("user_not_found")}
Пример #16
0
 def get(self, survey_id):
     survey = SurveyModel.find_by_survey_id(survey_id)
     if survey:
         return survey_schema.dump(survey)
     return {"message": gettext("survey_not_found")}, 404
Пример #17
0
    def delete(self, score_type_id):
        score_type = ScoreTypeModel.find_by_score_type_id(score_type_id)
        if score_type:
            score_type.delete_from_db()

        return {"message": gettext("score_type_deleted")}, 200
Пример #18
0
 def get(self, person_id):
     user = UserModel.find_by_person_id(person_id)
     if user:
         return user_schema.dump(user)
     return {"message": gettext("person_id_not_found")}, 404
Пример #19
0
    def delete(self, survey_id):
        survey = SurveyModel.find_by_survey_id(survey_id)
        if survey:
            survey.delete_from_db()

        return {"message": gettext("survey_deleted")}, 200
Пример #20
0
    def delete(self, person_id):
        user = UserModel.find_by_person_id(person_id)
        if user:
            user.delete_from_db()

        return {"message": gettext("person_id_deleted")}, 200
Пример #21
0
 def get(self, survey_id):
     survey = SurveyModel.find_by_survey_id(survey_id)
     if survey:
         return survey.surveyjs_json()
     return {"message": gettext("survey_not_found")}, 404