Implement login/logout
[blerg.git] / www / jssrc / blerg / Blerg.js
index 080e644..2a571a8 100644 (file)
@@ -5,19 +5,24 @@ enyo.kind({
        handlers: {
                onStartSignup: "showSignupDialog",
                onTryLogin: "tryLogin",
+               onTryLogout: "tryLogout",
                onSetTitle: "setTitle"
        },
        components: [
                {classes: "blerg-header", components: [
-                       {kind: "blerg.Title"},
-                       {kind: "blerg.Controls"},
+                       {name: "title", kind: "blerg.Title"},
+                       {name: "controls", kind: "blerg.Controls"},
                        {style: "clear: both"},
                        {name: "post", kind: "blerg.Post", showing: false},
                        {name: "help", kind: "blerg.Help"}
                ]},
                {name: "main", kind: "blerg.Main"},
                {name: "signupDialog", kind: "blerg.SignupDialog"},
-               {name: "passwdDialog", kind: "blerg.PasswdDialog"}
+               {name: "passwdDialog", kind: "blerg.PasswdDialog"},
+               {name: "api", kind: "blerg.API",
+                onLoginSuccessful: "loginSuccessful",
+                onLoginFailed: "loginFailed",
+                onLogoutSuccessful: "logout"}
        ],
        urlmap: [
                ['search', /^\?post\/([^/]+)\/(.+)/, "blerg.ExternalURLPost"],
@@ -78,5 +83,24 @@ enyo.kind({
                        this.$.title.hideControls();
        },
        tryLogin: function(inSender, inEvent) {
+               this.$.api.login(inEvent.username, inEvent.password);
+       },
+       tryLogout: function(inSender, inEvent) {
+               this.$.api.logout();
+       },
+       loginSuccessful: function(inSender, inEvent) {
+               this.$.api.requestFeedStatus();
+               this.feedStatusUpdateInterval = setInterval(function() {
+                       this.$.api.requestFeedStatus();
+               }.bind(this), 900000);
+               this.waterfall('onLogin', inEvent);
+       },
+       loginFailed: function(inSender, inEvent) {
+               alert('Login failed');
+               this.logout();
+       },
+       logout: function(inSender, inEvent) {
+               clearInterval(this.feedStatusUpdateInterval);
+               this.waterfall('onLogout');
        }
 });