Module: Devise::Models::LdapAuthenticatable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise_ldap_authenticatable/model.rb
Overview
LDAP Module, responsible for validating the user credentials via LDAP.
Examples:
User.authenticate('[email protected]', 'password123') # returns authenticated user or nil
User.find(1).valid_password?('password123') # returns true/false
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #change_password!(current_password) ⇒ Object
- #ldap_dn ⇒ Object
- #ldap_get_param(login_with, param) ⇒ Object
- #ldap_groups ⇒ Object
- #login_with ⇒ Object
- #password=(new_password) ⇒ Object
- #reset_password!(new_password, new_password_confirmation) ⇒ Object
-
#valid_ldap_authentication?(password) ⇒ Boolean
Checks if a resource is valid upon authentication.
Instance Method Details
#change_password!(current_password) ⇒ Object
25 26 27 28 29 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 25 def change_password!(current_password) raise "Need to set new password first" if @password.blank? Devise::LdapAdapter.update_own_password(login_with, @password, current_password) end |
#ldap_dn ⇒ Object
56 57 58 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 56 def ldap_dn Devise::LdapAdapter.get_dn(login_with) end |
#ldap_get_param(login_with, param) ⇒ Object
60 61 62 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 60 def ldap_get_param(login_with, param) Devise::LdapAdapter.get_ldap_param(login_with,param) end |
#ldap_groups ⇒ Object
52 53 54 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 52 def ldap_groups Devise::LdapAdapter.get_groups(login_with) end |
#login_with ⇒ Object
20 21 22 23 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 20 def login_with @login_with ||= Devise.mappings[self.class.to_s.underscore.to_sym].to.authentication_keys.first self[@login_with] end |
#password=(new_password) ⇒ Object
39 40 41 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 39 def password=(new_password) @password = new_password end |
#reset_password!(new_password, new_password_confirmation) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 31 def reset_password!(new_password, new_password_confirmation) if new_password == new_password_confirmation && ::Devise.ldap_update_password Devise::LdapAdapter.update_password(login_with, new_password) end clear_reset_password_token if valid? save end |
#valid_ldap_authentication?(password) ⇒ Boolean
Checks if a resource is valid upon authentication.
44 45 46 47 48 49 50 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 44 def valid_ldap_authentication?(password) if Devise::LdapAdapter.valid_credentials?(login_with, password) return true else return false end end |