Newer
Older

Yassine Doghri
committed
<?php

Yassine Doghri
committed
declare(strict_types=1);

Yassine Doghri
committed
namespace Modules\Auth\Config;

Yassine Doghri
committed

Yassine Doghri
committed
use CodeIgniter\Shield\Authentication\Actions\ActionInterface;
use CodeIgniter\Shield\Config\Auth as ShieldAuth;
use Modules\Auth\Models\UserModel;

Yassine Doghri
committed
class Auth extends ShieldAuth

Yassine Doghri
committed
{

Yassine Doghri
committed
/**

Yassine Doghri
committed
* ////////////////// AUTHENTICATION //////////////////

Yassine Doghri
committed
*
* @var array<string, string>
*/

Yassine Doghri
committed
public array $views = [
'login' => 'login',
'register' => 'register',

Yassine Doghri
committed
'layout' => '_layout',
'action_email_2fa' => 'email_2fa_show',
'action_email_2fa_verify' => 'email_2fa_verify',
'action_email_2fa_email' => 'emails/email_2fa_email',
'action_email_activate_show' => 'email_activate_show',
'action_email_activate_email' => 'emails/email_activate_email',
'magic-link-login' => 'magic_link_form',
'magic-link-message' => 'magic_link_message',
'magic-link-email' => 'emails/magic_link_email',
'magic-link-set-password' => 'magic_link_set_password',
'welcome-email' => 'emails/welcome_email',

Yassine Doghri
committed
];

Yassine Doghri
committed
/**

Yassine Doghri
committed
* --------------------------------------------------------------------
* Redirect urLs
* --------------------------------------------------------------------
* The default URL that a user will be redirected to after
* various auth actions. If you need more flexibility you can
* override the `getUrl()` method to apply any logic you may need.

Yassine Doghri
committed
*

Yassine Doghri
committed
* @var array<string, string>

Yassine Doghri
committed
*/

Yassine Doghri
committed
public array $redirects = [
'register' => '/',
'login' => '/',
'logout' => 'login',
];

Yassine Doghri
committed

Yassine Doghri
committed
/**

Yassine Doghri
committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
* --------------------------------------------------------------------
* Authentication Actions
* --------------------------------------------------------------------
* Specifies the class that represents an action to take after
* the user logs in or registers a new account at the site.
*
* You must register actions in the order of the actions to be performed.
*
* Available actions with Shield:
* - register: 'CodeIgniter\Shield\Authentication\Actions\EmailActivator'
* - login: 'CodeIgniter\Shield\Authentication\Actions\Email2FA'
*
* @var array<string, class-string<ActionInterface>|null>
*/
public array $actions = [
'register' => null,
'login' => null,
];
/**
* --------------------------------------------------------------------
* Allow Registration
* --------------------------------------------------------------------
* Determines whether users can register for the site.
*/
public bool $allowRegistration = true;
/**
* --------------------------------------------------------------------
* Welcome Link Lifetime
* --------------------------------------------------------------------
* Specifies the amount of time, in seconds, that a welcome link is valid.
* You can use Time Constants or any desired number.
*/
public int $welcomeLinkLifetime = 48 * HOUR;
/**
* --------------------------------------------------------------------
* User Provider
* --------------------------------------------------------------------
* The name of the class that handles user persistence.
* By default, this is the included UserModel, which
* works with any of the database engines supported by CodeIgniter.
* You can change it as long as they adhere to the
* CodeIgniter\Shield\Models\UserModel.

Yassine Doghri
committed
*

Yassine Doghri
committed
* @var class-string<UserModel>

Yassine Doghri
committed
*/

Yassine Doghri
committed
public string $userProvider = UserModel::class;

Yassine Doghri
committed

Yassine Doghri
committed
/**
* --------------------------------------------------------------------------
* Auth gateway
* --------------------------------------------------------------------------
* Defines a base route for all authentication related pages
*/
public string $gateway = 'cp-auth';

Yassine Doghri
committed
public function __construct()
{
$adminGateway = config('Admin')
->gateway;
$this->redirects = [
'register' => $adminGateway,
'login' => $adminGateway,
'logout' => $adminGateway,
];
}
/**
* Returns the URL that a user should be redirected to after a successful login.
*
* Redirects to the set-password form if magicLogin
*/
public function loginRedirect(): string
{
$url = session('magicLogin') ? route_to('magic-link-set-password') : setting('Auth.redirects')['login'];
return $this->getUrl($url);
}