'post_reset' => 'postReset', ], ], */ use NinjaWars\core\control\PasswordController; use NinjaWars\core\data\PasswordResetRequest; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RedirectResponse; $command = (string) in('command'); $controller = new PasswordController(); $request = Request::createFromGlobals(); switch (true) { case $command == 'post_reset': $response = $controller->postReset($request); break; case $command == 'reset': $response = $controller->getReset($request); break; case $command == 'email': $response = $controller->postEmail($request); break; default: $command == 'index'; $response = $controller->index($request); break; } if ($response instanceof RedirectResponse) { $response->send(); } else { display_page($response['template'], $response['title'], $response['parts'], $response['options']); }
public function testGetResetWithAValidTokenDisplaysAFilledInPasswordResetForm() { $token = '4447744'; // Generate a password reset req to be matched! PasswordResetRequest::generate($this->account, $token); $matched_req = PasswordResetRequest::match($token); $this->assertNotEmpty($matched_req); // Symfony Request $request = Request::create('/resetpassword.php'); $request->setMethod('POST'); $request->query->set('token', $token); // get a response $controller = new PasswordController(); $response = $controller->getReset($request); // Response should contain an array with the token in the parts. $this->assertFalse($response instanceof RedirectResponse, 'Redirection to the url [' . ($response instanceof RedirectResponse ? $response->getTargetUrl() : null) . '] was the invalid result of password reset.'); $this->assertTrue(is_array($response), 'Response was not a ViewSpec Array'); $this->assertNotEmpty($response['parts']); $this->assertEquals($response['parts']['token'], $token); }
public function testGetResetWithAValidTokenDisplaysAFilledInPasswordResetForm() { $token = $this->nonce = '4447744'; // Generate a password reset req to be matched! PasswordResetRequest::generate($this->account, $token); $matched_req = PasswordResetRequest::match($token); $this->assertNotEmpty($matched_req); // Symfony Request $request = Request::create('/password/get_reset/'); $request->setMethod('POST'); $request->query->set('token', $token); RequestWrapper::inject($request); // get a response $controller = new PasswordController(); $response = $controller->getReset($this->m_dependencies); // Response should contain an array with the token in the parts. $this->assertFalse($response instanceof RedirectResponse, 'Redirection to the url [' . ($response instanceof RedirectResponse ? $response->getTargetUrl() : null) . '] was the invalid result of password reset.'); $this->assertInstanceOf(StreamedViewResponse::class, $response, 'Response was not a StreamedViewResponse'); $reflection = new \ReflectionProperty(get_class($response), 'data'); $reflection->setAccessible(true); $response_data = $reflection->getValue($response); $this->assertNotEmpty($response_data); $this->assertEquals($response_data['token'], $token); }