Exemple #1
0
 /**
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('username');
     $password = $input->getArgument('password');
     $email = $input->getArgument('email');
     $displayname = $input->getArgument('displayname');
     $role = $input->getArgument('role');
     $data = ['username' => $username, 'password' => $password, 'email' => $email, 'displayname' => $displayname, 'roles' => [$role]];
     $user = new Entity\Users($data);
     $valid = true;
     if (!$this->app['users']->checkAvailability('username', $user->getUsername())) {
         $valid = false;
         $output->writeln("<error>Error creating user: username {$user->getUsername()} already exists</error>");
     }
     if (!$this->app['users']->checkAvailability('email', $user->getEmail())) {
         $valid = false;
         $output->writeln("<error>Error creating user: email {$user->getEmail()} exists</error>");
     }
     if (!$this->app['users']->checkAvailability('displayname', $user->getDisplayname())) {
         $valid = false;
         $output->writeln("<error>Error creating user: display name {$user->getDisplayname()} already exists</error>");
     }
     if ($valid) {
         $res = $this->app['users']->saveUser($user);
         if ($res) {
             $this->auditLog(__CLASS__, "User created: {$user['username']}");
             $output->writeln("<info>Successfully created user: {$user['username']}</info>");
         } else {
             $output->writeln("<error>Error creating user: {$user['username']}</error>");
         }
     }
 }
Exemple #2
0
 /**
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Bolt\Storage\Repository\UsersRepository $repo */
     $repo = $this->app['storage']->getRepository('Bolt\\Storage\\Entity\\Users');
     $user = new Entity\Users(['username' => $input->getArgument('username'), 'password' => $input->getArgument('password'), 'email' => $input->getArgument('email'), 'displayname' => $input->getArgument('displayname'), 'roles' => (array) $input->getArgument('role')]);
     $message = [];
     $valid = true;
     if ($repo->getUser($user->getEmail())) {
         $valid = false;
         $message[] = "<error>    * Email address '{$user->getEmail()}' already exists</error>";
     }
     if ($repo->getUser($user->getUsername())) {
         $valid = false;
         $message[] = "<error>    * User name '{$user->getUsername()}' already exists</error>";
     }
     if ($valid === false) {
         $message[] = "<error>Error creating user:</error>";
         $output->write(array_reverse($message), true);
         return;
     }
     try {
         // Boot all service providers manually as, we're not handling a request
         $this->app->boot();
         $this->app['storage']->getRepository('Bolt\\Storage\\Entity\\Users')->save($user);
         $this->auditLog(__CLASS__, "User created: {$user->getUsername()}");
         $output->writeln("<info>Successfully created user: {$user->getUsername()}</info>");
     } catch (\Exception $e) {
         $output->writeln("<error>Error creating user: {$user->getUsername()}</error>");
     }
 }
Exemple #3
0
 /**
  * Send the password reset link notification to the user.
  *
  * @param Entity\Users $userEntity
  * @param string       $shadowpassword
  * @param string       $shadowtoken
  */
 private function resetPasswordNotification(Entity\Users $userEntity, $shadowpassword, $shadowtoken)
 {
     $shadowlink = sprintf('%s%sresetpassword?token=%s', $this->app['resources']->getUrl('hosturl'), $this->app['resources']->getUrl('bolt'), urlencode($shadowtoken));
     // Compile the email with the shadow password and reset link.
     $mailhtml = $this->app['render']->render('@bolt/mail/passwordreset.twig', ['user' => $userEntity, 'shadowpassword' => $shadowpassword, 'shadowtoken' => $shadowtoken, 'shadowvalidity' => date('Y-m-d H:i:s', strtotime('+2 hours')), 'shadowlink' => $shadowlink]);
     $subject = sprintf('[ Bolt / %s ] Password reset.', $this->app['config']->get('general/sitename'));
     $name = $this->app['config']->get('general/mailoptions/senderName', $this->app['config']->get('general/sitename'));
     $email = $this->app['config']->get('general/mailoptions/senderMail', $userEntity->getEmail());
     $from = [$email => $name];
     $message = $this->app['mailer']->createMessage('message')->setSubject($subject)->setFrom($from)->setReplyTo($from)->setTo([$userEntity->getEmail() => $userEntity->getDisplayname()])->setBody(strip_tags($mailhtml))->addPart($mailhtml, 'text/html');
     $failed = true;
     $failedRecipients = [];
     try {
         $recipients = $this->app['mailer']->send($message, $failedRecipients);
         // Try and send immediately
         $this->app['swiftmailer.spooltransport']->getSpool()->flushQueue($this->app['swiftmailer.transport']);
         if ($recipients) {
             $this->app['logger.system']->info("Password request sent to '" . $userEntity->getDisplayname() . "'.", ['event' => 'authentication']);
             $failed = false;
         }
     } catch (\Exception $e) {
         // Notify below
     }
     if ($failed) {
         $this->app['logger.system']->error("Failed to send password request sent to '" . $userEntity['displayname'] . "'.", ['event' => 'authentication']);
         $this->app['logger.flash']->error(Trans::__('general.phrase.error-send-password-request'));
     }
 }
Exemple #4
0
 /**
  * Send the password reset link notification to the user.
  *
  * @param Entity\Users $userEntity
  * @param string       $shadowPassword
  * @param string       $shadowToken
  */
 private function resetPasswordNotification(Entity\Users $userEntity, $shadowPassword, $shadowToken)
 {
     $config = $this->app['config'];
     $flash = $this->app['logger.flash'];
     $mailer = $this->app['mailer'];
     $logger = $this->app['logger.system'];
     $twig = $this->app['twig'];
     $urlGenerator = $this->app['url_generator'];
     $shadowLink = $urlGenerator->generate('resetpassword', ['token' => $shadowToken], UrlGeneratorInterface::ABSOLUTE_URL);
     // Compile the email with the shadow password and reset link.
     $mailHtml = $twig->render('@bolt/mail/passwordreset.twig', ['user' => $userEntity, 'shadowpassword' => $shadowPassword, 'shadowtoken' => $shadowToken, 'shadowvalidity' => Carbon::now()->addHours(2)->format('Y-m-d H:i:s'), 'shadowlink' => $shadowLink]);
     $subject = sprintf('[ Bolt / %s ] Password reset.', $config->get('general/sitename'));
     $name = $config->get('general/mailoptions/senderName', $config->get('general/sitename'));
     $email = $config->get('general/mailoptions/senderMail', $userEntity->getEmail());
     $from = [$email => $name];
     $message = $mailer->createMessage('message')->setSubject($subject)->setFrom($from)->setReplyTo($from)->setTo([$userEntity->getEmail() => $userEntity->getDisplayname()])->setBody(strip_tags($mailHtml))->addPart($mailHtml, 'text/html');
     $failed = true;
     $failedRecipients = [];
     try {
         $recipients = $mailer->send($message, $failedRecipients);
         // Try and send immediately
         $this->app['swiftmailer.spooltransport']->getSpool()->flushQueue($this->app['swiftmailer.transport']);
         if ($recipients) {
             $logger->info("Password request sent to '" . $userEntity->getDisplayname() . "'.", ['event' => 'authentication']);
             $failed = false;
         }
     } catch (\Exception $e) {
         // Notify below
     }
     if ($failed) {
         $logger->error("Failed to send password request sent to '" . $userEntity['displayname'] . "'.", ['event' => 'authentication']);
         $flash->error(Trans::__('general.phrase.error-send-password-request'));
     }
 }