Guest User

Untitled

a guest
Feb 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class ApplicationController < ActionController::Base
  2. # ...
  3.  
  4. helper_method :admin?
  5.  
  6. private
  7.  
  8. def admin?
  9. ##
  10. # Turns out this doesn't work on actions
  11. # where authorize isn't called
  12. #
  13. #request.env['HTTP_AUTHORIZATION'] ||
  14. #request.env['X-HTTP_AUTHORIZATION'] ||
  15. #request.env['X_HTTP_AUTHORIZATION'] ||
  16. #request.env['REDIRECT_X_HTTP_AUTHORIZATION']
  17. #
  18. # This on the other hand does
  19. #request_http_basic_authentication
  20. #
  21. # No..... It Didn't.
  22. # Now what do we do?
  23. true
  24. end
  25.  
  26. protected
  27.  
  28. def authorize
  29. authenticate_or_request_with_http_basic do |username, password|
  30. username == "foo" && password == "bar"
  31. end
  32. end
  33.  
  34. end
Add Comment
Please, Sign In to add comment