开发者

authenticate user using devise in custom controller

开发者 https://www.devze.com 2023-02-20 05:17 出处:网络
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 passwo

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消