Commit f4e6d9e3 authored by o's avatar o
Browse files

preserve the list of logged in pages across logins

parent ea8013cb
......@@ -71,12 +71,33 @@ class ApplicationController < ActionController::Base
end
helper_method :update_session_expiry
def where_am_i_logged_in
return [] unless session[:logged_in]
return [] unless session[:login_user]
session[:logged_in][session[:login_user]] || []
end
def remember_login(what)
session[:logged_in] ||= {}
session[:logged_in][session[:login_user]] ||= []
session[:logged_in][session[:login_user]] << what
session[:logged_in][session[:login_user]].uniq!
end
def reset_user_session
session[:user_id] = nil
url = session[:origin_url]
unless session_expired?
url = session[:origin_url]
# remember the list of places where we logged in in the past. this is just
# for the UI, not actually auth
if session[:login_user]
logged_in = session[:logged_in]
end
end
reset_session
session[:locale] = I18n.locale
session[:origin_url] = url
session[:logged_in] = logged_in
update_session_expiry
end
end
......@@ -8,13 +8,7 @@ class LoginController < ApplicationController
def save_login_token(res, user)
session[:login_token] = res['login_token']
session[:login_user] = user
end
def reset_user_session_post_login
logged_in = session[:logged_in] || []
# Login ok
reset_user_session
session[:logged_in] = logged_in
remember_login(current_login_service_name)
end
def login
......@@ -60,11 +54,9 @@ class LoginController < ApplicationController
if res = auth(@input_user_id, @input_pw, @input_unlock, @input_totp)
# Login ok
reset_user_session_post_login
reset_user_session
save_login_token(res, @input_user_id)
session[:logged_in] << current_login_service_name
session[:logged_in].uniq!
if CountIpFails
Rails.cache.write(client_auth_key, 0, expires_in: 10.minutes)
......
......@@ -3,6 +3,6 @@ class MainController < ApplicationController
unless has_login_token?
redirect_to 'https://www.immerda.ch'
end
@logged_in = session[:logged_in]
@logged_in = where_am_i_logged_in
end
end
......@@ -45,11 +45,9 @@ class SamlLoginController < LoginController
if res = ApiBackend::reissue_saml(user,
session[:login_token],
@saml_request)
reset_user_session_post_login
reset_user_session
save_login_token(res, user)
session[:logged_in] << current_login_service_name
session[:logged_in].uniq!
return successful_login(res, nil)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment