Two Models of Composing Actions
|
|
I’ve been working with authentication systems lately and I’m basically seeing actions composed in two different ways. Model A In Model A, a form posts back to the action that rendered it, and if the form post is successful then the action redirects elsewhere. For example, account creation in Acts As Authenticated is like this:
With this Psuedo Controller Code
As you can see, this action is very similar to what a Controller#new/Controller#create pair typically do, however the overall composition is using more of a “post back” technique. Additionally, other methods in AAA (login, change_password, etc.) follow this model as well. Model B In Model B, the flow of things is more RESTful.
With this Psuedo Controller Code:
As you see, is the more traditional Controller#new/Controller#create pair model. In my view, this is the evolving best practice because it’s more RESTful. All that said, a few questions as I’m trying to get my head around authentication, but the thoughts are broadly applicable:
Bottom line: I’m trying to get my head around the role of the Account Controller, and the relationship between the Account Controller and User Controller. Underlying that question is a) I can’t make up my mind if I should have both Account and User, or just User, b) if I have both, then which actions belong in each, and c) which composition model from above is the appropriate best practice. I hope I’ve expressed all that clearly…thoughts?? Scott |
|
|
It should be mentioned that restful_authentication is now somewhat preferred by most in the REST camp vs. AAA… looking at the code there may help clear up some confusion. On to your questions. Models != Resources. Models map to database tables. Resources are the… well, resources that your application provides to the outside world via HTTP. If you think of it that way, then the answer to your second question becomes clear. Login and logout (and it is implemented this way in restful_authentication) are simply the create and destroy methods on a “sessions” resource. Note that there is no session model, only a resource. Which is a perfect illustration of how resources do not necessarily have to map one-to-one to something in your database. As for stuff like change_password and forgot_password, it’s up to you whether you’d like to implement those RESTfully or decide that they’re just “oddball” actions that you want to stick on the end of some other controller. Example, you could do something like a ForgottenPasswordController and implement a new/create on that controller, or simply tack it onto the UsersController and be done with it. Hope this helps. |