You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
627 B

  1. # frozen_string_literal: true
  2. module LdapAuthenticable
  3. extend ActiveSupport::Concern
  4. def ldap_setup(_attributes)
  5. self.confirmed_at = Time.now.utc
  6. self.admin = false
  7. save!
  8. end
  9. class_methods do
  10. def ldap_get_user(attributes = {})
  11. resource = joins(:account).find_by(accounts: { username: attributes[Devise.ldap_uid.to_sym].first })
  12. if resource.blank?
  13. resource = new(email: attributes[:mail].first, agreement: true, account_attributes: { username: attributes[Devise.ldap_uid.to_sym].first })
  14. resource.ldap_setup(attributes)
  15. end
  16. resource
  17. end
  18. end
  19. end