diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb index a3e50bf..8e5f617 100644 --- a/app/controllers/orgs_controller.rb +++ b/app/controllers/orgs_controller.rb @@ -1,5 +1,5 @@ class OrgsController < ApplicationController - after_action :verify_authorized, except: ['shibboleth_ds'] + after_action :verify_authorized, except: ['shibboleth_ds', 'shibboleth_ds_passthru'] respond_to :html ## @@ -46,10 +46,32 @@ # GET /orgs/shibboleth_ds def shibboleth_ds + @user = User.new # Display the custom Shibboleth discovery service page. @orgs = Org.joins(:identifier_schemes).where('identifier_schemes.name = ?', 'shibboleth').sort{|x,y| x.name <=> y.name } end + # POST /orgs/shibboleth_ds + def shibboleth_ds_passthru + if !params[:org_name].blank? + session['org_id'] = params[:org_name] + elsif session['org_id'].blank? + flash[:notice] = _('Please choose an institution') + render action: 'shibboleth_ds' + end + + scheme = IdentifierScheme.find_by(name: 'shibboleth') + shib_entity = OrgIdentifier.where(org_id: params[:org_name], identifier_scheme: scheme) + + if !shib_entity.empty? + #initiate shibboleth login sequence + redirect_to "#{request.base_url}#{Rails.application.config.shibboleth_login}?target=#{user_shibboleth_omniauth_callback_url}&entityID=#{shib_entity.first.identifier}" + else + flash[:notice] = _('Your institution does not seem to be properly configured.') + render action: 'shibboleth_ds' + end + end + private def org_params params.require(:org).permit(:name, :abbreviation, :target_url, :is_other, :banner_text, :language_id, diff --git a/app/views/orgs/shibboleth_ds.html.erb b/app/views/orgs/shibboleth_ds.html.erb index f392c57..f1522af 100644 --- a/app/views/orgs/shibboleth_ds.html.erb +++ b/app/views/orgs/shibboleth_ds.html.erb @@ -3,7 +3,7 @@

Find your institution to sign in

-
+ <%= form_for 'shibboleth_ds', url: shibboleth_ds_path, html: {class: "shibboleth-ds-form roadmap-form"} do |f| %>
-
+ <% end %>
diff --git a/app/views/shared/_login_form.html.erb b/app/views/shared/_login_form.html.erb index 6b889d1..8495417 100644 --- a/app/views/shared/_login_form.html.erb +++ b/app/views/shared/_login_form.html.erb @@ -8,7 +8,8 @@
<% if request.fullpath != "/users/sign_up?nosplash=true" && session[:shibboleth_data].nil? then%> - <%else%> diff --git a/config/routes.rb b/config/routes.rb index 8f87b9a..b114317 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,6 +52,7 @@ delete '/users/identifiers/:id', to: 'user_identifiers#destroy', as: 'destroy_user_identifier' get '/orgs/shibboleth', to: 'orgs#shibboleth_ds', as: 'shibboleth_ds' + post '/orgs/shibboleth', to: 'orgs#shibboleth_ds_passthru' #ActiveAdmin.routes(self) diff --git a/lib/assets/javascripts/orgs/shibboleth_ds.js b/lib/assets/javascripts/orgs/shibboleth_ds.js index f876c5a..aae05ec 100644 --- a/lib/assets/javascripts/orgs/shibboleth_ds.js +++ b/lib/assets/javascripts/orgs/shibboleth_ds.js @@ -1,4 +1,9 @@ $(document).ready(function(){ + // If the hidden valid-form field is set to true then enable the submit button + $("#org_id").change(function(){ + $(this).siblings(".form-submit").attr('aria-disabled', $(this).val() === ""); + }); + $("#show_list").click(function(e){ e.preventDefault(); if($("#full_list").css("display") == "none"){