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

daycry / auth / 22527357078

28 Feb 2026 07:22PM UTC coverage: 63.267% (+0.7%) from 62.568%
22527357078

push

github

daycry
Remove PHP 8.1 from PHPUnit CI matrix

Update .github/workflows/phpunit.yml to drop PHP 8.1 from the test matrix. CI will now run PHPUnit only on PHP 8.2 and 8.3, reducing the matrix to current supported versions.

3064 of 4843 relevant lines covered (63.27%)

41.52 hits per line

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

0.0
/src/Controllers/RegisterController.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\Controllers;
15

16
use CodeIgniter\Events\Events;
17
use CodeIgniter\HTTP\RedirectResponse;
18
use CodeIgniter\HTTP\ResponseInterface;
19
use Daycry\Auth\Entities\User;
20
use Daycry\Auth\Exceptions\ValidationException;
21
use Daycry\Auth\Models\UserModel;
22
use Daycry\Auth\Validation\ValidationRules;
23

24
/**
25
 * Class RegisterController
26
 *
27
 * Handles displaying registration form,
28
 * and handling actual registration flow.
29
 */
30
class RegisterController extends BaseAuthController
31
{
32
    /**
33
     * Displays the registration form.
34
     */
35
    public function registerView(): ResponseInterface
×
36
    {
37
        // Check if already logged in
38
        if (($redirect = $this->redirectIfLoggedIn(config('Auth')->registerRedirect())) instanceof RedirectResponse) {
×
39
            return $redirect;
×
40
        }
41

42
        // Check if registration is allowed
43
        if (! setting('Auth.allowRegistration')) {
×
44
            return $this->handleError(
×
45
                $this->request->getUri()->getPath(),
×
46
                lang('Auth.registerDisabled'),
×
47
            );
×
48
        }
49

50
        // Check if there's a pending post-auth action
51
        if ($this->hasPostAuthAction()) {
×
52
            return $this->redirectToAuthAction();
×
53
        }
54

55
        $content = $this->view(setting('Auth.views')['register']);
×
56

57
        return $this->response->setBody($content);
×
58
    }
59

60
    /**
61
     * Attempts to register the user.
62
     */
63
    public function registerAction(): RedirectResponse
×
64
    {
65
        // Check if already logged in
66
        if (($redirect = $this->redirectIfLoggedIn(config('Auth')->registerRedirect())) instanceof RedirectResponse) {
×
67
            return $redirect;
×
68
        }
69

70
        // Check if registration is allowed
71
        if (! setting('Auth.allowRegistration')) {
×
72
            return $this->handleError(
×
73
                config('Auth')->registerRoute(),
×
74
                lang('Auth.registerDisabled'),
×
75
            );
×
76
        }
77

78
        // Validate input
79
        $rules    = $this->getValidationRules();
×
80
        $postData = $this->request->getPost();
×
81

82
        // Fire pre-register event before validation
83
        Events::trigger('pre-register', $postData);
×
84

85
        if (! $this->validateRequest($postData, $rules)) {
×
86
            return $this->handleValidationError(config('Auth')->registerRoute());
×
87
        }
88

89
        // Save the user
90
        $users             = $this->getUserProvider();
×
91
        $allowedPostFields = array_keys($rules);
×
92
        $user              = $this->getUserEntity();
×
93
        $user->fill($this->request->getPost($allowedPostFields));
×
94

95
        // Workaround for email only registration/login
96
        if ($user->username === null) {
×
97
            $user->username = null;
×
98
        }
99

100
        try {
101
            $users->save($user);
×
102
        } catch (ValidationException $e) {
×
103
            return $this->handleError(
×
104
                config('Auth')->registerRoute(),
×
105
                'Registration failed',
×
106
                true,
×
107
            )->with('errors', $users->errors());
×
108
        }
109

110
        // Get complete user object with ID
111
        $user = $users->findById($users->getInsertID());
×
112

113
        // Add to default group
114
        $users->addToDefaultGroup($user);
×
115

116
        Events::trigger('register', $user);
×
117

118
        // Start authentication process
119
        $authenticator = $this->getSessionAuthenticator();
×
120
        $authenticator->startLogin($user);
×
121

122
        // Check for post-registration action
123
        $hasAction = $authenticator->startUpAction('register', $user);
×
124
        if ($hasAction) {
×
125
            return $this->redirectToAuthAction();
×
126
        }
127

128
        // Set the user active and complete login
129
        $user->activate();
×
130
        $authenticator->completeLogin($user);
×
131

132
        return $this->handleSuccess(
×
133
            config('Auth')->registerRedirect(),
×
134
            lang('Auth.registerSuccess'),
×
135
        );
×
136
    }
137

138
    /**
139
     * Returns the User provider
140
     */
141
    protected function getUserProvider(): UserModel
×
142
    {
143
        $provider = model(setting('Auth.userProvider'));
×
144

145
        assert($provider instanceof UserModel, 'Config Auth.userProvider is not a valid UserProvider.');
×
146

147
        return $provider;
×
148
    }
149

150
    /**
151
     * Returns the Entity class that should be used
152
     */
153
    protected function getUserEntity(): User
×
154
    {
155
        return new User();
×
156
    }
157

158
    /**
159
     * Returns the rules that should be used for validation.
160
     *
161
     * @return         array<string, array<string, list<string>|string>>
162
     * @phpstan-return array<string, array<string, string|list<string>>>
163
     */
164
    protected function getValidationRules(): array
×
165
    {
166
        $rules = new ValidationRules();
×
167

168
        return $rules->getRegistrationRules();
×
169
    }
170
}
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