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

daycry / auth / 21031260116

15 Jan 2026 11:02AM UTC coverage: 66.786% (+0.2%) from 66.555%
21031260116

push

github

daycry
Refactor Auth config for improved organization

Reorganized the Auth configuration file by grouping related settings into logical sections such as logging, rate limiting, authentication, user/registration, password/security, OAuth, views/URLs, and discovery/cron. This improves readability and maintainability without changing any functional behavior.

2246 of 3363 relevant lines covered (66.79%)

33.3 hits per line

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

0.0
/src/Controllers/BaseAuthController.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 App\Controllers\BaseController;
17
use CodeIgniter\HTTP\RedirectResponse;
18
use Daycry\Auth\Authentication\Authenticators\Session;
19
use Daycry\Auth\Interfaces\AuthController;
20
use Daycry\Auth\Result;
21
use Daycry\Auth\Traits\BaseControllerTrait;
22
use Daycry\Auth\Traits\Viewable;
23

24
/**
25
 * Base Auth Controller that provides common functionality for all auth controllers
26
 *
27
 * Uses BaseControllerTrait for core functionality and implements
28
 * common patterns used across auth controllers.
29
 */
30
abstract class BaseAuthController extends BaseController implements AuthController
31
{
32
    use BaseControllerTrait;
33
    use Viewable;
34

35
    /**
36
     * Get CSRF token array for forms
37
     */
38
    protected function getTokenArray(): array
39
    {
40
        return $this->getToken();
×
41
    }
42

43
    /**
44
     * Check if user is already logged in and redirect if needed
45
     */
46
    protected function redirectIfLoggedIn(?string $redirectUrl = null): ?RedirectResponse
47
    {
48
        if (auth()->loggedIn()) {
×
49
            $url = $redirectUrl ?? config('Auth')->loginRedirect();
×
50

51
            return redirect()->to($url);
×
52
        }
53

54
        return null;
×
55
    }
56

57
    /**
58
     * Get validation rules for the specific controller
59
     * Must be implemented by child classes
60
     */
61
    abstract protected function getValidationRules(): array;
62

63
    /**
64
     * Validate request data with given rules
65
     */
66
    protected function validateRequest(array $data, array $rules): bool
67
    {
68
        return $this->validateData($data, $rules, [], config('Auth')->DBGroup);
×
69
    }
70

71
    /**
72
     * Handle validation errors with redirect
73
     */
74
    protected function handleValidationError(?string $route = null): RedirectResponse
75
    {
76
        $route ??= $this->request->getUri()->getPath();
×
77

78
        return redirect()->to($route)
×
79
            ->withInput()
×
80
            ->with('errors', $this->validator->getErrors());
×
81
    }
82

83
    /**
84
     * Handle successful action with redirect
85
     */
86
    protected function handleSuccess(string $redirectUrl, ?string $message = null): RedirectResponse
87
    {
88
        $redirect = redirect()->to($redirectUrl);
×
89

90
        if ($message) {
×
91
            $redirect = $redirect->with('message', $message);
×
92
        }
93

94
        return $redirect;
×
95
    }
96

97
    /**
98
     * Handle error with redirect
99
     */
100
    protected function handleError(string $route, string $error, bool $withInput = true): RedirectResponse
101
    {
102
        $redirect = redirect()->to($route);
×
103

104
        if ($withInput) {
×
105
            $redirect = $redirect->withInput();
×
106
        }
107

108
        return $redirect->with('error', $error);
×
109
    }
110

111
    /**
112
     * Get current session authenticator
113
     */
114
    protected function getSessionAuthenticator(): Session
115
    {
116
        return auth('session')->getAuthenticator();
×
117
    }
118

119
    /**
120
     * Check if current request has post-authentication action
121
     */
122
    protected function hasPostAuthAction(): bool
123
    {
124
        return $this->getSessionAuthenticator()->hasAction();
×
125
    }
126

127
    /**
128
     * Redirect to auth action if one exists
129
     */
130
    protected function redirectToAuthAction(): RedirectResponse
131
    {
132
        return redirect()->route('auth-action-show')->withCookies();
×
133
    }
134

135
    /**
136
     * Extract credentials from POST data for login
137
     */
138
    protected function extractLoginCredentials(): array
139
    {
140
        $credentials             = $this->request->getPost(setting('Auth.validFields')) ?? [];
×
141
        $credentials             = array_filter($credentials);
×
142
        $credentials['password'] = $this->request->getPost('password');
×
143

144
        return $credentials;
×
145
    }
146

147
    /**
148
     * Check if remember me is requested
149
     */
150
    protected function shouldRememberUser(): bool
151
    {
152
        return (bool) $this->request->getPost('remember');
×
153
    }
154

155
    /**
156
     * Handle authentication result
157
     */
158
    protected function handleAuthResult(Result $result, string $failureRoute): RedirectResponse
159
    {
160
        if (! $result->isOK()) {
×
161
            return $this->handleError($failureRoute, $result->reason());
×
162
        }
163

164
        // Handle post-authentication action if exists
165
        if ($this->hasPostAuthAction()) {
×
166
            return $this->redirectToAuthAction();
×
167
        }
168

169
        // Redirect to success page
170
        return $this->handleSuccess(
×
171
            config('Auth')->loginRedirect(),
×
172
        )->withCookies();
×
173
    }
174
}
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