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

Fix: Login with email and add option to disable some external auth provider #396

Merged
merged 11 commits into from
Dec 7, 2023
Merged
6 changes: 3 additions & 3 deletions app/assets/images/icons/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions app/assets/images/icons/google.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 11 additions & 6 deletions app/assets/images/icons/keycloak.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions app/assets/images/icons/orcid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@
margin-top: 10px;
margin-bottom: 20px;
width: 357px;
}
.disabled-login-sso{
width: 40px;
margin: 7px 10px;
}
.login-active-sso path{
fill: var(--primary-color)
}
11 changes: 10 additions & 1 deletion app/controllers/login_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ def index

# logs in a user
def create
if is_email(params[:user][:username])
username = LinkedData::Client::Models::User.find_by_email(params[:user][:username]).first.username
else
username = params[:user][:username]
end
@errors = validate(params[:user])
if @errors.size < 1
logged_in_user = LinkedData::Client::Models::User.authenticate(params[:user][:username], params[:user][:password])
logged_in_user = LinkedData::Client::Models::User.authenticate(username, params[:user][:password])
if logged_in_user && !logged_in_user.errors
login(logged_in_user)
redirect = "/"
Expand Down Expand Up @@ -153,5 +158,9 @@ def validate(params)
return errors
end

def is_email(email)
email =~ /\A[^@\s]+@[^@\s]+\z/
end


end
21 changes: 13 additions & 8 deletions app/views/login/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
%p.dont-have-account
= t('login.no_account')
%a.text-decoration-none{:href => new_user_path}= t('login.register')
%hr.divider.w-100
%div.d-flex.justify-content-center.flew-wrap
%hr.divider.w-100.mb-4.mt-4
%div.d-flex.justify-content-around.flew-wrap
- omniauth_providers_info.each do |provider, config|
= button_to "/auth/#{config[:name] || config[:strategy] || provider}",
class: 'btn btn-lg', style:'width: 70px', title: "Login with #{provider.to_s.humanize}", 'data-turbo': false do
- if config[:icon]
= inline_svg config[:icon]
- else
= provider.to_s.humanize
- if config[:enable]
= button_to "/auth/#{config[:name] || config[:strategy] || provider}",
class: 'btn btn-lg',disabled: !config[:enable] ,style:'width: 70px', title: "Login with #{provider.to_s.humanize}", 'data-turbo': false do;
- if config[:icon]
= inline_svg "icons/#{config[:icon]}", class: 'login-active-sso'
- else
= provider.to_s.humanize
- else
.disabled-login-sso
= render Display::InfoTooltipComponent.new(text: "#{provider.to_s.humanize} is disabled", icon: config[:icon])

Loading