mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-01 10:56:08 +01:00
Added ajax task
This commit is contained in:
@@ -2244,4 +2244,28 @@ class AdminController extends AdminBaseController
|
||||
$this->setRedirect('/tools');
|
||||
}
|
||||
|
||||
public function taskRegenerate2FASecret()
|
||||
{
|
||||
if (!$this->authorizeTask('regenerate 2FA Secret', ['admin.login'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$twofa = $this->admin->get2FA();
|
||||
|
||||
$secret = $twofa->createSecret(160);
|
||||
$email = $this->grav['user']->email;
|
||||
|
||||
$image = $twofa->getQRCodeImageAsDataUri($email, $secret);
|
||||
|
||||
$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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user