-
Notifications
You must be signed in to change notification settings - Fork 290
Expand file tree
/
Copy pathSetupComponent.php
More file actions
57 lines (51 loc) · 1.86 KB
/
SetupComponent.php
File metadata and controls
57 lines (51 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
/**
* Copyright 2010 - 2026, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2026, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Controller\Component;
use Cake\Controller\Component;
use Cake\Core\Configure;
class SetupComponent extends Component
{
/**
* Initialize
*
* @param array $config component configuration
* @return void
* @throws \Exception
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->loadAuthComponents($this->getController());
}
/**
* Load all auth components needed: Authentication.Authentication, Authorization.Authorization and CakeDC/OneTimePasswordAuthenticator
*
* @param \Cake\Controller\Controller $controller Target controller
* @return void
* @throws \Exception
*/
protected function loadAuthComponents($controller)
{
$authenticationConfig = Configure::read('Auth.AuthenticationComponent');
if ($authenticationConfig['load'] ?? false) {
unset($authenticationConfig['config']);
$controller->loadComponent('Authentication.Authentication', $authenticationConfig);
}
if (Configure::read('Auth.AuthorizationComponent.enable') !== false) {
$config = (array)Configure::read('Auth.AuthorizationComponent');
$controller->loadComponent('Authorization.Authorization', $config);
}
if (Configure::read('OneTimePasswordAuthenticator.login') !== false) {
$controller->loadComponent('CakeDC/Auth.OneTimePasswordAuthenticator');
}
}
}