1 | <?php |
||
28 | class TotpController extends \yii\web\Controller |
||
29 | { |
||
30 | private const TOTP_BACK_URL = 'totp-back-url'; |
||
31 | |||
32 | public $enableCsrfValidation = false; |
||
33 | |||
34 | public function behaviors() |
||
35 | { |
||
36 | return array_merge(parent::behaviors(), [ |
||
37 | 'filterApi' => [ |
||
38 | 'class' => OauthLoginBehavior::class, |
||
39 | 'only' => ['api-temporary-secret', 'api-disable', 'api-enable'], |
||
40 | ], |
||
41 | 'access' => [ |
||
42 | 'class' => AccessControl::class, |
||
43 | 'denyCallback' => [$this, 'denyCallback'], |
||
44 | 'rules' => [ |
||
45 | // ? - guest |
||
46 | [ |
||
47 | 'actions' => ['check'], |
||
48 | 'roles' => ['?'], |
||
49 | 'allow' => true, |
||
50 | ], |
||
51 | // @ - authenticated |
||
52 | [ |
||
53 | 'actions' => ['enable', 'disable', 'toggle', 'api-temporary-secret', 'api-disable', 'api-enable', 'back'], |
||
54 | 'roles' => ['@'], |
||
55 | 'allow' => true, |
||
56 | ], |
||
57 | ], |
||
58 | ], |
||
59 | 'verbFilter' => [ |
||
60 | 'class' => VerbFilter::class, |
||
61 | 'actions' => [ |
||
62 | 'api-temporary-secret' => ['POST'], |
||
63 | 'api-enable' => ['POST'], |
||
64 | 'api-disable' => ['POST'], |
||
65 | ], |
||
66 | ], |
||
67 | 'contentNegotiator' => [ |
||
68 | 'class' => ContentNegotiator::class, |
||
69 | 'only' => ['api-temporary-secret', 'api-disable', 'api-enable'], |
||
70 | 'formats' => [ |
||
71 | 'application/json' => Response::FORMAT_JSON, |
||
72 | ], |
||
73 | ], |
||
74 | ]); |
||
75 | } |
||
76 | |||
77 | public function denyCallback() |
||
81 | |||
82 | public function actionEnable($back = null) |
||
83 | { |
||
84 | /** @var MfaIdentityInterface $user */ |
||
85 | $user = Yii::$app->user->identity; |
||
86 | if ($user->getTotpSecret()) { |
||
87 | Yii::$app->session->setFlash('error', Yii::t('mfa', 'Two-factor authentication is already enabled. Disable first.')); |
||
88 | |||
89 | return empty($back) ? $this->goHome() : $this->deferredRedirect($back); |
||
90 | } |
||
91 | |||
92 | $model = new InputForm(); |
||
93 | $secret = $this->module->getTotp()->getSecret(); |
||
94 | |||
95 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
||
96 | if ($this->module->getTotp()->verifyCode($secret, $model->code)) { |
||
97 | $user->setTotpSecret($secret); |
||
98 | $this->module->getTotp()->setIsVerified(true); |
||
99 | if ($user->save() && Yii::$app->user->login($user)) { |
||
100 | Yii::$app->session->setFlash('success', Yii::t('mfa', 'Two-factor authentication successfully enabled.')); |
||
101 | |||
102 | return empty($back) ? $this->goBack() : $this->deferredRedirect($back); |
||
103 | } else { |
||
104 | Yii::$app->session->setFlash('error', Yii::t('mfa', 'Sorry, we have failed to enable two-factor authentication.')); |
||
105 | |||
106 | return empty($back) ? $this->goHome() : $this->deferredRedirect($back); |
||
107 | } |
||
108 | } else { |
||
109 | $model->addError('code', Yii::t('mfa', 'Wrong verification code. Please verify your secret and try again.')); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | $qrcode = $this->module->getTotp()->getQRCodeImageAsDataUri($user->getUsername(), $secret); |
||
114 | |||
115 | return $this->render('enable', compact('model', 'secret', 'qrcode')); |
||
116 | } |
||
117 | |||
118 | public function actionDisable($back = null) |
||
140 | |||
141 | public function actionBack() |
||
142 | { |
||
151 | |||
152 | public function deferredRedirect($url = null) |
||
159 | |||
160 | public function actionToggle($back = null) |
||
167 | |||
168 | public function actionCheck() |
||
192 | |||
193 | /** |
||
194 | * @inheritDoc |
||
195 | */ |
||
196 | public function goBack($defaultUrl = null) |
||
205 | |||
206 | public function actionApiEnable() |
||
225 | |||
226 | public function actionApiDisable() |
||
244 | |||
245 | public function actionApiTemporarySecret() |
||
255 | } |
||
256 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.