-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
30 lines (22 loc) · 837 Bytes
/
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
''' auth.py
auth stuff for books. we use the same (literally) auth as for t2. '''
import hashlib, os, base64, functools
from . import app, db_auth as db
class Users(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
email = db.Column(db.String)
password_digest = db.Column(db.String)
remember_token = db.Column(db.String)
admin = db.Column(db.Boolean, default=False)
created_at = db.Column(db.DateTime)
updated_at = db.Column(db.DateTime)
def auth(user, password):
return True
def encrypt(token):
return hashlib.sha1(token).hexdigest()
def new_remember_token():
return base64.b64encode(os.urandom(16))
def current_user(token):
# look up hashed remember token in the (ruby) db
return Users.query.filter_by(remember_token=encrypt(token)).first()