Rails devise 自定义登录问题

tsinghan · December 30, 2013 · Last by TsingHan replied at December 30, 2013 · 3517 hits

我覆盖了 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

http://stackoverflow.com/questions/6004216/devise-forbid-certain-user-from-signing-in

# disabled account
def active_for_authentication?
  super and self.is_active
end
You need to Sign in before reply, if you don't have an account, please Sign up first.