X-Git-Url: https://dev.renevier.net/gitweb.cgi?a=blobdiff_plain;f=application%2Fcontrollers%2Fhelpers%2FSyjUserManager.php;fp=application%2Fcontrollers%2Fhelpers%2FSyjUserManager.php;h=427e6faa07434d3e9f215e3f3b6adad67edb6c17;hb=0722c496ca63f30937427e3bf8fbdd5cfee2c83d;hp=0000000000000000000000000000000000000000;hpb=0fb09adccd5c3b305d56f1b267dbd3bf836fd17f;p=syj.git diff --git a/application/controllers/helpers/SyjUserManager.php b/application/controllers/helpers/SyjUserManager.php new file mode 100644 index 0000000..427e6fa --- /dev/null +++ b/application/controllers/helpers/SyjUserManager.php @@ -0,0 +1,71 @@ +setIdentity($username)->setCredential($hash); + $auth = Zend_Auth::getInstance(); + $result = $auth->authenticate($authAdapter); + if (!$result->isValid()) { + self::$_current = null; + return false; + } + $userid = $authAdapter->getResultRowObject('id')->id; + $userMapper = new Syj_Model_UserMapper(); + $user = new Syj_Model_User(); + if (!$userMapper->find($userid, $user)) { + throw new Zend_Exception(); + } + + if (!isset ($_COOKIE['syj_user']) or (!isset ($_COOKIE['syj_hashpass']))) { + setcookie("syj_user", $username, 0, "", "", false, true); + setcookie("syj_hashpass", $hash, 0, "", "", false, true); + } + self::$_current = $user; + return true; + } + + static public function logout() { + self::$_current = null; + if (isset ($_COOKIE['syj_user'])) { + setcookie ('syj_user', "", time() - 3600, "" , "",false, true); + } + if (isset ($_COOKIE['syj_hashpass'])) { + setcookie ('syj_hashpass', "", time() - 3600, "" , "",false, true); + } + } + + static public function current() { + if (self::$_current === -1) { + if ((!isset ($_COOKIE['syj_user'])) || (!isset ($_COOKIE['syj_hashpass'])) + || (!self::validate($_COOKIE['syj_user'], $_COOKIE['syj_hashpass']))) { + self::logout(); + } + } + return self::$_current; + } + + public function needsLogin() { + if (self::current()) { + return; + } + + $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); + $view = $viewRenderer->view; + $request = $this->getRequest(); + + $encodeduri = $view->UriPath(true); + $loginurl = $view->addParamToUrl($view->baseUrl() . '/' . 'login', 'redirect', $encodeduri); + $translator = Zend_Registry::get('Zend_Translate'); + $this->getActionController()->getHelper('Redirector')->gotoURL($loginurl, array('prependBase' => false)); + } + +}