-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.py
50 lines (39 loc) · 1.22 KB
/
users.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
#!/usr/bin/env python
import hashlib
import pickle
from flask_login import UserMixin
USER_FILE = '/tmp/users.pkl'
SHADOW_FILE = '/tmp/shadows.pkl'
class User(UserMixin):
def __init__(self, username):
self.username = username
def get_id(self):
return self.username
def __repr__(self):
return self.username
@classmethod
def initialize(cls):
try:
with open(USER_FILE, 'r') as pickle_file:
cls._users = pickle.load(pickle_file)
except:
cls._users = {}
try:
with open(SHADOW_FILE, 'r') as pickle_file:
cls._shadows = pickle.load(pickle_file)
except:
cls._shadows = {}
@classmethod
def update_databases(cls):
with open(USER_FILE, 'w') as pickle_file:
pickle.dump(cls._users, pickle_file)
with open(SHADOW_FILE, 'w') as pickle_file:
pickle.dump(cls._shadows, pickle_file)
@classmethod
def get(cls, userid, default):
return cls._users.get(userid, default)
@classmethod
def authenticate(cls, username, password):
# don't care; CAS authenticated us
cls._users[username] = cls(username)
return True