-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
32 lines (30 loc) · 1.07 KB
/
functions.py
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
import tornado
#####getting the username of the logged in user (sub function)###
##def get_current_username():
## if response.get_secure_cookie('tag_it') is not None:
## return response.get_secure_cookie('tag_it').decode("utf-8")
## else:
## return None
##
#####boolean value of whether the user is logged in or not (sub function) ###
##def is_logged_in():
## if response.get_cookie('tag_it') is None:
## return False
## else:
## return True
###Main function, creates context dictionary with compulsory values only ###
def make_context(response):
context = {}
#making user context
if response.get_cookie('tag_it'):
context['is_logged_in'] = True
try:
context['username'] = response.get_secure_cookie('tag_it').decode("utf-8")
import db
context["current_user"] = db.User.find(context['username'])
except:
response.clear_cookie('tag_it')
response.redirect('/')
else:
context['is_logged_in'] = False
return context