function resendVerifyEmail(Request $request, Application $app)
 {
     $repo = new UserAccountVerifyEmailRepository();
     $date = $repo->getLastSentForUserAccount($app['currentUser']);
     if ($date && $date->getTimestamp() > \TimeSource::time() - $app['config']->userAccountVerificationSecondsBetweenAllowedSends) {
         $app['flashmessages']->addMessage("Sorry, but an email was sent too recently. Please try again later.");
     } else {
         $verifyEmail = $repo->create($app['currentUser']);
         $verifyEmail->sendEmail($app, $app['currentUser']);
         $app['flashmessages']->addMessage("Verification email resent.");
     }
     return $app->redirect("/me/");
 }
 function show($id, Request $request, Application $app)
 {
     $this->build($id, $request, $app);
     $form = $app['form.factory']->create(new ActionForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $action = new ActionParser($data['action']);
             $uar = new UserAccountRepository();
             if ($action->getCommand() == 'editor' && $action->getParam(0) == 'yes') {
                 $this->parameters['user']->setIsEditor(true);
                 $uar->edit($this->parameters['user']);
                 return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
             } else {
                 if ($action->getCommand() == 'editor' && $action->getParam(0) == 'no') {
                     $this->parameters['user']->setIsEditor(false);
                     $uar->edit($this->parameters['user']);
                     return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
                 } else {
                     if ($action->getCommand() == 'sysadmin' && $action->getParam(0) == 'yes') {
                         $this->parameters['user']->setIsSystemAdmin(true);
                         $uar->edit($this->parameters['user']);
                         return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
                     } else {
                         if ($action->getCommand() == 'sysadmin' && $action->getParam(0) == 'no') {
                             $this->parameters['user']->setIsSystemAdmin(false);
                             $uar->edit($this->parameters['user']);
                             return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
                         } else {
                             if ($action->getCommand() == 'verifyemail') {
                                 $uar->verifyEmail($this->parameters['user']);
                                 return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
                             } else {
                                 if ($action->getCommand() == 'resendverificationemail' && !$this->parameters['user']->getIsEmailVerified()) {
                                     $repo = new UserAccountVerifyEmailRepository();
                                     $verify = $repo->create($this->parameters['user']);
                                     $verify->sendEmail($app, $this->parameters['user']);
                                     $app['flashmessages']->addMessage('Sent');
                                     return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
                                 } else {
                                     if ($action->getCommand() == 'close') {
                                         $uar->systemAdminShuts($this->parameters['user'], $app['currentUser'], $action->getParam(0));
                                         return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
                                     } else {
                                         if ($action->getCommand() == 'open') {
                                             $uar->systemAdminOpens($this->parameters['user'], $app['currentUser']);
                                             return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
                                         } else {
                                             if ($action->getCommand() == 'email' && filter_var($action->getParam(0), FILTER_VALIDATE_EMAIL)) {
                                                 $this->parameters['user']->setEmail($action->getParam(0));
                                                 $uar->editEmail($this->parameters['user']);
                                                 return $app->redirect('/sysadmin/user/' . $this->parameters['user']->getId());
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('sysadmin/user/show.html.twig', $this->parameters);
 }
 function verify($id, $code, Application $app)
 {
     $userRepository = new UserAccountRepository();
     if ($app['currentUser'] && $app['currentUser']->getId() == $id) {
         // we don't just do this to save a DB Query. We do this so when we mark user object
         // verified the user object available to twig is marked verified and so the user
         // doesn't see big notices on the page.
         $user = $app['currentUser'];
     } else {
         $user = $userRepository->loadByID($id);
     }
     if (!$user) {
         $app['monolog']->addError("Failed verifying account - no user");
         return $app['twig']->render('index/user/verifyFail.html.twig', array());
     }
     if ($user->getIsEmailVerified()) {
         $app['monolog']->addError("Failed verifying account - user " . $user->getId() . " - already verified");
         return $app['twig']->render('index/user/verifyDone.html.twig', array());
     }
     $repo = new UserAccountVerifyEmailRepository();
     $userVerifyCode = $repo->loadByUserAccountIDAndAccessKey($id, $code);
     if ($userVerifyCode) {
         // new way of generating access codes
         $repo->markVerifiedByUserAccountIDAndAccessKey($id, $code);
         $user->setIsEmailVerified(true);
         return $app['twig']->render('index/user/verifyDone.html.twig', array());
     } else {
         if ($user->getEmailVerifyCode() && $user->getEmailVerifyCode() == $code) {
             // old way of generating access codes
             $userRepository->verifyEmail($user);
             $user->setIsEmailVerified(true);
             return $app['twig']->render('index/user/verifyDone.html.twig', array());
         } else {
             $app['monolog']->addError("Failed verifying account - user " . $user->getId());
             return $app['twig']->render('index/user/verifyFail.html.twig', array());
         }
     }
 }