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

daycry / auth / 22527658769

28 Feb 2026 07:41PM UTC coverage: 63.267% (-3.6%) from 66.864%
22527658769

push

github

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

Implement TOTP 2FA, JWT auth, device session tracking, and docs overhaul

465 of 1168 new or added lines in 52 files covered. (39.81%)

129 existing lines in 46 files now uncovered.

3064 of 4843 relevant lines covered (63.27%)

41.53 hits per line

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

0.0
/src/Controllers/LoginController.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\Validation\ValidationRules;
20

21
class LoginController extends BaseAuthController
22
{
23
    /**
24
     * Displays the form the login to the site.
25
     */
UNCOV
26
    public function loginView(): ResponseInterface
×
27
    {
28
        // Check if already logged in
29
        if (($redirect = $this->redirectIfLoggedIn()) instanceof RedirectResponse) {
×
30
            return $redirect;
×
31
        }
32

33
        // Check if there's a pending post-auth action
34
        if ($this->hasPostAuthAction()) {
×
35
            return $this->redirectToAuthAction();
×
36
        }
37

38
        $content = $this->view(setting('Auth.views')['login']);
×
39

40
        return $this->response->setBody($content);
×
41
    }
42

43
    /**
44
     * Attempts to log the user in.
45
     */
UNCOV
46
    public function loginAction(): RedirectResponse
×
47
    {
48
        // Validate input
49
        $rules    = $this->getValidationRules();
×
50
        $postData = $this->request->getPost();
×
51

52
        if (! $this->validateRequest($postData, $rules)) {
×
53
            return $this->handleValidationError(config('Auth')->loginRoute());
×
54
        }
55

56
        // Extract credentials and remember preference
57
        $credentials = $this->extractLoginCredentials();
×
58
        $remember    = $this->shouldRememberUser();
×
59

60
        // Fire pre-login event (listeners can cancel or enrich credentials)
NEW
61
        Events::trigger('pre-login', $credentials);
×
62

63
        // Attempt authentication
64
        $authenticator = $this->getSessionAuthenticator();
×
65
        $result        = $authenticator->remember($remember)->attempt($credentials);
×
66

67
        return $this->handleAuthResult($result, config('Auth')->loginRoute());
×
68
    }
69

70
    /**
71
     * Returns the rules that should be used for validation.
72
     *
73
     * @return         array<string, array<string, list<string>|string>>
74
     * @phpstan-return array<string, array<string, string|list<string>>>
75
     */
UNCOV
76
    protected function getValidationRules(): array
×
77
    {
78
        $rules = new ValidationRules();
×
79

80
        return $rules->getLoginRules();
×
81
    }
82

83
    /**
84
     * Logs the current user out.
85
     */
UNCOV
86
    public function logoutAction(): RedirectResponse
×
87
    {
88
        // Capture logout redirect URL before auth logout
89
        $url = config('Auth')->logoutRedirect();
×
90

91
        auth()->logout();
×
92

93
        return $this->handleSuccess($url, lang('Auth.successLogout'));
×
94
    }
95
}
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