• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / auth / 25552752016

08 May 2026 11:20AM UTC coverage: 71.592% (+13.0%) from 58.608%
25552752016

push

github

web-flow
Merge pull request #48 from daycry/development

Add Laravel-parity authentication features: Gates, Password Confirmation, Basic Auth

198 of 252 new or added lines in 18 files covered. (78.57%)

1 existing line in 1 file now uncovered.

4453 of 6220 relevant lines covered (71.59%)

62.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/Commands/SessionsCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Auth.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Auth\Commands;
15

16
use CodeIgniter\CLI\CLI;
17
use Daycry\Auth\Models\DeviceSessionModel;
18
use Daycry\Auth\Models\UserModel;
19
use Throwable;
20

21
/**
22
 * Admin CLI to terminate a user's active device sessions.
23
 *
24
 * Usage:
25
 *   php spark auth:sessions terminate -e user@example.com
26
 *   php spark auth:sessions terminate -i 42
27
 */
28
class SessionsCommand extends BaseCommand
29
{
30
    protected $name        = 'auth:sessions';
31
    protected $description = 'Terminate active device sessions for a user.';
32
    protected $usage       = 'auth:sessions terminate -e <email> | -i <id>';
33

34
    /**
35
     * Command's Options
36
     *
37
     * @var array<string, string>
38
     */
39
    protected $options = [
40
        '-e' => 'Target user email.',
41
        '-i' => 'Target user id.',
42
    ];
43

44
    public function run(array $params): int
5✔
45
    {
46
        $action = $params[0] ?? '';
5✔
47

48
        if ($action !== 'terminate') {
5✔
49
            $this->error('Unsupported action. Supported: terminate.');
1✔
50

51
            return 1;
1✔
52
        }
53

54
        $email = (string) ($params['e'] ?? '');
4✔
55
        $id    = (string) ($params['i'] ?? '');
4✔
56

57
        if ($email === '' && $id === '') {
4✔
58
            $this->error('Specify -e <email> or -i <id>.');
1✔
59

60
            return 1;
1✔
61
        }
62

63
        /** @var UserModel $userModel */
64
        $userModel = model(UserModel::class);
3✔
65
        $user      = $id !== ''
3✔
66
            ? $userModel->findById((int) $id)
1✔
67
            : $userModel->findByCredentials(['email' => $email]);
2✔
68

69
        if ($user === null) {
3✔
70
            $this->error('User not found.');
1✔
71

72
            return 1;
1✔
73
        }
74

75
        try {
76
            /** @var DeviceSessionModel $deviceModel */
77
            $deviceModel = model(DeviceSessionModel::class);
2✔
78
            $deviceModel->terminateAllForUser($user);
2✔
79

80
            $this->write('Terminated all device sessions for user ' . $user->id, 'green');
2✔
81

82
            return 0;
2✔
83
        } catch (Throwable $e) {
×
NEW
84
            $this->error('Session termination failed: ' . $e->getMessage());
×
85

86
            return 1;
×
87
        }
88
    }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc