mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-01 10:56:08 +01:00
2FA logic optimization
This commit is contained in:
@@ -2244,34 +2244,13 @@ class AdminController extends AdminBaseController
|
||||
$this->setRedirect('/tools');
|
||||
}
|
||||
|
||||
public function taskRegenerate2FASecret()
|
||||
public function taskRegenerate2FASecret($secret = null)
|
||||
{
|
||||
if (!$this->authorizeTask('regenerate 2FA Secret', ['admin.login'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$user = $this->grav['user'];
|
||||
|
||||
$twofa = $this->admin->get2FA();
|
||||
|
||||
$secret = $twofa->createSecret(160);
|
||||
$email = $user->email;
|
||||
|
||||
$image = $twofa->getQRCodeImageAsDataUri($email, $secret);
|
||||
|
||||
$user->twofa_secret = $secret;
|
||||
|
||||
|
||||
$user->save();
|
||||
|
||||
$this->admin->json_response = ['status' => 'success', 'image' => $image, 'secret' => trim(chunk_split($secret, 4, ' '))];
|
||||
} catch (\Exception $e) {
|
||||
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return $this->admin->get2FAData($secret);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user