public function processAction(Request $req, Application $app) { $template_data = []; $code = Response::HTTP_OK; try { $page = new Login($app['sentry']); if ($page->authenticate($req->get('email'), $req->get('password'))) { // This is for redirecting to OAuth endpoint if we arrived // as part of the Authorization Code Grant flow. if ($this->app['session']->has('redirectTo')) { return new RedirectResponse($this->app['session']->get('redirectTo')); } return $this->redirectTo('dashboard'); } $errorMessage = $page->getAuthenticationMessage(); $template_data = ['email' => $req->get('email')]; $code = Response::HTTP_BAD_REQUEST; } catch (Exception $e) { $errorMessage = $e->getMessage(); $template_data = ['email' => $req->get('email')]; $code = Response::HTTP_BAD_REQUEST; } // Set Success Flash Message $this->app['session']->set('flash', ['type' => 'error', 'short' => 'Error', 'ext' => $errorMessage]); $template_data['flash'] = $this->getFlash($app); return $this->render('login.twig', $template_data, $code); }
public function testGetVariablesGoodLogin() { $_REQUEST['email'] = $this->credentials['email']; $_REQUEST['passwd'] = $this->credentials['password']; $sentry = m::mock('Cartalyst\\Sentry\\Sentry'); $sentry->shouldReceive('authenticate')->with($this->credentials, false)->once()->andReturn($user = m::mock('Cartalyst\\Sentry\\Users\\UserInterface')); $login = new Login($sentry); $variables = $login->getViewVariables(); $this->assertArrayHasKey('redirect', $variables); }
public function processAction(Request $req, Application $app) { $template_data = array(); $code = 200; try { $page = new Login($app['sentry']); if ($page->authenticate($req->get('email'), $req->get('password'))) { return $this->redirectTo('dashboard'); } $errorMessage = $page->getAuthenticationMessage(); $template_data = array('email' => $req->get('email')); $code = 400; } catch (Exception $e) { $errorMessage = $e->getMessage(); $template_data = array('email' => $req->get('email')); $code = 400; } // Set Success Flash Message $this->app['session']->set('flash', array('type' => 'error', 'short' => 'Error', 'ext' => $errorMessage)); $template_data['flash'] = $this->getFlash($app); return $this->render('login.twig', $template_data, $code); }
public function testGetViewVariablesAuthenticatesIfRequestParamsDetectedAndReturnsFailureVariables() { $faker = $this->getFaker(); $email = $faker->email; $password = $faker->password; $sentry = $this->getSentryMock(); $sentry->shouldReceive('authenticate')->once()->with(['email' => $email, 'password' => $password], false)->andThrow(new UserNotFoundException()); $login = new Login($sentry); $_REQUEST['email'] = $email; $_REQUEST['passwd'] = $password; $viewVariables = $login->getViewVariables(); $expected = ['errorMessage' => 'Invalid Email or Password', 'email' => $email]; $this->assertSame($expected, $viewVariables); }