我想使用Devise的控制器辅助方法signed_in?检查用户是否已经签名,如果是的话我想重定向到一个特定的页面。设计如何添加登录检查自定义会话控制器?
我试过这个,但signed_in?方法总是返回true,我该如何做这个工作?
class SessionsController < Devise::SessionsController
def new
redirect_to root_url
end
def create
if signed_in?(resource_name)
redirect_to where_-_want_to_url
else
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
return sign_in_and_redirect(resource_name, resource)
end
end
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, :redirect => stored_location_for(scope) || after_sign_in_path_for(resource)}
end
def failure
return render :json => { :success => false }
end
end
你想用这个做什么?你只是想显示一个不同的**主页**取决于用户是否登录? – Ashitaka 2012-03-23 20:22:46
不,有一种情况是登录页面被删除,但实际上用户已经登录。所以我想做服装重定向 – Rn2dy 2012-03-23 20:24:00