Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show errors for sso failure, handle sso from users with an existing email address #978

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def callback
# where we want a JS-based redirect to go.
render 'complete', locals: { redirect_to_url: url || hyrax.dashboard_path }
else
session['devise.user_attributes'] = @user.attributes
redirect_to new_user_registration_url
redirect_to root_path, flash: {error: 'Not able to log in user. #{@user.errors.full_messages}'}
end
end
alias cas callback
Expand All @@ -42,8 +41,8 @@ def passthru
render status: 404, plain: 'Not found. Authentication passthru.'
end

# def failure
# #redirect_to root_path
# end
def failure
redirect_to root_path, flash: {error: 'Authentication Failed. Something is wrong with the SSO configuration.'}
end
end
end
31 changes: 17 additions & 14 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ def self.default_scope
scope :registered, -> { for_repository.group(:id).where(guest: false) }

def self.from_omniauth(auth)
find_or_create_by(provider: auth.provider, uid: auth.uid) do |user|
user.email = auth&.info&.email
user.email ||= auth.uid
# rubocop:disable Performance/RedundantMatch
user.email = [auth.uid, '@', Site.instance.account.email_domain].join unless user.email.match('@')
# rubocop:enable Performance/RedundantMatch
user.password = Devise.friendly_token[0, 20]
user.display_name = auth&.info&.name # assuming the user model has a name
user.display_name ||= "#{auth&.info&.first_name} #{auth&.info&.last_name}" if auth&.info&.first_name && auth&.info&.last_name
# user.image = auth.info.image # assuming the user model has an image
# If you are using confirmable and the provider(s) you use validate emails,
# uncomment the line below to skip the confirmation emails.
# user.skip_confirmation!
end
u = find_by(provider: auth.provider, uid: auth.uid)
return u if u

u = find_by(email: auth&.info&.email&.downcase)
u ||= new
u.provider = auth.provider
u.uid = auth.uid
u.email = auth&.info&.email
u.email ||= auth.uid
# rubocop:disable Performance/RedundantMatch
u.email = [auth.uid, '@', Site.instance.account.email_domain].join unless u.email.match('@')
# rubocop:enable Performance/RedundantMatch
u.password = Devise.friendly_token[0, 20] if u.new_record?
u.display_name = auth&.info&.name # assuming the user model has a name
u.display_name ||= "#{auth&.info&.first_name} #{auth&.info&.last_name}" if auth&.info&.first_name && auth&.info&.last_name
u.save
u
end

# Method added by Blacklight; Blacklight uses #to_s on your
Expand Down
Loading