-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSessionManager.py
42 lines (31 loc) · 976 Bytes
/
SessionManager.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
33
34
35
36
37
38
39
from flask import session
class SessionManager:
__instance = None
@staticmethod
def getInstance():
""" Static access method. """
if SessionManager.__instance == None:
SessionManager()
return SessionManager.__instance
def __init__(self):
""" Virtually private constructor. """
if SessionManager.__instance != None:
raise Exception("This class is a singleton!")
else:
SessionManager.__instance = self
def issetSession(self):
if session.get('user'):
return True
else:
return False
def setSession(self, data):
if not self.issetSession():
session['user'] = data
def getSession(self):
if self.issetSession():
return session['user']
else:
return None
def destroySession(self):
session.pop('user', None)
SessionManager.__instance = None