R
R
Radist_1012015-09-25 13:00:06
Flask
Radist_101, 2015-09-25 13:00:06

How to force logout in flask?

Good day! How to force logout for a user in flask if the same user logs in through another device? The flask-login library is used, there is also a version with flask-httpauth

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pcdesign, 2015-09-25
@Radist_101

Maybe shove it into before_request something like this?

@app.before_request
def before_request():
    user_id = session.get('user_id', None)
    # Дальше проверяем, есть ли у user_id  другие открытые сессии.
    # Если сессия есть, то 
    # session.clear()

R
Radist_101, 2015-09-26
@Radist_101

In the flask-login settings, I found such a session_protection parameter, this is an attribute of the LoginManager instance.
login_manager = LoginManager()
login_manager.session_protection = 'strong'
If session_protection == 'strong' the session will be forced to end if the client tries to log in from different browsers and different IPs. But I try to log in from a computer and from a phone, authorization passes without problems

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question