Class: LdapRails::LdapUser
- Inherits:
-
Object
- Object
- LdapRails::LdapUser
- Defined in:
- lib/ldap-rails/ldap_user.rb
Instance Attribute Summary collapse
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.auth(username, password) ⇒ Object
Tries to authenticate using the given username and password.
Instance Method Summary collapse
-
#initialize(hash) ⇒ LdapUser
constructor
A new instance of LdapUser.
- #to_hash ⇒ Object
Constructor Details
#initialize(hash) ⇒ LdapUser
Returns a new instance of LdapUser.
7 8 9 |
# File 'lib/ldap-rails/ldap_user.rb', line 7 def initialize hash @username = hash[:username] end |
Instance Attribute Details
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/ldap-rails/ldap_user.rb', line 5 def username @username end |
Class Method Details
.auth(username, password) ⇒ Object
Tries to authenticate using the given username and password. Returns an LdapUser is successful, nil if unsuccessful.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ldap-rails/ldap_user.rb', line 17 def self.auth username, password unless LdapRails.config raise NoConfigurationError.new("You must have a call to LdapRails.configure in an initializer.") end LdapRails.ldap.auth dn_for(username), password if LdapRails.ldap.bind return new(:username => username) else return nil end end |
Instance Method Details
#to_hash ⇒ Object
11 12 13 |
# File 'lib/ldap-rails/ldap_user.rb', line 11 def to_hash {:username => @username} end |