public function loginAction() { //$this->_helper->layout->disableLayout(); $this->_helper->layout()->setLayout('layout-lgs'); $r = $this->getRequest(); //$returnTo = $r->getParam('returnTo'); //$this->view->returnTo = urlencode($returnTo); if ($r->isPost()) { $returnTo = $r->getParam('returnTo'); $this->view->returnTo = $returnTo; Zend_Session::rememberMe(86400); $saveHandler = Zend_Session::getSaveHandler(); $saveHandler->setLifetime(87500)->setOverrideLifetime(true); Zend_Session::start(); $username = $r->getParam('username'); $password = $r->getParam('password'); $registry = Zend_Registry::getInstance(); $application = $registry->get('application'); //ensure resource Session has/is initialized; //$application->getBootstrap()->bootstrap('identity'); $identity = $application->getBootstrap()->getResource('identity'); $authAdapter = $identity->authAdapter; $authAdapter->setIdentity($username)->setCredential($password); $auth = Zend_Auth::getInstance(); $authResult = $auth->authenticate($authAdapter); if ($authResult->isValid()) { Zend_Session::regenerateId(); // success : store database row to auth's storage $data = $authAdapter->getResultRowObject(); $auth->getStorage()->write($data); if (strpos($returnTo, '?')) { $sAddition = '&'; } else { $sAddition = '?'; } //[TODO] update last login date in tbl User //[TODO] update last login IP in tbl User $tblUser = new Kutu_Core_Orm_Table_User(); $row = $tblUser->fetchRow($tblUser->select()->where('username = ?', $username)); $ip = $this->real_ip_address(); $row->lastLoginIp = $ip; $today = date('Y-m-d h:i:s'); $row->lastLoginDate = $today; $row->save(); header("location: " . $returnTo . $sAddition . "PHPSESSID=" . Zend_Session::getId()); } else { if ($authResult->getCode() != -51) { // failure : clear database row from session Zend_Auth::getInstance()->clearIdentity(); } $this->view->errorMessage = "Login GAGAL"; } } else { Zend_Session::start(); $returnTo = $r->getParam('returnTo'); if (!empty($returnTo)) { $returnTo = urldecode($returnTo); $this->view->returnTo = $returnTo; } else { //$returnTo = KUTU_ROOT_URL.'/identity/account'; $returnTo = KUTU_ROOT_URL . '/pages'; $this->view->returnTo = $returnTo; } //check sudah login belum $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { //echo "punya identitas"; if (strpos($returnTo, '?')) { $sAddition = '&'; } else { $sAddition = '?'; } header("location: " . $returnTo . $sAddition . "PHPSESSID=" . Zend_Session::getId()); } } }