Added ajax task

This commit is contained in:
Andy Miller
2017-08-25 17:11:10 -06:00
parent 92dd08eb4a
commit 2f63859bd3
2 changed files with 27 additions and 3 deletions

View File

@@ -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;
}
}