• 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

89.29
/src/Commands/TotpCommand.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\UserModel;
18
use Daycry\Auth\Services\AuditLogger;
19
use Throwable;
20

21
/**
22
 * Admin CLI to manage a user's TOTP 2FA enrollment.
23
 *
24
 * Usage:
25
 *   php spark auth:totp reset -e user@example.com
26
 *   php spark auth:totp reset -i 42
27
 */
28
class TotpCommand extends BaseCommand
29
{
30
    protected $name        = 'auth:totp';
31
    protected $description = 'Admin TOTP management (reset).';
32
    protected $usage       = 'auth:totp reset -e <email> | -i <id>';
33

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

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

46
        if ($action !== 'reset') {
5✔
47
            $this->error('Unsupported action. Supported: reset.');
1✔
48

49
            return 1;
1✔
50
        }
51

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

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

58
            return 1;
1✔
59
        }
60

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

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

70
            return 1;
1✔
71
        }
72

73
        try {
74
            $user->disableTotp();
2✔
75

76
            (new AuditLogger())->record(
2✔
77
                AuditLogger::EVENT_TOTP_ADMIN_RESET,
2✔
78
                (int) $user->id,
2✔
79
                ['initiator' => 'cli'],
2✔
80
            );
2✔
81

82
            $this->write('TOTP reset for user ' . $user->id . '. Backup codes were also purged.', 'green');
2✔
83

84
            return 0;
2✔
85
        } catch (Throwable $e) {
×
NEW
86
            $this->error('TOTP reset failed: ' . $e->getMessage());
×
87

88
            return 1;
×
89
        }
90
    }
91
}
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