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.

26 lines
656 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. self.external = true
  8. save!
  9. end
  10. class_methods do
  11. def ldap_get_user(attributes = {})
  12. resource = joins(:account).find_by(accounts: { username: attributes[Devise.ldap_uid.to_sym].first })
  13. if resource.blank?
  14. resource = new(email: attributes[:mail].first, agreement: true, account_attributes: { username: attributes[Devise.ldap_uid.to_sym].first })
  15. resource.ldap_setup(attributes)
  16. end
  17. resource
  18. end
  19. end
  20. end