-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.py
41 lines (30 loc) · 920 Bytes
/
services.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
40
41
from authlib.jose import jwt
from authlib.jose import errors as jerr
from time import time
KEY="tokenizer"
class services():
def __init__(self,conn):
self.conn=conn
def createToken(self,data):
header={'alg': 'HS256'}
payload={'iss':'BLCKWD', 'sub':data, 'iat': int(time()), 'exp':int(time())+14*86400}
return jwt.encode(header,payload,KEY)
def isAuth(self,token):
try:
claim=jwt.decode(token,KEY)
claim.validate()
return claim
except jerr.BadSignatureError:
return False
except jerr.ExpiredTokenError:
return False
def canView(self, claim):
userId=claim.sub
permissions=self.conn.getPermissionsUser(userId)
if permissions[0]:
return True
return False
def canWrite(self):
pass
def canCreate(self):
pass