diff --git a/app/controllers/identifiers_controller.rb b/app/controllers/identifiers_controller.rb index e505e0376d..5d01ac4959 100644 --- a/app/controllers/identifiers_controller.rb +++ b/app/controllers/identifiers_controller.rb @@ -8,7 +8,6 @@ class IdentifiersController < ApplicationController # DELETE /users/identifiers # rubocop:disable Metrics/AbcSize def destroy - # byebug authorize Identifier user = User.find(current_user.id) identifier = Identifier.find(params[:id]) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index e33a2f6b9d..2fcd18f588 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -12,24 +12,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController end end - - # def openid_connect - # @user = User.from_omniauth(request.env["omniauth.auth"]) - - # if @user.present? - # sign_in_and_redirect @user, event: :authentication - # set_flash_message(:notice, :success, kind: "OpenID Connect") if is_navigational_format? - # else - # session["devise.openid_connect_data"] = request.env["omniauth.auth"] - # redirect_to new_user_registration_url - # end - # end - - - - #This is for the OpenidConnect CILogon - def openid_connect # First or create auth = request.env['omniauth.auth'] @@ -40,7 +23,7 @@ def openid_connect #If email is missing we need to request the user to register with DMP. #User email can be missing if the user email id is set to private or trusted clients only we won't get the value. #USer email id is one of the mandatory field which is must required. - flash[:notice] = 'Please try sign-up with DMP assistant.' + flash[:notice] = 'Something went wrong, Please try signing-up here.' redirect_to new_user_registration_path elsif current_user.nil? # We need to register @@ -51,7 +34,6 @@ def openid_connect value: auth.uid, attrs: auth, identifiable: user) - end sign_in_and_redirect user, event: :authentication elsif user.nil? @@ -61,12 +43,18 @@ def openid_connect attrs: auth, identifiable: current_user) - flash[:notice] = 'linked succesfully' - redirect_to root_path + flash[:notice] = 'Linked succesfully' + redirect_to root_path end end + def orcid + handle_omniauth(IdentifierScheme.for_authentication.find_by(name: 'orcid')) + end + def shibboleth + handle_omniauth(IdentifierScheme.for_authentication.find_by(name: 'shibboleth')) + end # Processes callbacks from an omniauth provider and directs the user to # the appropriate page: diff --git a/app/models/user.rb b/app/models/user.rb index 7968959fad..4fa0f99a94 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -177,39 +177,29 @@ class User < ApplicationRecord ## # Load the user based on the scheme and id provided by the Omniauth call def self.from_omniauth(auth) - # byebug Identifier.by_scheme_name(auth.provider.downcase.to_s, 'User') .where(value: auth.uid) .first&.identifiable - # end - - - # Rails.logger.info "OmniAuth Auth Hash: #{auth.inspect}" - # where(provider: auth.provider, uid: auth.uid).first_or_create do |user| - # user.provider = auth.provider - # user.uid = auth.uid - # user.email = auth.info.email - # user.password = Devise.friendly_token[0,20] - # end - # # # .where(value: auth.info.eppn) #need to add a cilogon condition for this - # # .first&.identifiable - # # .where(value: auth.uid).first_or_create do |user| - # # user.email = auth.info.email - # # user.password = Devise.friendly_token[0, 20] - # # user.name = auth.info.name # if the User model has a name - # # end end - # def self.from_omniauth(auth) - # Rails.logger.info "OmniAuth Auth Hash: #{auth.inspect}" - # where(provider: auth.provider, uid: auth.uid).first_or_create do |user| - # user.provider = auth.provider - # user.uid = auth.uid - # user.email = auth.info.email if !auth.info.email_verified.nil? - # user.password = Devise.friendly_token[0,20] - # end - # end + # Handle user creation from provider + def self.create_from_provider_data(provider_data) + user = User.find_by email: provider_data.info.email + + return user if user + + user = User.new( + firstname: provider_data.info.first_name, + surname: provider_data.info.last_name, + email: provider_data.info.email, + # We don't know which organization to setup so we will use other + org: Org.find_by(is_other: true), + accept_terms: true, + password: Devise.friendly_token[0, 20] + ) + user.save + end def self.to_csv(users) User::AtCsv.new(users).to_csv diff --git a/app/views/shared/_sign_in_form.html.erb b/app/views/shared/_sign_in_form.html.erb index ff624618fc..55fc8a490a 100644 --- a/app/views/shared/_sign_in_form.html.erb +++ b/app/views/shared/_sign_in_form.html.erb @@ -40,15 +40,10 @@
- <%= _('or') %> -