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

daycry / auth / 25518434194

07 May 2026 07:49PM UTC coverage: 58.608% (-6.4%) from 64.989%
25518434194

push

github

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

Implement security enhancements and new account features

277 of 1030 new or added lines in 55 files covered. (26.89%)

11 existing lines in 6 files now uncovered.

3544 of 6047 relevant lines covered (58.61%)

47.97 hits per line

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

0.0
/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

NEW
44
    public function run(array $params): int
×
45
    {
NEW
46
        $action = array_shift($params) ?? '';
×
47

NEW
48
        if ($action !== 'terminate') {
×
NEW
49
            CLI::error('Unsupported action. Supported: terminate.');
×
50

NEW
51
            return 1;
×
52
        }
53

NEW
54
        $email = (string) (CLI::getOption('e') ?? '');
×
NEW
55
        $id    = (string) (CLI::getOption('i') ?? '');
×
56

NEW
57
        if ($email === '' && $id === '') {
×
NEW
58
            CLI::error('Specify -e <email> or -i <id>.');
×
59

NEW
60
            return 1;
×
61
        }
62

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

NEW
69
        if ($user === null) {
×
NEW
70
            CLI::error('User not found.');
×
71

NEW
72
            return 1;
×
73
        }
74

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

NEW
80
            CLI::write('Terminated all device sessions for user ' . $user->id, 'green');
×
81

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

NEW
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