Guest User

Untitled

a guest
Jul 26th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. Ruby rails - session management
  2. def self.Authenticate(login, pass)
  3. user = find_by_user_id(login)
  4. if user
  5. user
  6. else
  7. return false
  8. end
  9. conn = Net::LDAP.new(
  10. :host => SERVER,
  11. :port => PORT,
  12. :base => BASE,
  13. :auth => {
  14. :username => "#{login}@#{DOMAIN}",
  15. :password => pass,
  16. :method => :simple
  17. }
  18. )
  19. if conn.bind
  20. return true
  21. else
  22. return false
  23. end
  24. rescue Net::LDAP::LdapError => e
  25. return false
  26. end
  27.  
  28. def create
  29. user = User.Authenticate(params[:user_id], params[:password])
  30.  
  31. if user
  32. session[:user_id] = user.id
  33. redirect_to theapp_url, :notice => "Logged in!"
  34. else
  35. flash.now.alert = "Invalid email or password"
  36. render "new"
  37. end
  38. end
  39.  
  40. <%= form_tag sessions_path do %>
  41. <p>
  42. <%= label_tag :Username %><br />
  43. <%= text_field_tag :user_id, params[:user_id] %>
  44. </p>
  45. <p>
  46. <%= label_tag :Password %><br />
  47. <%= password_field_tag :password %>
  48. </p>
  49. <p class="button"><%= submit_tag "Log in" %></p>
  50. <% end %>
  51.  
  52. NoMethodError in SessionsController#create
  53.  
  54. undefined method `id' for true:TrueClass
  55. Rails.root: /myapp
  56.  
  57. Application Trace | Framework Trace | Full Trace
  58. app/controllers/sessions_controller.rb:12:in `create'
  59. Request
  60.  
  61. Parameters:
  62.  
  63. {"utf8"=>"✓",
  64. "authenticity_token"=>"OmzCrLHR1t/xfIXNcEzy2NCGfVpEKSyI4OZfqpPEFNw=",
  65. "user_id"=>"admin",
  66. "password"=>"[FILTERED]",
  67. "commit"=>"Log in"}
Add Comment
Please, Sign In to add comment