-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrequest_mod.py
More file actions
39 lines (29 loc) · 812 Bytes
/
Copy pathrequest_mod.py
File metadata and controls
39 lines (29 loc) · 812 Bytes
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
# encoding=utf-8
import json
from pony import orm
from TodoApp.Models.User import User
__author__ = "Quazi Nafiul Islam"
from flask import request, g
def before_request():
"""
Checks if there is a token before letting client access any path
other than `/user/`
"""
path = request.path
if path != '/user/':
try:
with orm.db_session:
token = json.loads(request.data)['token']
user = User.verify_auth_token(token)['id']
if user:
g.user = user
else:
g.user = None
except (orm.ObjectNotFound, TypeError, KeyError):
pass
def after_request(response):
try:
g.user = None
except AttributeError:
pass
return response