def logout() -> Union[str, werkzeug.Response]: """ If a user is logged in, show them a logout page that prompts them to click the New Identity button in Tor Browser to complete their session. Otherwise redirect to the main Source Interface page. """ if SessionManager.is_user_logged_in(db_session=db.session): SessionManager.log_user_out() # Clear the session after we render the message so it's localized # If a user specified a locale, save it and restore it session.clear() session["locale"] = g.localeinfo.id return render_template("logout.html") else: return redirect(url_for(".index"))
def test_log_user_out(self, source_app, app_storage): # Given a source user passphrase = PassphraseGenerator.get_default().generate_passphrase() create_source_user( db_session=db.session, source_passphrase=passphrase, source_app_storage=app_storage, ) with source_app.test_request_context(): # Who previously logged in SessionManager.log_user_in(db_session=db.session, supplied_passphrase=passphrase) # When they log out, it succeeds SessionManager.log_user_out() # And the SessionManager no longer returns a current user assert not SessionManager.is_user_logged_in(db_session=db.session) with pytest.raises(UserNotLoggedIn): SessionManager.get_logged_in_user(db_session=db.session)