Created
April 24, 2014 20:49
-
-
Save mauritslamers/11269026 to your computer and use it in GitHub Desktop.
auth check statechart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myApp.statechart = SC.Statechart.create({ | |
rootState: SC.State.design({ | |
initialSubstate: 'CHECKAUTH', | |
CHECKAUTH: SC.State.design({ | |
enterState: function () { | |
SC.Request.getUrl('/auth/is-authenticated').notify(this, '_authcheckDidRespond').send(); | |
}, | |
_authcheckDidRespond: function (result) { | |
if (SC.ok(result)) { | |
// let's assume that the auth is ok here | |
this.gotoState('HASAUTH'); | |
} | |
else { | |
this.gotoState('HASNOAUTH'); | |
} | |
} | |
}), | |
HASAUTH: SC.State.design({ | |
enterState: function () { | |
// continue into the app | |
} | |
}), | |
HASNOAUTH: SC.State.design({ | |
enterState: function () { | |
// show some login screen... | |
} | |
}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment