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());
         }
     }
 }