AuthComponent::_setDefaults()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 43
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 30
nc 3
nop 0
1
<?php
2
/**
3
 * CakeCMS Community
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Community
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Community".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Community\Controller\Component;
17
18
use Cake\Controller\Component\AuthComponent as BaseAuthComponent;
19
20
/**
21
 * Class AuthComponent
22
 *
23
 * @package Community\Controller\Component
24
 */
25
class AuthComponent extends BaseAuthComponent
26
{
27
28
    /**
29
     * Get login redirect by app client.
30
     *
31
     * @return  array
32
     */
33
    protected function _getLoginRedirect()
34
    {
35
        $redirect = [
36
            'action'     => 'index',
37
            'controller' => 'Users',
38
            'plugin'     => 'Community'
39
        ];
40
41
        if (!$this->request->getParam('prefix')) {
42
            $redirect = [
43
                'controller' => 'Users',
44
                'action'     => 'profile',
45
                'plugin'     => 'Community'
46
            ];
47
        }
48
        return $redirect;
49
    }
50
51
    /**
52
     * Sets defaults for configs.
53
     *
54
     * @return  void
55
     *
56
     * @throws  \Aura\Intl\Exception
57
     */
58
    protected function _setDefaults()
59
    {
60
        $defaults = [
61
            'authenticate' => [
62
                'Form' => [
63
                    'finder'    => 'auth',
64
                    'userModel' => 'Community.Users',
65
                    'fields'    => [
66
                        'username' => 'login',
67
                        'password' => 'password'
68
                    ],
69
                ]
70
            ],
71
            'flash' => [
72
                'key'       => 'auth',
73
                'element'   => 'error',
74
                'params'    => ['class' => 'error']
75
            ],
76
            'loginAction' => [
77
                'controller' => 'Users',
78
                'action'     => 'login',
79
                'plugin'     => 'Community'
80
            ],
81
            'unauthorizedRedirect' => [
82
                'action'     => 'login',
83
                'controller' => 'Users',
84
                'plugin'     => 'Community'
85
            ],
86
            'authorize'      => ['Community.Base'],
87
            'loginRedirect'  => $this->_getLoginRedirect(),
88
            'logoutRedirect' => $this->_config['loginAction'],
89
            'authError'      => __d('community', 'You are not authorized to access that location.')
90
        ];
91
92
        $config = $this->getConfig();
93
        foreach ($config as $key => $value) {
94
            if ($value !== null) {
95
                unset($defaults[$key]);
96
            }
97
        }
98
99
        $this->setConfig($defaults);
100
    }
101
}
102