Finish user signup
[blerg.git] / www / jssrc / blerg / API.js
index 203706a..a5aa965 100644 (file)
@@ -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({
+            username: username,
+            password: password,
+        });
+    },
     login: function(username, password) {
         var req = new enyo.Ajax({
             url: baseURL + '/login',
@@ -88,6 +108,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) {