mirror of
https://github.com/wallabag/wallabag.git
synced 2025-06-05 15:08:47 +00:00
Fix tests
This commit is contained in:
parent
edc79ad886
commit
2dfbe9e5fa
4 changed files with 36 additions and 69 deletions
|
@ -81,24 +81,24 @@ class ConfigController extends Controller
|
||||||
$userForm->handleRequest($request);
|
$userForm->handleRequest($request);
|
||||||
|
|
||||||
// `googleTwoFactor` isn't a field within the User entity, we need to define it's value in a different way
|
// `googleTwoFactor` isn't a field within the User entity, we need to define it's value in a different way
|
||||||
if (true === $user->isGoogleAuthenticatorEnabled() && false === $userForm->isSubmitted()) {
|
if ($this->getParameter('twofactor_auth') && true === $user->isGoogleAuthenticatorEnabled() && false === $userForm->isSubmitted()) {
|
||||||
$userForm->get('googleTwoFactor')->setData(true);
|
$userForm->get('googleTwoFactor')->setData(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($userForm->isSubmitted() && $userForm->isValid()) {
|
if ($userForm->isSubmitted() && $userForm->isValid()) {
|
||||||
// handle creation / reset of the OTP secret if checkbox changed from the previous state
|
// handle creation / reset of the OTP secret if checkbox changed from the previous state
|
||||||
|
if ($this->getParameter('twofactor_auth')) {
|
||||||
if (true === $userForm->get('googleTwoFactor')->getData() && false === $user->isGoogleAuthenticatorEnabled()) {
|
if (true === $userForm->get('googleTwoFactor')->getData() && false === $user->isGoogleAuthenticatorEnabled()) {
|
||||||
$secret = $this->get('scheb_two_factor.security.google_authenticator')->generateSecret();
|
$secret = $this->get('scheb_two_factor.security.google_authenticator')->generateSecret();
|
||||||
|
|
||||||
$user->setGoogleAuthenticatorSecret($secret);
|
$user->setGoogleAuthenticatorSecret($secret);
|
||||||
$user->setEmailTwoFactor(false);
|
$user->setEmailTwoFactor(false);
|
||||||
|
|
||||||
$qrCode = $this->get('scheb_two_factor.security.google_authenticator')->getQRContent($user);
|
$this->addFlash('OtpQrCode', $this->get('scheb_two_factor.security.google_authenticator')->getQRContent($user));
|
||||||
|
|
||||||
$this->addFlash('OTPSecret', ['code' => $secret, 'qrCode' => $qrCode]);
|
|
||||||
} elseif (false === $userForm->get('googleTwoFactor')->getData() && true === $user->isGoogleAuthenticatorEnabled()) {
|
} elseif (false === $userForm->get('googleTwoFactor')->getData() && true === $user->isGoogleAuthenticatorEnabled()) {
|
||||||
$user->setGoogleAuthenticatorSecret(null);
|
$user->setGoogleAuthenticatorSecret(null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$userManager->updateUser($user, true);
|
$userManager->updateUser($user, true);
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,7 @@
|
||||||
<br/>
|
<br/>
|
||||||
<img id="androidQrcode" />
|
<img id="androidQrcode" />
|
||||||
<script>
|
<script>
|
||||||
const imgBase64 = jrQrcode.getQrBase64('wallabag://{{ app.user.username }}@{{ wallabag_url }}');
|
document.getElementById('androidQrcode').src = jrQrcode.getQrBase64('wallabag://{{ app.user.username }}@{{ wallabag_url }}');
|
||||||
document.getElementById('androidQrcode').src = imgBase64;
|
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -186,20 +185,20 @@
|
||||||
{{ form_widget(form.user.googleTwoFactor) }}
|
{{ form_widget(form.user.googleTwoFactor) }}
|
||||||
{{ form_errors(form.user.googleTwoFactor) }}
|
{{ form_errors(form.user.googleTwoFactor) }}
|
||||||
</div>
|
</div>
|
||||||
{% for OTPSecret in app.session.flashbag.get('OTPSecret') %}
|
{% for OtpQrCode in app.session.flashbag.get('OtpQrCode') %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
You just enabled the OTP two factor authentication, open your OTP app and use that code to get a one time password.
|
You just enabled the OTP two factor authentication, open your OTP app and use that code to get a one time password.
|
||||||
<br/>
|
<br/>
|
||||||
That code will disapear after a page reload.
|
That code will disapear after a page reload.
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<strong>{{ OTPSecret.code }}</strong>
|
<strong>{{ app.user.getGoogleAuthenticatorSecret }}</strong>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
Or you can scan that QR Code with your app:
|
Or you can scan that QR Code with your app:
|
||||||
<br/>
|
<br/>
|
||||||
<img id="2faQrcode" class="hide-on-med-and-down" />
|
<img id="2faQrcode" class="hide-on-med-and-down" />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('2faQrcode').src = jrQrcode.getQrBase64('{{ OTPSecret.qrCode }}');;
|
document.getElementById('2faQrcode').src = jrQrcode.getQrBase64('{{ OtpQrCode }}');;
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -212,20 +212,20 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% for OTPSecret in app.session.flashbag.get('OTPSecret') %}
|
{% for OtpQrCode in app.session.flashbag.get('OtpQrCode') %}
|
||||||
<div class="card-panel yellow darken-1 black-text">
|
<div class="card-panel yellow darken-1 black-text">
|
||||||
You just enabled the OTP two factor authentication, open your OTP app and use that code to get a one time password.
|
You just enabled the OTP two factor authentication, open your OTP app and use that code to get a one time password.
|
||||||
<br/>
|
<br/>
|
||||||
That code will disapear after a page reload.
|
That code will disapear after a page reload.
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<strong>{{ OTPSecret.code }}</strong>
|
<strong>{{ app.user.getGoogleAuthenticatorSecret }}</strong>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
Or you can scan that QR Code with your app:
|
Or you can scan that QR Code with your app:
|
||||||
<br/>
|
<br/>
|
||||||
<img id="2faQrcode" class="hide-on-med-and-down" />
|
<img id="2faQrcode" class="hide-on-med-and-down" />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('2faQrcode').src = jrQrcode.getQrBase64('{{ OTPSecret.qrCode }}');;
|
document.getElementById('2faQrcode').src = jrQrcode.getQrBase64('{{ OtpQrCode }}');;
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -8,7 +8,6 @@ use Pagerfanta\Adapter\DoctrineORMAdapter;
|
||||||
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
|
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
|
||||||
use Pagerfanta\Pagerfanta;
|
use Pagerfanta\Pagerfanta;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
use Symfony\Component\Form\FormInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
|
@ -32,10 +31,10 @@ class ManageController extends Controller
|
||||||
// enable created user by default
|
// enable created user by default
|
||||||
$user->setEnabled(true);
|
$user->setEnabled(true);
|
||||||
|
|
||||||
$form = $this->createEditForm('NewUserType', $user, $request);
|
$form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$user = $this->handleOtp($form, $user);
|
|
||||||
$userManager->updateUser($user);
|
$userManager->updateUser($user);
|
||||||
|
|
||||||
// dispatch a created event so the associated config will be created
|
// dispatch a created event so the associated config will be created
|
||||||
|
@ -66,10 +65,25 @@ class ManageController extends Controller
|
||||||
$userManager = $this->container->get('fos_user.user_manager');
|
$userManager = $this->container->get('fos_user.user_manager');
|
||||||
|
|
||||||
$deleteForm = $this->createDeleteForm($user);
|
$deleteForm = $this->createDeleteForm($user);
|
||||||
$form = $this->createEditForm('UserType', $user, $request);
|
$form = $this->createForm('Wallabag\UserBundle\Form\UserType', $user);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
// `googleTwoFactor` isn't a field within the User entity, we need to define it's value in a different way
|
||||||
|
if ($this->getParameter('twofactor_auth') && true === $user->isGoogleAuthenticatorEnabled() && false === $form->isSubmitted()) {
|
||||||
|
$form->get('googleTwoFactor')->setData(true);
|
||||||
|
}
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$user = $this->handleOtp($form, $user);
|
// handle creation / reset of the OTP secret if checkbox changed from the previous state
|
||||||
|
if ($this->getParameter('twofactor_auth')) {
|
||||||
|
if (true === $form->get('googleTwoFactor')->getData() && false === $user->isGoogleAuthenticatorEnabled()) {
|
||||||
|
$user->setGoogleAuthenticatorSecret($this->get('scheb_two_factor.security.google_authenticator')->generateSecret());
|
||||||
|
$user->setEmailTwoFactor(false);
|
||||||
|
} elseif (false === $form->get('googleTwoFactor')->getData() && true === $user->isGoogleAuthenticatorEnabled()) {
|
||||||
|
$user->setGoogleAuthenticatorSecret(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$userManager->updateUser($user);
|
$userManager->updateUser($user);
|
||||||
|
|
||||||
$this->get('session')->getFlashBag()->add(
|
$this->get('session')->getFlashBag()->add(
|
||||||
|
@ -172,50 +186,4 @@ class ManageController extends Controller
|
||||||
->getForm()
|
->getForm()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a form to create or edit a User entity.
|
|
||||||
*
|
|
||||||
* @param string $type Might be NewUserType or UserType
|
|
||||||
* @param User $user The new / edit user
|
|
||||||
* @param Request $request The request
|
|
||||||
*
|
|
||||||
* @return FormInterface
|
|
||||||
*/
|
|
||||||
private function createEditForm($type, User $user, Request $request)
|
|
||||||
{
|
|
||||||
$form = $this->createForm('Wallabag\UserBundle\Form\\' . $type, $user);
|
|
||||||
$form->handleRequest($request);
|
|
||||||
|
|
||||||
// `googleTwoFactor` isn't a field within the User entity, we need to define it's value in a different way
|
|
||||||
if (true === $user->isGoogleAuthenticatorEnabled() && false === $form->isSubmitted()) {
|
|
||||||
$form->get('googleTwoFactor')->setData(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle OTP update, taking care to only have one 2fa enable at a time.
|
|
||||||
*
|
|
||||||
* @see ConfigController
|
|
||||||
*
|
|
||||||
* @param FormInterface $form
|
|
||||||
* @param User $user
|
|
||||||
*
|
|
||||||
* @return User
|
|
||||||
*/
|
|
||||||
private function handleOtp(FormInterface $form, User $user)
|
|
||||||
{
|
|
||||||
if (true === $form->get('googleTwoFactor')->getData() && false === $user->isGoogleAuthenticatorEnabled()) {
|
|
||||||
$user->setGoogleAuthenticatorSecret($this->get('scheb_two_factor.security.google_authenticator')->generateSecret());
|
|
||||||
$user->setEmailTwoFactor(false);
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->setGoogleAuthenticatorSecret(null);
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue