Advertisement
Guest User

Untitled

a guest
Oct 6th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1.  
  2. #import('dart:html');
  3.  
  4. void main() {
  5. Torn t = new Torn("Plornt","mahpassword");
  6. t.login(() { print("Yay logged in!"); },(String error) { print(error); });
  7. }
  8.  
  9. class Torn {
  10. String username, _password, _pwordHash, userID;
  11. Torn (String this.username, String this._password) {
  12.  
  13. }
  14.  
  15. Document requestData (String url, [String postVars, bool pauseApp = false, onSuccess(Document ht)]) {
  16. HttpRequest html = new HttpRequest();
  17. html.open((postVars == null ? 'GET' : 'POST'), url, async: !pauseApp);
  18.  
  19. html.send(postVars);
  20. if (pauseApp == true) { return html.responseXML; }
  21. else { html.on.readyStateChange.add((Event e) {
  22. if (html.readyState == HttpRequest.DONE && (html.status == 200 || html.status == 0)) {
  23. try {
  24.  
  25. DOMParser d = new DOMParser();
  26. onSuccess(d.parseFromString(html.responseText,"text/html"));
  27. }
  28. catch (e) {
  29. print("Error on requestData($url) async = $pauseApp - $e");
  30. }
  31. }
  32. });
  33. }
  34. }
  35. void login (onSuccess(),onError(String error)) {
  36. this.requestData("http://www.torn.com/authenticate.php", postVars: "player=${username}&password=${_password}", onSuccess: (Document ht) {
  37. if (ht.query("Title") == "TORN Homepage") {
  38. onSuccess();
  39. }
  40. else onError("Username or password incorrect");
  41. });
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement