actionTwoStepEnable()   B
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 43
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 8.439
c 0
b 0
f 0
cc 6
eloc 20
nc 9
nop 0
1
<?php
2
/**
3
 * Workaround for two step managment.
4
 *
5
 * @package ThreemaGateway
6
 * @author rugk
7
 * @copyright Copyright (c) 2015-2016 rugk
8
 * @license MIT
9
 */
10
11
class ThreemaGateway_ControllerPublic_Account extends XFCP_ThreemaGateway_ControllerPublic_Account
12
{
13
    /**
14
     * Expand XenForo's two factor enable managment as it is not properly implemented.
15
     *
16
     * @see https://xenforo.com/community/threads/1-5-documentation-for-two-step-authentication.102846/#post-1031047
17
     * @return XenForo_ControllerResponse_View
18
     */
19
    public function actionTwoStepEnable()
20
    {
21
        /** @var XenForo_ControllerResponse_View $parent */
22
        $parent = parent::actionTwoStepEnable();
23
24
        if ($parent instanceof XenForo_ControllerResponse_View) {
25
            // read params
26
            /** @var array $params */
27
            $params = $parent->subView->params;
28
            /** @var XenForo_Tfa_AbstractProvider $provider */
29
            $provider = $params['provider'];
30
            /** @var string $providerId */
31
            $providerId = $params['providerId'];
32
            /** @var array $providerData */
33
            $providerData = [];
34
            if (array_key_exists('providerData', $params)) {
35
                $providerData = $params['providerData'];
36
            }
37
38
            if (in_array($providerId, ThreemaGateway_Constants::TFA_PROVIDER_ARRAY)) {
39
                //get additional data
40
                /** @var XenForo_Visitor $visitor */
41
                $visitor = XenForo_Visitor::getInstance();
42
43
                //forward request to manager
44
                /** @var XenForo_ControllerResponse|null $result */
45
                $result = $provider->handleManage($this, $visitor->toArray(), $providerData);
46
47
                if (!$result) {
48
                    $result = $this->responseRedirect(
49
                        XenForo_ControllerResponse_Redirect::SUCCESS,
50
                        XenForo_Link::buildPublicLink('account/two-step')
51
                    );
52
                } elseif ($result instanceof XenForo_ControllerResponse_View) {
53
                    $result = $this->_getWrapper('account', 'two-step', $result);
54
                }
55
56
                return $result;
57
            }
58
        }
59
60
        return $parent;
61
    }
62
}
63