authenticate user using devise in custom controller
I'm using rails 3 and devise and I would like to have a SecurityController where I call methods like sign_in_user or reset_password which will be a post passing in parameters like username and password to it.
I know I could use before_filter :authenticate_user! but I would like to authenticate myself. If the authentication is successful then I would like for that user to sign_in.
Reason I do this is because I have an iphone app which depends on开发者_JS百科 authenticating to the web app to use the app.
I haven't had reason to do this myself yet, but if you read the "Configuring Controllers" section at https://github.com/plataformatec/devise, it show how you can create a custom controller that extends Devise::SessionsController
, and then point your authentication routing to that controller. I think that is what you are asking how to do -- correct?
To quote from the page...
If the customization at the views level is not enough, you can customize each controller by following these steps:
1) Create your custom controller, for example a Admins::SessionsController:
class Admins::SessionsController < Devise::SessionsController
end
2) Tell the router to use this controller:
devise_for :admins, :controllers => { :sessions => "admins/sessions" }
3) And since we changed the controller, it won’t use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
精彩评论