Class: CmsUser

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cms_user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#password_confirmationObject

Returns the value of attribute password_confirmation.



14
15
16
# File 'app/models/cms_user.rb', line 14

def password_confirmation
  @password_confirmation
end

Class Method Details

.authenticate(login, password, authentication, ldap_hostname, ldap_base_DN, ldap_uid) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/cms_user.rb', line 33

def self.authenticate(, password, authentication, ldap_hostname, ldap_base_DN, ldap_uid)

  if authentication == 'LDAP'
    username = 

    if (password.empty?) then
      return nil
    end

    ldap = Net::LDAP.new(:host => ldap_hostname, :base => ldap_base_DN)
    filter = Net::LDAP::Filter.eq(ldap_uid, )
    ldap.search(:filter => filter) {|entry|  = entry.dn}
    ldap.auth(, password)

    if ldap.bind
      user = CmsUser.(username, false) # need to check if user is in the database and not disabled
      if (user)
        return user
      else
        #user is in LDAP but not in local database
        return nil
      end
    else
      #authentication failed
      return nil
    end
  else
    user= self.()
    if user
      expected_password = encrypted_password(password, user.salt)
      if user.hashed_password != expected_password
        user = nil
      end
    end
    user
  end

end

Instance Method Details

#full_nameObject



29
30
31
# File 'app/models/cms_user.rb', line 29

def full_name
  [first_name, last_name].join(' ')
end

#passwordObject

‘password’ is a virtual attribute



18
19
20
# File 'app/models/cms_user.rb', line 18

def password
  @password
end

#password=(pwd) ⇒ Object



22
23
24
25
26
27
# File 'app/models/cms_user.rb', line 22

def password=(pwd)
  @password = pwd
  return if pwd.blank?
  create_new_salt
  self.hashed_password = CmsUser.encrypted_password(self.password, self.salt)
end