mardi 24 mai 2016

PHP Laravel : How to logout from other device with same userId forcefully

I'm building a laravel application where A user logged in other device and While logged out I want to force him to logged out from other device also. How do I implement in laravel.

Personally I have used Redis Server for that.But I don't know why It's not working. While running the program I have run redis-server.exe also.And I'm in Windows. And Here is my Controller where I have written the login for forcing the user from logged out from other device. If anyone find any solution please help me to find it out.Thanks In Advance.

Controller:

 public function postSignIn(Request $request)
    {       

       if (Auth::attempt(['email' => $request['email'], 'password' =>$request['password'] ]) ) {

       $redis = \Redis::connection();   
       $userId=Auth::user()->id;
        $redis->sadd('users:sessions:'.$userId,Session::getId());
          return redirect()->route('main');

        }
        return redirect()->back();
    }

 public function getLogout()
    {
        $redis = \Redis::connection();
        $userId=Auth::user()->id;
        $userSessions = $redis->smembers('user:sessions:' . $userId);
        $currentSession = Session::getId();
        foreach ($userSessions as $sessionId) {
             if ($currentSession == $sessionId) {
          continue; 
                }
                 $redis->srem('user:sessions:' . $userId, $sessionId);
                $redis->del('localhost:' . $sessionId);

            }
        Auth::logout();
        return redirect()->route('main');
    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TDl8rp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire