forked from gergely/calendar-social
Make it possible to list and invalidate active sessions
This commit is contained in:
@@ -27,6 +27,7 @@ from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from sqlalchemy_utils.types.choice import ChoiceType
|
||||
|
||||
from .cache import cache
|
||||
from .utils import force_locale
|
||||
|
||||
db = SQLAlchemy()
|
||||
@@ -219,6 +220,21 @@ class User(db.Model, UserMixin):
|
||||
|
||||
return current_app.timezone
|
||||
|
||||
@property
|
||||
def session_list_key(self):
|
||||
"""The cache key of this user’s session list
|
||||
"""
|
||||
|
||||
return f'open_sessions:{self.id}'
|
||||
|
||||
@property
|
||||
def active_sessions(self):
|
||||
return cache.get(self.session_list_key) or []
|
||||
|
||||
@active_sessions.setter
|
||||
def active_sessions(self, value):
|
||||
cache.set(self.session_list_key, list(value))
|
||||
|
||||
def __repr__(self):
|
||||
return f'<User {self.id}({self.username})>'
|
||||
|
||||
|
Reference in New Issue
Block a user