Guest User

Untitled

a guest
Apr 10th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. <% form_tag do %>
  2. <p>Please authenticate</p>
  3. <p>
  4. <label>Username:</label>
  5. <%= text_field_tag 'login' %>
  6. </p>
  7. <p>
  8. <label>Password:</label>
  9. <%= password_field_tag 'password' %>
  10. </p>
  11. <p><%= submit_tag 'login' %></p>
  12. <% end %>
  13.  
  14.  
  15.  
  16. class AuthController < ApplicationController
  17.  
  18. def login
  19. if request.post?
  20. if authenticated?(login, password)
  21. redirect_to :controller => 'story'
  22. end
  23.  
  24. end
  25. end
  26.  
  27. def logout
  28. end
  29. end
  30.  
  31.  
  32.  
  33. require "net/ldap"
  34.  
  35. DOMAIN_CONTROLLER = "my.spiffy.ldap.server"
  36. LDAP_PORT = 389
  37.  
  38. def self.authenticated?(username, password)
  39. ldap = Net::LDAP.new
  40. ldap.host = DOMAIN_CONTROLLER
  41. ldap.port = LDAP_PORT
  42.  
  43. ldap.auth( username, password )
  44.  
  45. return ldap.bind
  46. end
Add Comment
Please, Sign In to add comment