public function postAction() { $db = $this->_helper->database->getAdapter(); $token = $this->getRequest()->getParam("token"); self::$logger->info("Logout requested for token ({$token})."); $response = array('success' => false, 'message' => 'An unknown error occurred'); $token_username = SecurityUtils::getUsernameForToken($db, $token); if (!isset($token_username)) { $response['success'] = false; $response['message'] = "Token ({$token}) does not match a user"; //throw new SecurityException("Token ($token) does not match a user"); } else { //$db->update('user', array('token' => null), 'username = ?'); $db->update('user', array('token' => null), $db->quoteInto('username = ?', $token_username)); $response['success'] = true; $response['message'] = "Logged out successfully."; setcookie('token', '', 0, '/'); } //sleep(2); // simulate network lag echo Zend_Json::encode($response); }
public function indexAction() { $db = $this->_helper->database->getAdapter(); //@TODO: handle the query with $this->_getParam(...) $action = $this->getRequest()->getParam("action"); self::$logger->info("security handling action ({$action})"); $response = array('success' => false); // fail by default // if ($action == 'validateToken') { // @TODO db lookup to validate token $token = $this->getRequest()->getParam("token"); $token_username = SecurityUtils::getUsernameForToken($db, $token); if (isset($token_username)) { $response = array('success' => true, 'username' => $token_username); } else { $response = array('success' => false, 'message' => 'Could not validate token'); setcookie('token', '', 0, '/'); } // } else { // self::$logger->emerg("Unknown action ($action)!"); // } echo Zend_Json::encode($response); }