@@ 269-285 (lines=17) @@ | ||
266 | * @throws \yii\base\InvalidConfigException |
|
267 | * @throws \yii\base\NotSupportedException |
|
268 | */ |
|
269 | public function generateOtpByIdentityLoggedIn() |
|
270 | { |
|
271 | $data = $this->getIdentityLoggedIn(); |
|
272 | ||
273 | if (is_array($data)) { |
|
274 | ||
275 | /** @var IdentityInterface $identity */ |
|
276 | $identity = $data[0]; |
|
277 | $secretKey = $identity->getMfaSecretKey(); |
|
278 | ||
279 | if (!empty($secretKey)) { |
|
280 | return $this->getOtp()->generate($secretKey); |
|
281 | } |
|
282 | } |
|
283 | ||
284 | return null; |
|
285 | } |
|
286 | ||
287 | /** |
|
288 | * Validate an otp by current user logged in |
|
@@ 295-310 (lines=16) @@ | ||
292 | * @throws \yii\base\InvalidConfigException |
|
293 | * @throws \yii\base\NotSupportedException |
|
294 | */ |
|
295 | public function validateOtpByIdentityLoggedIn(string $otp) |
|
296 | { |
|
297 | $data = $this->getIdentityLoggedIn(); |
|
298 | ||
299 | if (is_array($data)) { |
|
300 | /** @var IdentityInterface $identity */ |
|
301 | $identity = $data[0]; |
|
302 | $secretKey = $identity->getMfaSecretKey(); |
|
303 | ||
304 | if (!empty($secretKey)) { |
|
305 | return $this->getOtp()->validate($secretKey, $otp); |
|
306 | } |
|
307 | } |
|
308 | ||
309 | return false; |
|
310 | } |
|
311 | ||
312 | /** |
|
313 | * Return a qr code uri of current user |