public function checkAuthentication() { // Log the user in so that phprojekt recognizes us. // If the client doesn't send http headers, he probably has a cookie and assumes to be already logged in if (array_key_exists('PHP_AUTH_USER', $_SERVER)) { Phprojekt_Auth::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); } }
/** * Overwrite checkAuthentication. * We don't use the normal authentication. Instead, we have to authenticate the user based on httpauth data. */ public function checkAuthentication() { try { if (array_key_exists('PHP_AUTH_USER', $_SERVER)) { Phprojekt_Auth::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); } } catch (Phprojekt_Auth_Exception $e) { // We have to delete the stack trace here because we need to avoid logging the user's password. // This would be done because of Phprojekt_Auth::login($user, $password) throw new Phprojekt_Auth_Exception($e->getMessage(), $e->getCode()); } }
/** * Trying a login with a valid user and its password * This try has to log in the user */ public function testLogin() { $tmp = Phprojekt_Auth::login('Test', 'test'); $this->assertTrue($tmp); /* logged in needs to be true */ $this->assertTrue(Phprojekt_Auth::isLoggedIn()); }
/** * Trying a login with a valid user and its password * This try has to log in the user */ public function testLogin() { try { $tmp = Phprojekt_Auth::login('david', 'test'); } catch (Phprojekt_Auth_Exception $error) { $this->fail($error->getMessage() . " " . $error->getCode()); } $this->assertTrue($tmp); /* logged in needs to be true */ $this->assertTrue(Phprojekt_Auth::isLoggedIn()); }
/** * Executes the login by json using the username and password. * * OPTIONAL request parameters: * <pre> * - string <b>username</b> Username for login. * - string <b>password</b> Password for login. * </pre> * * The return is a string in JSON format with: * <pre> * - type => 'success' or 'error'. * - message => Success or error message. * </pre> * * @return void */ public function jsonLoginAction() { $username = Cleaner::sanitize('xss', $this->getRequest()->getParam('username', null)); $password = Cleaner::sanitize('xss', $this->getRequest()->getParam('password', null)); try { $success = Phprojekt_Auth::login($username, $password); if ($success === true) { $return = array('type' => 'success', 'message' => ''); } } catch (Phprojekt_Auth_Exception $error) { $return = array('type' => 'error', 'message' => $error->getMessage()); } $this->_helper->viewRenderer->setNoRender(); $this->view->clearVars(); Phprojekt_Converter_Json::echoConvert($return); }