X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=sidebyside;f=www%2Fjssrc%2Fblerg%2FAPI.js;h=95cdbcdd940689917fb6bcbe8d90b82f8ba32253;hb=782bdd9400ccdef901463f1bb5788c31275cd007;hp=203706a674da60477844ccca4312302ecb89885d;hpb=04a4fdf9d85e0d0b193300abe0c0e433449cd285;p=blerg.git diff --git a/www/jssrc/blerg/API.js b/www/jssrc/blerg/API.js index 203706a..95cdbcd 100644 --- a/www/jssrc/blerg/API.js +++ b/www/jssrc/blerg/API.js @@ -32,6 +32,26 @@ enyo.kind({ blerg.API.apiInitialized = true; }, + signup: function(username, password) { + var req = new enyo.Ajax({ + url: baseURL + '/create', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + if (inResponse.status == 'success') { + this.bubble('onSignupSuccess', {username: username}); + } else { + this.bubble('onSignupFailure', {username: username}); + } + }.bind(this)); + req.error(function() { + this.bubble('onSignupFailure', {username: username}); + }.bind(this)); + req.go(enyo.Ajax.objectToQuery({ + username: username, + password: password, + })); + }, login: function(username, password) { var req = new enyo.Ajax({ url: baseURL + '/login', @@ -48,10 +68,10 @@ enyo.kind({ this.bubble('onLoginFailed'); } }.bind(this)); - req.go({ + req.go(enyo.Ajax.objectToQuery({ username: username, password: password - }); + })); }, logout: function() { var req = new enyo.Ajax({ @@ -63,11 +83,29 @@ enyo.kind({ enyo.setCookie('auth', '', {"Max-Age": 0}); this.bubble('onLogoutSuccessful'); }.bind(this)); - req.go({ + req.go(enyo.Ajax.objectToQuery({ username: blerg.API.username - }); + })); enyo.setCookie('username', '', {"Max-Age": 0}); }, + changePassword: function(oldpassword, newpassword) { + var req = new enyo.Ajax({ + url: baseURL + '/passwd', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + if (inResponse.status == 'success') { + this.bubble('onPasswordChangeSuccessful'); + } else { + this.bubble('onPasswordChangeFailed'); + } + }.bind(this)); + req.go(enyo.Ajax.objectToQuery({ + username: blerg.API.username, + password: oldpassword, + new_password: newpassword + })); + }, loadUserRecords: function(username, from ,to) { var url; if (from != undefined && to != undefined) { @@ -88,6 +126,12 @@ enyo.kind({ entries: inResponse }); }.bind(this)); + req.error(function(inSender, inResponse) { + if (inResponse == 404) + this.bubble('onUserNotFound'); + else + this.bubble('onAPIError', {response: inResponse}); + }.bind(this)); req.go(); }, loadTagRecords: function(type, tag) { @@ -129,9 +173,9 @@ enyo.kind({ req.response(function(inSender, inResponse) { this.bubble('onFeedInfo', inResponse); }.bind(this)); - req.go({ + req.go(enyo.Ajax.objectToQuery({ username: blerg.API.username - }); + })); }, loadFeed: function() { if (!blerg.API.loggedIn) @@ -147,9 +191,9 @@ enyo.kind({ entries: inResponse }); }.bind(this)); - req.go({ + req.go(enyo.Ajax.objectToQuery({ username: blerg.API.username - }); + })); }, getSubscriptionStatus: function(username) { var req = new enyo.Ajax({ @@ -162,9 +206,9 @@ enyo.kind({ subscribed: inResponse.subscribed }); }.bind(this)); - req.go({ + req.go(enyo.Ajax.objectToQuery({ username: blerg.API.username - }); + })); }, subscribe: function(username) { var req = new enyo.Ajax({ @@ -177,9 +221,9 @@ enyo.kind({ subscribed: inResponse.status == "success" }); }.bind(this)); - req.go({ + req.go(enyo.Ajax.objectToQuery({ username: blerg.API.username - }); + })); }, unsubscribe: function(username) { var req = new enyo.Ajax({ @@ -192,8 +236,31 @@ enyo.kind({ subscribed: inResponse.status != "success" }); }.bind(this)); - req.go({ + req.go(enyo.Ajax.objectToQuery({ username: blerg.API.username - }); + })); }, + post: function(data) { + var req = new enyo.Ajax({ + url: baseURL + '/put', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + if (inResponse && inResponse.status == 'success') { + this.bubble('onPostSuccessful', { + username: blerg.API.username, + data: data + }); + } else { + this.bubble('onPostFailed', { + username: blerg.API.username, + data: data + }); + } + }.bind(this)); + req.go(enyo.Ajax.objectToQuery({ + username: blerg.API.username, + data: data + })); + } });