Refactor User model, extract PamAuthenticable, LdapAuthenticable (#10217)

This commit is contained in:
Eugen Rochko 2019-03-14 02:13:42 +01:00 committed by GitHub
parent dfb9efae81
commit 9e33174604
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 155 additions and 120 deletions

View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
module LdapAuthenticable
extend ActiveSupport::Concern
def ldap_setup(_attributes)
self.confirmed_at = Time.now.utc
self.admin = false
save!
end
class_methods do
def 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, agreement: true, account_attributes: { username: attributes[Devise.ldap_uid.to_sym].first })
resource.ldap_setup(attributes)
end
resource
end
end
end