Skip to content

Commit

Permalink
Add "Alternative Token" handling for flask-login (see #699) (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmith26 authored and lipis committed Aug 9, 2017
1 parent fc6cb78 commit d01874c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions main/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def key(self):
return self.user_db.key.urlsafe()

def get_id(self):
return self.user_db.key.urlsafe()
return unicode(self.user_db.session_token)

def is_authenticated(self):
return True
Expand All @@ -73,8 +73,8 @@ def has_permission(self, permission):


@login_manager.user_loader
def load_user(key):
user_db = ndb.Key(urlsafe=key).get()
def load_user(session_token):
user_db = model.User.get_by('session_token', session_token)
if user_db:
return FlaskUser(user_db)
return None
Expand Down Expand Up @@ -395,6 +395,7 @@ def create_user_db(auth_id, name, username, email='', verified=False, **props):
auth_ids=[auth_id] if auth_id else [],
verified=verified,
token=util.uuid(),
session_token=util.uuid(),
**props
)
user_db.put()
Expand Down
2 changes: 2 additions & 0 deletions main/control/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def user_reset(token=None):
form = UserResetForm()
if form.validate_on_submit():
user_db.password_hash = util.password_hash(user_db, form.new_password.data)
user_db.session_token = util.uuid()
user_db.token = util.uuid()
user_db.verified = True
user_db.put()
Expand Down Expand Up @@ -261,6 +262,7 @@ def user_activate(token):
if form.validate_on_submit():
form.populate_obj(user_db)
user_db.password_hash = util.password_hash(user_db, form.password.data)
user_db.session_token = util.uuid()
user_db.token = util.uuid()
user_db.verified = True
user_db.put()
Expand Down
1 change: 1 addition & 0 deletions main/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class User(model.Base):
verified = ndb.BooleanProperty(default=False)
token = ndb.StringProperty(default='')
password_hash = ndb.StringProperty(default='')
session_token = ndb.StringProperty(default='')

def has_permission(self, perm):
return self.admin or perm in self.permissions
Expand Down

0 comments on commit d01874c

Please sign in to comment.