我在滑轨潜水时遇到以下问题。
所有请求和响应都是 JSON
登录/partners/sign_in后,我收到以下回复:
HTTP/1.1 200 OK {"成功":true}
在我退出/partners/sign_out后,我得到以下回复:
HTTP/1.1 200 OK {"成功":true}
现在我的问题:如何创建自己的 RegisterController 以及它的外观,有没有示例?我在 github/devise 上进行了搜索,但没有找到任何示例。
我想响应其他内容,如果身份验证失败,我想响应 HTTP 404 ERROR
路线.rb
devise_for :partners, :controllers => { :sessions => "sessions" }
session_controller.rb
class SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
return sign_in_and_redirect(resource_name, resource)
end
def destroy
redirect_path = after_sign_out_path_for(resource_name)
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
set_flash_message :notice, :signed_out if signed_out
respond_to do |format|
format.html { redirect_to redirect_path }
format.json { render :json => {:success => true} }
end
end
private
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
return render :json => {:success => true}
end
def failure
return render:json => {:success => false, :errors => ["Login failed."]}
end
end