Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import('dart:html');
- void main() {
- Torn t = new Torn("Plornt","mahpassword");
- t.login(() { print("Yay logged in!"); },(String error) { print(error); });
- }
- class Torn {
- String username, _password, _pwordHash, userID;
- Torn (String this.username, String this._password) {
- }
- Document requestData (String url, [String postVars, bool pauseApp = false, onSuccess(Document ht)]) {
- HttpRequest html = new HttpRequest();
- html.open((postVars == null ? 'GET' : 'POST'), url, async: !pauseApp);
- html.send(postVars);
- if (pauseApp == true) { return html.responseXML; }
- else { html.on.readyStateChange.add((Event e) {
- if (html.readyState == HttpRequest.DONE && (html.status == 200 || html.status == 0)) {
- try {
- DOMParser d = new DOMParser();
- onSuccess(d.parseFromString(html.responseText,"text/html"));
- }
- catch (e) {
- print("Error on requestData($url) async = $pauseApp - $e");
- }
- }
- });
- }
- }
- void login (onSuccess(),onError(String error)) {
- this.requestData("http://www.torn.com/authenticate.php", postVars: "player=${username}&password=${_password}", onSuccess: (Document ht) {
- if (ht.query("Title") == "TORN Homepage") {
- onSuccess();
- }
- else onError("Username or password incorrect");
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement