-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
76 lines (66 loc) · 1.81 KB
/
auth.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from lib2to3.pgen2.token import tok_name
from operator import ge
from re import S
from flask import render_template, request, redirect, url_for, Flask, session
from get_dynamodb import get_dynamodb
from post_to_account_dynamodb import post_account_details
from login import check_account_credentials
from create_event import post_event_details, check_event_details
import secrets
from datetime import datetime, timedelta
'''
session_token: {
"generated_timestamp"
"valid_until"
"username"
}
'''
active_sessions = {}
"""
"""
def get_session_token(request):
try:
token = request.cookies.get('session-token')
except Exception:
return None
if check_token(token) == False:
return None
return token
"""
"""
def generate_token(user):
now = datetime.now()
token_id = secrets.token_urlsafe(64)
valid_until = now + timedelta(days=7)
new_token = {
"generated_timestamp":now,
"valid_until":valid_until,
"username":user
}
active_sessions[token_id] = new_token
return token_id, valid_until
"""
"""
def check_token(session_token):
if session_token in active_sessions:
now = datetime.now()
session = active_sessions[session_token]
if now > session["generated_timestamp"] and session["valid_until"] > now:
return True
else:
del active_sessions[session_token]
return False;
return False
"""
"""
def remove_token(session_token):
if check_token(session_token) == False:
return None
del active_sessions[session_token]
return True
"""
"""
def session_token_to_user(session_token):
if check_token(session_token) == False:
return None
return active_sessions[session_token]["username"]