1 | <?php |
||
2 | /** |
||
3 | * Created by PhpStorm. |
||
4 | * User: sheldon |
||
5 | * Date: 18-5-3 |
||
6 | * Time: 下午6:14. |
||
7 | */ |
||
8 | |||
9 | namespace Yeelight\Listeners\Auth; |
||
10 | |||
11 | use Carbon\Carbon; |
||
12 | use Illuminate\Queue\SerializesModels; |
||
13 | use Laravel\Passport\Events\AccessTokenCreated; |
||
14 | use Laravel\Passport\Token; |
||
15 | |||
16 | /** |
||
17 | * Class RevokeOldTokens |
||
18 | * |
||
19 | * @category Yeelight |
||
20 | * |
||
21 | * @package Yeelight\Listeners\Auth |
||
22 | * |
||
23 | * @author Sheldon Lee <[email protected]> |
||
24 | * |
||
25 | * @license https://opensource.org/licenses/MIT MIT |
||
26 | * |
||
27 | * @link https://www.yeelight.com |
||
28 | */ |
||
29 | class RevokeOldTokens |
||
30 | { |
||
31 | use SerializesModels; |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
32 | |||
33 | /** |
||
34 | * Handle the event. |
||
35 | * |
||
36 | * @param AccessTokenCreated $event AccessTokenCreated |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | public function handle(AccessTokenCreated $event) |
||
41 | { |
||
42 | Token::where('id', '!=', $event->tokenId) |
||
43 | ->where('user_id', $event->userId) |
||
44 | ->where('client_id', $event->clientId) |
||
45 | ->where('expires_at', '<', Carbon::now()) |
||
46 | ->orWhere('revoked', true) |
||
47 | ->delete(); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Get the channels the event should be broadcast on. |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | public function broadcastOn() |
||
56 | { |
||
57 | return []; |
||
58 | } |
||
59 | } |
||
60 |