Exemplo n.º 1
0
 /**
  * Send a reset link to a given user.
  *
  * @return Response
  * @TODO: Authenticate the csrf, which must match, from the session.
  */
 public function postEmail(Container $p_dependencies)
 {
     $request = RequestWrapper::$request;
     $error = null;
     $message = null;
     $account = null;
     $email = $request->get('email');
     $ninja_name = $request->get('ninja_name');
     if (!$email && !$ninja_name) {
         $error = 'You must specify either an email or a ninja name!';
     } else {
         if ($email) {
             $account = Account::findByEmail($email);
         }
         if (!isset($account)) {
             $account = Account::findByNinjaName($ninja_name);
         }
         if ($account === null || !$account->id()) {
             $error = 'Sorry, unable to find a matching account!';
         } else {
             // PWR created with default nonce
             $request = PasswordResetRequest::generate($account);
             if ($this->sendEmail($request->nonce, $account)) {
                 $message = 'Your reset email was sent!';
             } else {
                 $error = 'Sorry, there was a problem sending to your account!  Please contact support.';
             }
         }
     }
     return new RedirectResponse('/password/?' . ($message ? 'message=' . rawurlencode($message) . '&' : '') . ($error ? 'error=' . rawurlencode($error) : ''));
 }
Exemplo n.º 2
0
 public function testAccountCanHavePlayers()
 {
     $account = Account::findByNinjaName($this->test_ninja_name);
     $pcs = $account->getCharacters();
     $this->assertNotEmpty($pcs);
     $this->assertInstanceOf(Player::class, reset($pcs));
 }
Exemplo n.º 3
0
 public function testPostEmailCanGetAnAccountUsingANinjaName()
 {
     $req = Request::create('/password/post_email/');
     $req->setMethod('POST');
     $char = TestAccountCreateAndDestroy::char();
     $ninja_name = $char->name();
     $req->request->set('ninja_name', $ninja_name);
     RequestWrapper::inject($req);
     $account = Account::findByNinjaName($ninja_name);
     $this->assertNotEmpty($account->id(), 'Unable to find id for newly created account.');
     $controller = new PasswordController();
     $controller->postEmail($this->m_dependencies);
     // Check for a matching request for the appropriate account.
     $pwrr = PasswordResetRequest::where('_account_id', '=', $account->id())->first();
     $this->assertNotEmpty($pwrr, 'Fail: Unable to find a matching password reset request  for account_id: [' . $this->account->id() . '].');
     $this->nonce = $pwrr->nonce;
 }