Guest User

Untitled

a guest
Mar 8th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. def check_feed_authorization
  2. if request.env.has_key? 'X-HTTP_AUTHORIZATION'
  3. # try to get it where mod_rewrite might have put it
  4. authdata = @request.env['X-HTTP_AUTHORIZATION'].to_s.split
  5. elsif request.env.has_key? 'HTTP_AUTHORIZATION'
  6. # this is the regular location
  7. authdata = @request.env['HTTP_AUTHORIZATION'].to_s.split
  8. end
  9.  
  10. # at the moment we only support basic authentication
  11. @allowed_user=nil
  12. if authdata and authdata[0] == 'Basic'
  13. email,password=Base64.decode64(authdata[1]).split(':')[0..1]
  14. @allowed_user = User.authenticate(email,password)
  15. end
  16.  
  17. if @allowed_user
  18. return @allowed_user
  19. else
  20. #deny_access
  21. return nil
  22. end
  23. end
  24.  
  25. def deny_access
  26. @response.headers["WWW-Authenticate"] = "Basic realm=\"listasgems\""
  27. render :nothing=>true, :status=>401
  28. end
Add Comment
Please, Sign In to add comment