Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function register(Application $app)
 {
     $app['email.mapper'] = $app->share(function (Application $app) {
         return new EmailMapper($app['db'], new EmailEntity());
     });
     $app['email.service'] = $app->share(function (Application $app) {
         $service = new EmailService();
         $service->setEmailMapper($app['email.mapper'])->setEmailConfig($app['config']->load('email'))->setResque($app['resque']);
         return $service;
     });
     $app['email.sender'] = $app->share(function (Application $app) {
         $emailConfig = $app['config']->load('email');
         if (!($apiKey = Arr::path($emailConfig, 'sender.mandrill.apiKey'))) {
             return;
         }
         $sender = new MandrillSender(new Mandrill($apiKey), $app['email.mapper']);
         $sender->setConfig($emailConfig);
         return $sender;
     });
     $app['email.send'] = $app->share(function (Application $app) {
         $command = new SendEmailCommand('email:send');
         $command->setEmailMapper($app['email.mapper']);
         if ($app['email.sender']) {
             $command->setEmailSender($app['email.sender']);
         }
         return $command;
     });
 }
 /**
  * Send reset password email
  *
  * @param  Request $request
  * @return array
  */
 public function post(Request $request)
 {
     // Validate user
     $email = Arr::get($this->getContentAsArray($request), 'email');
     $user = $this->userService->findByEmail($email);
     if (!$user) {
         return $this->createNotFoundResponse();
     }
     // If a token exists that won't expire in the next 5 minutes, send it
     $token = $this->userService->findTokenBy(['user_id' => $user->getId(), 'token_type_id' => TokenEntity::TYPE_RESET_PASSWORD, ['expires', '>', time() + 5 * 60]]);
     // Otherwise create a new token
     if (!$token) {
         $token = $this->userService->createUserToken(['user_id' => $user->getId(), 'token_type_id' => TokenEntity::TYPE_RESET_PASSWORD, 'expires' => strtotime('+1 day', time())]);
     }
     $this->resetPasswordView->setUserToken($token);
     $email = $this->emailService->createFromArray(['recipient_email' => $user->getEmail(), 'subject' => 'Reset Your Password', 'message' => (string) $this->resetPasswordView]);
     $this->emailService->enqueueSendEmailJob($email);
     return $this->create204Response(204, '');
 }