mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-02 11:26:04 +01:00
Added ajax task
This commit is contained in:
@@ -93,9 +93,9 @@ class AdminBaseController
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->validateNonce()) {
|
// if (!$this->validateNonce()) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
$method = 'task' . ucfirst($this->task);
|
$method = 'task' . ucfirst($this->task);
|
||||||
|
|
||||||
|
|||||||
@@ -2244,4 +2244,28 @@ class AdminController extends AdminBaseController
|
|||||||
$this->setRedirect('/tools');
|
$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