我覆盖了 devise session 的 create 方法,判断当用户被禁用时,无法登录,我的代码如下:
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
if resource.is_deleted?
render :new
else
sign_in(resource_name, resource)
redirect_to after_sign_in_path_for(resource)
end
end
但是感觉不对,我看了一下 ruby-china 的代码如下:但是我没看到是如何处理的,谁帮忙解释一下
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
resource.ensure_private_token!
respond_to do |format|
format.html { redirect_to after_sign_in_path_for(resource) }
format.json { render :status => '201', :json => resource.as_json(:only => [:login, :email, :private_token]) }
end
end