コード例 #1
0
 function test2()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userAccountResetRepository = new UserAccountResetRepository();
     # Test1: recently unused is null
     TimeSource::mock(2013, 1, 1, 1, 0, 1);
     $x = $userAccountResetRepository->loadRecentlyUnusedSentForUserAccountId($user->getId(), 180);
     $this->assertNull($x);
     # Test2: Request one
     TimeSource::mock(2013, 1, 1, 1, 0, 2);
     $userAccountReset = $userAccountResetRepository->create($user);
     #Test 3: recently unused has one
     TimeSource::mock(2013, 1, 1, 1, 0, 3);
     $x = $userAccountResetRepository->loadRecentlyUnusedSentForUserAccountId($user->getId(), 180);
     $this->assertTrue($x != null);
     # Test4: days pass. recently unused is null again
     TimeSource::mock(2013, 1, 5, 1, 0, 5);
     $x = $userAccountResetRepository->loadRecentlyUnusedSentForUserAccountId($user->getId(), 180);
     $this->assertNull($x);
 }
コード例 #2
0
 function reset($id, $code, Request $request, Application $app)
 {
     $userRepository = new UserAccountRepository();
     if ($app['currentUser'] && $app['currentUser']->getId() == $id) {
         // We do this to save a DB Query
         $user = $app['currentUser'];
     } else {
         $user = $userRepository->loadByID($id);
     }
     if (!$user) {
         $app['monolog']->addError("Failed resetting account - user not known");
         return $app['twig']->render('index/user/resetFail.html.twig', array());
     }
     $userAccountResetRepository = new UserAccountResetRepository();
     $userAccountReset = $userAccountResetRepository->loadByUserAccountIDAndAccessKey($id, $code);
     if (!$userAccountReset) {
         $app['monolog']->addError("Failed resetting account - user " . $user->getId() . " - code wrong");
         return $app['twig']->render('index/user/resetFail.html.twig', array());
     }
     if ($userAccountReset->getIsAlreadyUsed()) {
         $app['monolog']->addError("Failed resetting account - user " . $user->getId() . " - code already used");
         return $app['twig']->render('index/user/resetFail.html.twig', array());
     }
     $form = $app['form.factory']->create(new ResetUserForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $user->setPassword($data['password1']);
             $userRepository->resetAccount($user, $userAccountReset);
             return $app['twig']->render('index/user/resetDone.html.twig', array('user' => $user));
         }
     }
     return $app['twig']->render('index/user/reset.html.twig', array('form' => $form->createView(), 'user' => $user));
 }