Created
May 20, 2013 14:17
-
-
Save joefiorini/5612528 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // How you could do what you want in Ember | |
| App.Router.map(function(){ | |
| this.resource("userSession", function(){ | |
| this.route("new", { path: "/sign-in" }); | |
| }) | |
| }); | |
| // However, any time you create a resource you have an extra layer of routing | |
| // & a model that you may/may not want. In the case of sign-in, which doesn't | |
| // really represent part of the UI, I'd consider just using a route instead. | |
| App.Router.map(function(){ | |
| this.route("signIn", { path: "/sign-in" }); | |
| }); | |
| // Then in your controller you can set the current session on ApplicationController | |
| App.SignInController = Ember.Controller.extend({ | |
| signIn: function(){ | |
| var session = UserSession.validate(this.get("username"), this.get("password")); // assuming you have some object with a session token or something | |
| this.controllers("application").set("session", sesssion); | |
| } | |
| }); |
Author
Author
Also, not sure if you saw this but this looks like an interesting approach:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the biggest reason you're having a hard time is that it's a security risk. There cannot be any chance the user can disable the auth check and start getting protected data. I'm sure you've already considered those implications though :)
You are correct on the purpose of
UserSession.validate. You have to be careful with cookies & ajax requests; I'm not sure how browsers handle cookies in ajax responses but I seem to remember it being a no-no in some; don't remember which. You could also just use document.cookies to set it manually in Javascript.