Added check if there is only one user

Added translations and documentation
This commit is contained in:
Nicolas Lœuillet 2016-09-08 14:07:36 +02:00 committed by Jeremy Benoist
parent abb5291cd5
commit bb0c78f4a6
No known key found for this signature in database
GPG Key ID: BCA73962457ACC3C
17 changed files with 50 additions and 1 deletions

View File

@ -50,6 +50,8 @@ User information
You can change your name, your email address and enable ``Two factor authentication``. You can change your name, your email address and enable ``Two factor authentication``.
If the wallabag instance has more than one enabled user, you can delete your account here. **Take care, we delete all your data**.
Two factor authentication Two factor authentication
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -51,6 +51,8 @@ Mon compte
Vous pouvez ici modifier votre nom, votre adresse email et activer la ``Double authentification``. Vous pouvez ici modifier votre nom, votre adresse email et activer la ``Double authentification``.
Si l'instance de wallabag compte plus d'un utilisateur actif, vous pouvez supprimer ici votre compte. **Attention, nous supprimons toutes vos données**.
Double authentification (2FA) Double authentification (2FA)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Config;
use Wallabag\CoreBundle\Entity\TaggingRule; use Wallabag\CoreBundle\Entity\TaggingRule;
use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\ConfigType;
@ -148,6 +149,9 @@ class ConfigController extends Controller
'token' => $config->getRssToken(), 'token' => $config->getRssToken(),
], ],
'twofactor_auth' => $this->getParameter('twofactor_auth'), 'twofactor_auth' => $this->getParameter('twofactor_auth'),
'enabled_users' => $this->getDoctrine()
->getRepository('WallabagUserBundle:User')
->getSumEnabledUsers(),
]); ]);
} }
@ -257,10 +261,20 @@ class ConfigController extends Controller
* *
* @Route("/account/delete", name="delete_account") * @Route("/account/delete", name="delete_account")
* *
* @throws AccessDeniedHttpException
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse * @return \Symfony\Component\HttpFoundation\RedirectResponse
*/ */
public function deleteAccountAction() public function deleteAccountAction()
{ {
$enabledUsers = $this->getDoctrine()
->getRepository('WallabagUserBundle:User')
->getSumEnabledUsers();
if ($enabledUsers <= 1) {
throw new AccessDeniedHttpException();
}
$em = $this->get('fos_user.user_manager'); $em = $this->get('fos_user.user_manager');
$em->deleteUser($this->getUser()); $em->deleteUser($this->getUser());

View File

@ -88,6 +88,7 @@ config:
name_label: 'Navn' name_label: 'Navn'
email_label: 'Emailadresse' email_label: 'Emailadresse'
# twoFactorAuthentication_label: 'Two factor authentication' # twoFactorAuthentication_label: 'Two factor authentication'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Gammel adgangskode' old_password_label: 'Gammel adgangskode'
new_password_label: 'Ny adgangskode' new_password_label: 'Ny adgangskode'

View File

@ -88,6 +88,7 @@ config:
name_label: 'Name' name_label: 'Name'
email_label: 'E-Mail-Adresse' email_label: 'E-Mail-Adresse'
twoFactorAuthentication_label: 'Zwei-Faktor-Authentifizierung' twoFactorAuthentication_label: 'Zwei-Faktor-Authentifizierung'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Altes Kennwort' old_password_label: 'Altes Kennwort'
new_password_label: 'Neues Kennwort' new_password_label: 'Neues Kennwort'

View File

@ -88,6 +88,7 @@ config:
name_label: 'Name' name_label: 'Name'
email_label: 'Email' email_label: 'Email'
twoFactorAuthentication_label: 'Two factor authentication' twoFactorAuthentication_label: 'Two factor authentication'
delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Current password' old_password_label: 'Current password'
new_password_label: 'New password' new_password_label: 'New password'

View File

@ -88,6 +88,7 @@ config:
name_label: 'Nombre' name_label: 'Nombre'
email_label: 'Direccion e-mail' email_label: 'Direccion e-mail'
twoFactorAuthentication_label: 'Autentificación de dos factores' twoFactorAuthentication_label: 'Autentificación de dos factores'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Contraseña actual' old_password_label: 'Contraseña actual'
new_password_label: 'Nueva contraseña' new_password_label: 'Nueva contraseña'

View File

@ -88,6 +88,7 @@ config:
name_label: 'نام' name_label: 'نام'
email_label: 'نشانی ایمیل' email_label: 'نشانی ایمیل'
twoFactorAuthentication_label: 'تأیید ۲مرحله‌ای' twoFactorAuthentication_label: 'تأیید ۲مرحله‌ای'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'رمز قدیمی' old_password_label: 'رمز قدیمی'
new_password_label: 'رمز تازه' new_password_label: 'رمز تازه'

View File

@ -88,6 +88,7 @@ config:
name_label: 'Nom' name_label: 'Nom'
email_label: 'Adresse e-mail' email_label: 'Adresse e-mail'
twoFactorAuthentication_label: 'Double authentification' twoFactorAuthentication_label: 'Double authentification'
delete_account: 'Supprimer mon compte'
form_password: form_password:
old_password_label: 'Mot de passe actuel' old_password_label: 'Mot de passe actuel'
new_password_label: 'Nouveau mot de passe' new_password_label: 'Nouveau mot de passe'

View File

@ -88,6 +88,7 @@ config:
name_label: 'Nome' name_label: 'Nome'
email_label: 'E-mail' email_label: 'E-mail'
twoFactorAuthentication_label: 'Two factor authentication' twoFactorAuthentication_label: 'Two factor authentication'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Password corrente' old_password_label: 'Password corrente'
new_password_label: 'Nuova password' new_password_label: 'Nuova password'

View File

@ -88,6 +88,7 @@ config:
name_label: 'Nom' name_label: 'Nom'
email_label: 'Adreça de corrièl' email_label: 'Adreça de corrièl'
twoFactorAuthentication_label: 'Dobla autentificacion' twoFactorAuthentication_label: 'Dobla autentificacion'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Senhal actual' old_password_label: 'Senhal actual'
new_password_label: 'Senhal novèl' new_password_label: 'Senhal novèl'

View File

@ -88,6 +88,7 @@ config:
name_label: 'Nazwa' name_label: 'Nazwa'
email_label: 'Adres email' email_label: 'Adres email'
twoFactorAuthentication_label: 'Autoryzacja dwuetapowa' twoFactorAuthentication_label: 'Autoryzacja dwuetapowa'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Stare hasło' old_password_label: 'Stare hasło'
new_password_label: 'Nowe hasło' new_password_label: 'Nowe hasło'

View File

@ -88,6 +88,7 @@ config:
name_label: 'Nume' name_label: 'Nume'
email_label: 'E-mail' email_label: 'E-mail'
# twoFactorAuthentication_label: 'Two factor authentication' # twoFactorAuthentication_label: 'Two factor authentication'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Parola veche' old_password_label: 'Parola veche'
new_password_label: 'Parola nouă' new_password_label: 'Parola nouă'

View File

@ -88,6 +88,7 @@ config:
name_label: 'İsim' name_label: 'İsim'
email_label: 'E-posta' email_label: 'E-posta'
twoFactorAuthentication_label: 'İki adımlı doğrulama' twoFactorAuthentication_label: 'İki adımlı doğrulama'
# delete_account: 'Delete my account'
form_password: form_password:
old_password_label: 'Eski şifre' old_password_label: 'Eski şifre'
new_password_label: 'Yeni şifre' new_password_label: 'Yeni şifre'

View File

@ -148,6 +148,9 @@
{{ form_widget(form.user._token) }} {{ form_widget(form.user._token) }}
{{ form_widget(form.user.save) }} {{ form_widget(form.user.save) }}
{% if enabled_users > 1 %}
<a class='btn red' href='{{ path('delete_account') }}'>{{ 'config.form_user.delete_account' | trans }}</a>
{% endif %}
</form> </form>
<h2>{{ 'config.tab_menu.password'|trans }}</h2> <h2>{{ 'config.tab_menu.password'|trans }}</h2>

View File

@ -167,7 +167,10 @@
{{ form_widget(form.user.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} {{ form_widget(form.user.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
{{ form_widget(form.user._token) }} {{ form_widget(form.user._token) }}
</form> </form>
<a class='btn red' href='{{ path('delete_account') }}'>{{ 'config.user.delete_account' | trans }}</a>
{% if enabled_users > 1 %}
<a class='btn red' href='{{ path('delete_account') }}'>{{ 'config.form_user.delete_account' | trans }}</a>
{% endif %}
</div> </div>
<div id="set4" class="col s12"> <div id="set4" class="col s12">

View File

@ -38,4 +38,18 @@ class UserRepository extends EntityRepository
->getQuery() ->getQuery()
->getSingleResult(); ->getSingleResult();
} }
/**
* Count how many users are enabled.
*
* @return int
*/
public function getSumEnabledUsers()
{
return $this->createQueryBuilder('u')
->select('count(u)')
->andWhere('u.expired = 0')
->getQuery()
->getSingleScalarResult();
}
} }