ruby-on-rails – 自定义设备会话控制器在错误时不重定向(:reca
发布时间:2020-12-17 02:18:54 所属栏目:百科 来源:网络整理
导读:我重写了设备会话控制器…它的工作原理(我可以用json登录),但我无法让它重定向到错误的另一个动作: class Users::SessionsController Devise::SessionsController def create resource = warden.authenticate!(:scope = resource_name,:recall = "#{control
我重写了设备会话控制器…它的工作原理(我可以用json登录),但我无法让它重定向到错误的另一个动作:
class Users::SessionsController < Devise::SessionsController def create resource = warden.authenticate!(:scope => resource_name,:recall => "#{controller_path}#no") return invalid_login_attempt unless resource sign_in(resource_name,resource) #respond_with resource,:location => redirect_location(resource_name,resource) respond_to do |format| format.json { render :status => 200,:json => { :success => true,:auth_token => resource.authentication_token,:user => resource } } end end def no puts "NO!" return render:json => {:success => false,:errors => alert} end end 我也尝试过: if resource.nil? puts "NIL!" end 我总是得到相同的默认Devise json错误以响应错误的sign_in凭据: {error: "You need to sign in or sign up before continuing."} 我究竟做错了什么? 解决方法
请记住,如果warden没有让用户通过身份验证!动作它会向失败应用程序抛出一个符号.因此,在失败的情况下,该行之后的任何内容都无关紧要.
更改身份验证!要进行身份验证,它将返回用户对象,供您根据需要进行处理. 检查warden gem中的proxy.rb文件以获取更多详细信息. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |