Skip to content

Commit

Permalink
Merge pull request #29 from MozillaSocial/skip-login-interstitial
Browse files Browse the repository at this point in the history
Replace 'Login with...' page with auto-redirect script
  • Loading branch information
aaga committed Aug 15, 2023
2 parents 93e19e4 + 4fe0aa5 commit 7107548
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ApplicationController < ActionController::Base
helper_method :whitelist_mode?
helper_method :body_class_string
helper_method :skip_csrf_meta_tags?
helper_method :sso_redirect

rescue_from ActionController::ParameterMissing, Paperclip::AdapterRegistry::NoHandlerError, with: :bad_request
rescue_from Mastodon::NotPermittedError, with: :forbidden
Expand Down Expand Up @@ -135,6 +136,10 @@ def omniauth_only?
ENV['OMNIAUTH_ONLY'] == 'true'
end

def sso_redirect
"/auth/auth/#{Devise.omniauth_providers[0]}" if ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1
end

def sso_account_settings
ENV.fetch('SSO_ACCOUNT_SETTINGS', nil)
end
Expand Down
37 changes: 30 additions & 7 deletions app/views/auth/sessions/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
- content_for :page_title do
= t('auth.login')

- content_for :header_tags do
= render partial: 'shared/og'
- unless sso_redirect
- content_for :header_tags do
= render partial: 'shared/og'

- unless omniauth_only?
= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
Expand All @@ -21,10 +22,32 @@

- if devise_mapping.omniauthable? && resource_class.omniauth_providers.any?
.simple_form.alternative-login
%h4= omniauth_only? ? t('auth.log_in_with') : t('auth.or_log_in_with')
- if sso_redirect
%h4= 'Redirecting...'
-else
%h4= omniauth_only? ? t('auth.log_in_with') : t('auth.or_log_in_with')

.actions
- resource_class.omniauth_providers.each do |provider|
= provider_sign_in_link(provider)
.actions
- resource_class.omniauth_providers.each do |provider|
= provider_sign_in_link(provider)

- if sso_redirect
:javascript
(function() {
let form = document.createElement('form');
form.action = '#{ sso_redirect }';
form.method = 'post';
if (localStorage.getItem("mozsoc.auth_intent") == 'signup') {
let input = document.createElement('input');
input.type = 'hidden';
input.name = 'intent';
input.value = 'signup';
form.append(input);
}
localStorage.removeItem('mozsoc.auth_intent');
document.body.append(form);
form.submit();
})();

.form-footer= render 'auth/shared/links'
- unless sso_redirect
.form-footer= render 'auth/shared/links'

0 comments on commit 7107548

Please sign in to comment.