开发者

ROR user authentication

In my web app after a user logs in a new session is created so until he closes the browser he stays logged in. The problem appears when admin wants to ban the user who's browser is still open. Even though the user is banned and cannot log in anymore, he still stays logged in until he closes the browser or manually logs out. Th开发者_如何学编程is definitely should be fixed.

Is it possible to add a verifying method to every action of every controller? Of course I mean a smart way - not copy/paste 100 times.


add the following to your application controller:

before_filter :sign_out_banned_user

def sign_out_banned_user
  if current_user.banned?
    session[:current_user_id] = nil
    redirect_to root_path, :notice => "You are banned"
    return false
  end
end


You must reset the session also i think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜