无法使用重写的Devise SessionControl签名

时间:2017-02-14 22:09:37

标签: ruby-on-rails devise ruby-on-rails-5 rails-api

我正在使用Rails 5应用程序(仅限api),我使用Devise作为User模型,并在mobile/auth/users处覆盖控件。我只能使用每个控制器的少数操作,例如我sign_up可以通过cURL,但我不能sign_in,我不知道为什么。这里有例子:

控制器:sessions: 'mobile/auth/users/sessions'

覆盖范例:

def create
    super
end

请求:

curl -H 'Content-Type: application/json' -X POST http://api.test.com:3000/mobile/users/sign_in -d '{"user" : { "email" : "user@example.com", "password" : "1234567890"}}'

错误:401 Unauthorized

身体:{"error":"You need to sign in or sign up before continuing."}

我试图签名并且我已经注册了正确的确认信息,为什么控制器会覆盖什么无效?在正常的应用程序中,视图一切顺利。

谢谢!

编辑:完整控制器

 class Mobile::Auth::Users::SessionsController < Devise::SessionsController

   # GET /resource/sign_in
   # def new
   #   super
   # end

   # POST /resource/sign_in
   def create
       super
   end

   # DELETE /resource/sign_out
   def destroy
     super
   end

   protected

   # If you have extra params to permit, append them to the sanitizer.
   def configure_sign_in_params
    devise_parameter_sanitizer.permit(:sign_in, keys: [:email])
    devise_parameter_sanitizer.permit(:sign_in, keys: [:password])
   end

   def serialize_options(resource)
     super
   end

   def auth_options
     super
   end

   def translation_scope
     super
   end

   private

   # Check if there is no signed in user before doing the sign out.
   #
   # If there is no signed in user, it will set the flash message and redirect
   # to the after_sign_out path.
   def verify_signed_out_user
     super
   end

   def all_signed_out?
     super
   end

   def respond_to_on_destroy
     super
   end
 end

编辑v2

好的,问题是我可以通过DEVISE 登录VIA CURL。即使我将Cookie与-b cookie_name放在一起,我也总是401 Status Code。默认设计使用cookie来处理&#34; session&#34; (服务器端没有)。如何使用session在服务器端迁移设计行为?我应该编写自己的代码还是可以通过设计来改变行为?

0 个答案:

没有答案