-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (33 loc) · 1.17 KB
/
app.py
File metadata and controls
45 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from datetime import timedelta
from environs import Env
from flask import Flask
from flask_jwt_extended import JWTManager
from flask_restful import Api
from common.methods import encrypt_json_with_common_cipher
from todo.views import TodoTasks
from user.views import UserSignUp, UserLogin, DecryptData
env = Env()
env.read_env()
app = Flask(__name__)
api = Api(app)
app.config["JWT_SECRET_KEY"] = env("JWT_SECRET_KEY")
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = timedelta(
hours=int(env("JWT_ACCESS_TOKEN_EXPIRES"))
)
jwt = JWTManager(app)
@app.after_request
def after_request(response):
data = response.get_json()
if not data.get('decrypted_data') and response.status_code == 200:
response.data = encrypt_json_with_common_cipher(response.get_json())
return response
@app.errorhandler(422)
def handle_unprocessable_entity(err):
messages = err.exc.messages if err.exc else ["Invalid request"]
return {"status": "error", "result": messages}, 422
api.add_resource(TodoTasks, "/todo")
api.add_resource(UserSignUp, "/signup")
api.add_resource(UserLogin, "/login")
api.add_resource(DecryptData, "/decrypt_data")
if __name__ == "__main__":
app.run(debug=True)