Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add command to generate a two step validation secret

  • Loading branch information...
commit 258e202a0266cf00c4b21628a7bea71cf925a77c 1 parent a937ed6
@rande rande authored
View
56 Command/TwoStepVerificationCommand.php
@@ -0,0 +1,56 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\UserBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Output\Output;
+
+class TwoStepVerificationCommand extends ContainerAwareCommand
+{
+ public function configure()
+ {
+ $this->setName('sonata:user:two-step-verification');
+ $this->addArgument('username', InputArgument::REQUIRED, 'The username to protect with a two step verification process');
+ $this->setDescription('Generate a two step verification process to secure an access (Ideal for super admin protection)');
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ if (!$this->getContainer()->has('sonata.user.google.authenticator.provider')) {
+ throw new \RuntimeException('Two Step Verification process is not enabled');
+ }
+
+ $helper = $this->getContainer()->get('sonata.user.google.authenticator.provider');
+ $manager = $this->getContainer()->get('fos_user.user_manager');
+
+ $user = $manager->findUserByUsernameOrEmail($input->getArgument('username'));
+
+ if (!$user) {
+ throw new \RuntimeException(sprintf('Unable to find the username : %s', $input->getArgument('username')));
+ }
+
+ if (!$user->getTwoStepVerificationCode()) {
+ $user->setTwoStepVerificationCode($helper->generateSecret());
+ $manager->updateUser($user);
+ }
+
+ $output->writeln(array(
+ sprintf('<info>Username</info> : %s', $input->getArgument('username')),
+ sprintf('<info>Secret</info> : %s', $user->getTwoStepVerificationCode()),
+ sprintf('<info>Url</info> : %s', $helper->getUrl($user)),
+ ));
+ }
+}
View
6 Resources/doc/reference/two_step_validation.rst
@@ -19,9 +19,9 @@ Installation
Add the following lines to the file ``deps``::
- [SonataUserBundle]
- git=git://github.com/sonata-project/SonataUserBundle.git
- target=/bundles/Sonata/UserBundle
+ [GoogleAuthenticator]
+ git=git://github.com/rande/GoogleAuthenticator.php.git
+ target=/google-authenticator
Update the autoload.php file::
Please sign in to comment.
Something went wrong with that request. Please try again.