Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class UserSession < Authlogic::Session::Base

  verify_password_method :valid_ldap_credentials?

end 

class User < ActiveRecord::Base

  acts_as_authentic :validate_password_field => false

  protected
    def valid_ldap_credentials?(password_plaintext)
      # try to authenticate against the LDAP server
      ldap = Net::LDAP.new
      ldap.host = LDAP_HOST
      # first create the username/password strings to send to the LDAP server
      # in our case we need to add the domain so it looks like COMPANY\firstname.lastname
      ldap.auth "#{LDAP_DOMAIN}\\" + self.login, password_plaintext
      ldap.bind # will return false if authentication is NOT successful
    end

end


class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :login
      t.string :persistence_token
      t.integer :login_count
      t.datetime :last_request_at
      t.datetime :last_login_at
      t.datetime :current_login_at
      t.string :last_login_ip
      t.string :current_login_ip
      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end