parent
e852872846
commit
47bdb9b33b
12 changed files with 117 additions and 13 deletions
|
@ -14,7 +14,7 @@ class ApplicationController < ActionController::Base
|
|||
helper_method :current_session
|
||||
helper_method :current_theme
|
||||
helper_method :single_user_mode?
|
||||
helper_method :use_pam?
|
||||
helper_method :use_seamless_external_login?
|
||||
|
||||
rescue_from ActionController::RoutingError, with: :not_found
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
||||
|
@ -76,8 +76,8 @@ class ApplicationController < ActionController::Base
|
|||
@single_user_mode ||= Rails.configuration.x.single_user_mode && Account.exists?
|
||||
end
|
||||
|
||||
def use_pam?
|
||||
Devise.pam_authentication
|
||||
def use_seamless_external_login?
|
||||
Devise.pam_authentication || Devise.ldap_authentication
|
||||
end
|
||||
|
||||
def current_account
|
||||
|
|
|
@ -37,7 +37,7 @@ class Auth::SessionsController < Devise::SessionsController
|
|||
if session[:otp_user_id]
|
||||
User.find(session[:otp_user_id])
|
||||
elsif user_params[:email]
|
||||
if use_pam? && Devise.check_at_sign && user_params[:email].index('@').nil?
|
||||
if use_seamless_external_login? && Devise.check_at_sign && user_params[:email].index('@').nil?
|
||||
User.joins(:account).find_by(accounts: { username: user_params[:email] })
|
||||
else
|
||||
User.find_for_authentication(email: user_params[:email])
|
||||
|
|
|
@ -52,7 +52,6 @@ class User < ApplicationRecord
|
|||
devise :registerable, :recoverable, :rememberable, :trackable, :validatable,
|
||||
:confirmable
|
||||
|
||||
devise :pam_authenticatable if Devise.pam_authentication
|
||||
devise :omniauthable
|
||||
|
||||
belongs_to :account, inverse_of: :user
|
||||
|
@ -117,6 +116,12 @@ class User < ApplicationRecord
|
|||
acc.destroy! unless save
|
||||
end
|
||||
|
||||
def ldap_setup(_attributes)
|
||||
self.confirmed_at = Time.now.utc
|
||||
self.admin = false
|
||||
save!
|
||||
end
|
||||
|
||||
def confirmed?
|
||||
confirmed_at.present?
|
||||
end
|
||||
|
@ -247,17 +252,17 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def password_required?
|
||||
return false if Devise.pam_authentication
|
||||
return false if Devise.pam_authentication || Devise.ldap_authentication
|
||||
super
|
||||
end
|
||||
|
||||
def send_reset_password_instructions
|
||||
return false if encrypted_password.blank? && Devise.pam_authentication
|
||||
return false if encrypted_password.blank? && (Devise.pam_authentication || Devise.ldap_authentication)
|
||||
super
|
||||
end
|
||||
|
||||
def reset_password!(new_password, new_password_confirmation)
|
||||
return false if encrypted_password.blank? && Devise.pam_authentication
|
||||
return false if encrypted_password.blank? && (Devise.pam_authentication || Devise.ldap_authentication)
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -280,6 +285,17 @@ class User < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def self.ldap_get_user(attributes = {})
|
||||
resource = joins(:account).find_by(accounts: { username: attributes[Devise.ldap_uid.to_sym].first })
|
||||
|
||||
if resource.blank?
|
||||
resource = new(email: attributes[:mail].first, account_attributes: { username: attributes[Devise.ldap_uid.to_sym].first })
|
||||
resource.ldap_setup(attributes)
|
||||
end
|
||||
|
||||
resource
|
||||
end
|
||||
|
||||
def self.authenticate_with_pam(attributes = {})
|
||||
return nil unless Devise.pam_authentication
|
||||
super
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f|
|
||||
= render 'shared/error_messages', object: resource
|
||||
|
||||
- if !use_pam? || resource.encrypted_password.present?
|
||||
- if !use_seamless_external_login?? || resource.encrypted_password.present?
|
||||
= f.input :reset_password_token, as: :hidden
|
||||
|
||||
= f.input :password, autofocus: true, placeholder: t('simple_form.labels.defaults.new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.new_password'), :autocomplete => 'off' }
|
||||
|
@ -13,6 +13,6 @@
|
|||
.actions
|
||||
= f.button :button, t('auth.set_new_password'), type: :submit
|
||||
- else
|
||||
= t('simple_form.labels.defaults.pam_account')
|
||||
%p.hint= t('users.seamless_external_login')
|
||||
|
||||
.form-footer= render 'auth/shared/links'
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class: 'auth_edit' }) do |f|
|
||||
= render 'shared/error_messages', object: resource
|
||||
|
||||
- if !use_pam? || resource.encrypted_password.present?
|
||||
- if !use_seamless_external_login? || resource.encrypted_password.present?
|
||||
= f.input :email, placeholder: t('simple_form.labels.defaults.email'), input_html: { 'aria-label' => t('simple_form.labels.defaults.email') }
|
||||
= f.input :password, placeholder: t('simple_form.labels.defaults.new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.new_password'), :autocomplete => 'off' }
|
||||
= f.input :password_confirmation, placeholder: t('simple_form.labels.defaults.confirm_new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_new_password'), :autocomplete => 'off' }
|
||||
|
@ -13,7 +13,7 @@
|
|||
.actions
|
||||
= f.button :button, t('generic.save_changes'), type: :submit
|
||||
- else
|
||||
= t('simple_form.labels.defaults.pam_account')
|
||||
%p.hint= t('users.seamless_external_login')
|
||||
|
||||
%hr/
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
= render partial: 'shared/og'
|
||||
|
||||
= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
|
||||
- if use_pam?
|
||||
- if use_seamless_external_login?
|
||||
= f.input :email, autofocus: true, placeholder: t('simple_form.labels.defaults.username_or_email'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username_or_email') }
|
||||
- else
|
||||
= f.input :email, autofocus: true, placeholder: t('simple_form.labels.defaults.email'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.email') }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue