Exemplo n.º 1
0
 public function prepare()
 {
     $sessionManager = $this->getServiceLocator()->get('Session\\Services\\SessionManager');
     $userManager = $this->getServiceLocator()->get('User\\Services\\UserManager');
     $storage = $sessionManager->getStorage($userManager);
     if ($storage->has('user')) {
         $auth = new Authentication($this->getServiceLocator());
         $user = $storage->get('user');
         if ($auth->authenticate($user->getUsername(), $user->getPassword())) {
             $userManager->setUser($storage->get('user'));
         } else {
             $storage->reset('user');
         }
     }
 }
 public function loginAction()
 {
     if ($_POST) {
         $router = $this->getServiceLocator()->get('Router\\Services\\Router');
         $userManager = $this->getServiceLocator()->get('User\\Services\\UserManager');
         $auth = new Authentication($this->getServiceLocator());
         $usernameOrEmail = $_POST['user'];
         $password = md5($_POST['pass']);
         if ($user = $auth->authenticate($usernameOrEmail, $password)) {
             $userManager->login($user);
             $router->redirect(self::LOGIN_CALLBACK_ROUTE);
         }
         return array('user' => $usernameOrEmail, 'message' => 'Invalid username or password!');
     } else {
         return array('message' => '');
     }
 }