Commit 0125893f authored by o's avatar o
Browse files

have a main screen that shows current login sessions

parent 8512989a
......@@ -45,15 +45,9 @@ class ApplicationController < ActionController::Base
session[:locale] = I18n.locale
end
def admin?
@is_admin ||= Admin::Enabled && Admin::Admins.include?(current_user)
def has_login_token?
session[:login_token] && !session_expired?
end
helper_method :admin?
def feature_toggle?(*features)
features.any?{|f| (Config['features'] || []).include?(f) }
end
helper_method :feature_toggle?
def session_expired?
expire_time = session[:expires_at].to_i || Time.now.to_i
......
......@@ -8,6 +8,10 @@ class HandoffLoginController < LoginController
totp: totp)
end
def current_login_service_name
@handoff
end
protected
def successful_login(options, pw)
@user = options["email"]
......
......@@ -10,6 +10,13 @@ class LoginController < ApplicationController
session[:login_user] = @input_user_id
end
def reset_user_session_post_login
logged_in = session[:logged_in] || []
# Login ok
reset_user_session
session[:logged_in] = logged_in
end
def login
unless session[:properly_initialized]
return new_login_session
......@@ -51,9 +58,13 @@ class LoginController < ApplicationController
begin
if res = auth(@input_user_id, @input_pw, @input_unlock, @input_totp)
# Login ok
reset_user_session
reset_user_session_post_login
save_login_token(res)
session[:logged_in] << current_login_service_name
session[:logged_in].uniq!
if CountIpFails
Rails.cache.write(client_auth_key, 0, expires_in: 10.minutes)
......
class MainController < ApplicationController
def show
unless has_login_token?
redirect_to 'https://www.immerda.ch'
end
@logged_in = session[:logged_in]
end
end
......@@ -32,15 +32,23 @@ class SamlLoginController < LoginController
end
public
def current_login_service_name
@sp_info[:name]
end
def new
if !session_expired? && session[:login_token]
if has_login_token?
update_session_expiry
load_custom_params_new
if res = ApiBackend::reissue_saml(session[:login_user],
session[:login_token],
@saml_request)
reset_user_session
reset_user_session_post_login
save_login_token(res)
session[:logged_in] << current_login_service_name
session[:logged_in].uniq!
return successful_login(res, nil)
end
end
......
<%= link_to t(:logout), logout_path %>
<br />
<br />
<br />
<br />
<p>
<%= t(:current_sessions) %>
<ul>
<% @logged_in.each do |l| %>
<li><%= l %></li>
<% end %>
</ul>
</p>
......@@ -16,6 +16,8 @@ de:
recovery_token_hint: "Wir empfehlen dir einen Wiederherstellungscode zu generieren"
current_sessions: "Aktuell angemeldete Sitzungen"
login_failed: "Anmeldung fehlgeschlagen"
login: "Anmelden"
requires_javascript: "Javascript wird benötigt um sich anzumelden. Es werden nur Javascript Resourcen von dieser Domain benötigt."
......
......@@ -16,6 +16,8 @@ en:
recovery_token_hint: "We recommend you generate a recovery token"
current_sessions: "Currently existing sessions"
login_failed: "Login failed"
login: "Login"
requires_javascript: "Javascript is required to login! Only Javascript resources of this domain are required."
......
Rails.application.routes.draw do
root to: redirect("https://www.immerda.ch")
root to: 'main#show'
get '/login/saml', to: 'saml_login#new'
post '/login/saml', to: 'saml_login#login'
......
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