Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 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);
 }