Guest User

Untitled

a guest
Jun 5th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. ## qresource.rb
  2.  
  3.  
  4.  
  5. module Qresource
  6. def get_parser(xml_str) # {{{
  7. begin
  8. p = XML::Parser.new
  9. p.string = xml_str
  10. p.parse
  11. rescue
  12. # TODO raise exception here!
  13. nil
  14. end
  15. end # }}}
  16. end
  17.  
  18. ## dt_user.rb
  19.  
  20. def self.authenticate(login = '', password = '', api_url = '') # {{{
  21. rc = RestClient::Resource.new(
  22. api_url,
  23. :user => APP_CONFIG[:api][:backoffice][:user],
  24. :password => APP_CONFIG[:api][:backoffice][:password]
  25. )
  26. url = "/users/validate.xml?login=#{login}&password=#{password}"
  27. begin
  28. response = rc[url].get
  29. doc = get_parser( response )
  30. valid_password = doc.find_first('valid_password')
  31. if valid_password.content == 'yes'
  32. logger.debug "found valid password hurray!"
  33. return DtUser.new :login => login, :password => password, :api_url => api_url
  34. else
  35. logger.warn "valid_password #{valid_password.content}"
  36. return false
  37. end
  38. rescue
  39. logger.error "call/parsing failed with #{$!}"
  40. return false
  41. end
  42. logger.error "unable to login with #{login}/#{password} @ #{api_url}"
  43. return false
  44. end
  45. end
  46.  
  47. ## explain.txt
  48. results in "unkown method get_parser"
  49.  
  50. the dt_user is somewhat different from the rest of the qresource's since it needs a super-custom call to validate password.
  51.  
  52. regular qresource objects are not used as singletons...
Add Comment
Please, Sign In to add comment