dqbjvg2518 2015-07-25 14:00
浏览 36

如何通过记忆令牌禁用用户登录?

Laravel allows authenticating users with a remember_token stored in cookie.

In my user table I have an active column which is a boolean (1, 0).

If for example a user is fired, you need to disable his ability to login; so you change the active value to 0.

But what you are going to do with his cookies?

NOTICE! I've written this in a very primitive way! The question is how properly handle such situations.

  • 写回答

2条回答 默认 最新

  • douqian2957 2015-07-25 14:56
    关注

    As you have no way to remove remember cookie, you need to implement a check in your application that would make sure that all users that log in have active status.

    One way you could do this is to implement a listener for auth.login event and check the status there.

    class CheckUserStatusHandler {
      public function handle($user) {
        if (!$user->active) Auth::logout($user);
      }
    }
    

    Logout method will logout user and remove remember token.

    Then register the listener in your EventServiceProvider:

    protected $listen = [
      'auth.login' => [
            CheckUserStatusHandler::class
        ]
    ];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程