protected function returnResult() { if (Request::isAjax()) { Responder::sendJSON(array()); } Responder::redirectToPage(); }
protected function returnResult() { if (Request::isAjax()) { $ret = array('alert' => '@@Approved@@'); $ret['reload'] = 1000; Responder::sendJSON($ret); exit; } Responder::redirectToPage(); }
protected function returnResult() { /** * @todo translate string */ $message = '@@Item deleted@@'; $requested = 'You cannot delete question that already has answers.<br>A request to delete this question has been sent to moderators<br> It will be up to moderators to either delete or edit or close the question'; if (Request::isAjax()) { $res = !$this->requested ? $message : $requested; $ret = array('alert' => $res); if (!empty($this->posterDetails)) { $ret['alert'] .= $this->posterDetails; } else { /** * If item was actually deleted then * add 'reload' => 2 to return * which will cause page reload * in 1.5 seconds. */ if (!$this->requested) { $ret['reload'] = 1500; } } Responder::sendJSON($ret); } Responder::redirectToPage($this->Resource->getUrl()); }
/** * Process submitted Answer * * @return void */ protected function process() { $formVals = $this->Form->getSubmittedValues(); d('formVals: ' . print_r($formVals, 1)); $oAdapter = new AnswerParser($this->Registry); try { $Answer = $oAdapter->parse(new SubmittedAnswerWWW($this->Registry, $formVals)); d('cp created new answer: ' . \print_r($Answer->getArrayCopy(), 1)); d('ans id: ' . $Answer->getResourceId()); /** * In case of ajax we need to send out a * parsed html block with one answer * under the 'answer' key * * In case of non-ajax redirect back to question page, * hopefully the new answer will show up there too */ if (Request::isAjax()) { $aAnswer = $Answer->getArrayCopy(); /** * Add edit and delete tools because * Viewer already owns this comment and is * allowed to edit or delete it right away. * Javascript that usually dynamically adds these tools * is not going to be fired, so these tools * must already be included in the returned html * */ $aAnswer['edit_delete'] = ' <span class="ico del ajax" title="@@Delete@@">@@delete@@</span> <span class="ico edit ajax" title="@@Edit@@">@@edit@@</span>'; $a = array('answer' => \tplAnswer::parse($aAnswer)); d('before sending out $a: ' . print_r($a, 1)); Responder::sendJSON($a); } else { Responder::redirectToPage($this->Question->getUrl()); } } catch (\Lampcms\AnswerParserException $e) { d('Got AnswerParserException ' . $e->getMessage()); /** * The setFormError in Form sends our json in * case of Ajax request, so we don't have to * worry about it here */ $this->Form->setFormError($e->getMessage()); $this->showFormWithErrors(); } }
protected function returnResult() { /** * @todo translate string */ $message = 'Topic retagged successfully'; if (Request::isAjax()) { $ret = array('reload' => 100); //'alert' => $message, Responder::sendJSON($ret); } Responder::redirectToPage($this->Question->getUrl()); }
protected function main() { $locale = $this->Request->get('locale'); if (isset($_SESSION['guest_block'])) { unset($_SESSION['guest_block']); } if (isset($_SESSION['langs'])) { unset($_SESSION['langs']); } if (isset($_SESSION['welcome'])) { unset($_SESSION['welcome']); } if (isset($_SESSION['welcome_guest'])) { unset($_SESSION['welcome_guest']); } $_SESSION['locale'] = $locale; $this->Registry->Locale->set($locale); Cookie::set('locale', $locale); if (!empty($_SESSION['langs'])) { unset($_SESSION['langs']); } //echo __METHOD__.' '.__LINE__.' getting Tr object for locale: '.$locale; //$this->Tr = Translator::factory($this->Registry, $locale); //echo __METHOD__.' '.__LINE__.' '.print_r($this->Tr->getMessages(), 1);//$this->Tr->get('Questions'); Responder::redirectToPage($this->Request->get('redirect')); }
/** * Generate oAuth request token * and redirect to Blogger for authentication * * @return object $this * * @throws Exception in case something goes wrong during * this stage */ protected function step1() { try { // State 0 - Generate request token and redirect user to Blogger to authorize $url = $_SESSION['blogger_oauth'] = $this->oAuth->getRequestToken(self::REQUEST_TOKEN_URL . $this->callback); d('$_SESSION[\'blogger_oauth\']: ' . print_r($_SESSION['blogger_oauth'], 1)); if (!empty($_SESSION['blogger_oauth']) && !empty($_SESSION['blogger_oauth']['oauth_token'])) { Responder::redirectToPage(self::AUTHORIZE_URL . '?oauth_token=' . $_SESSION['blogger_oauth']['oauth_token'] . '&oauth_callback=' . $this->callback); } else { /** * Here throw regular Exception, not Lampcms\Exception * so that it will be caught ONLY by the index.php and formatted * on a clean page, without any template */ throw new \Exception("Failed fetching request token, response was: " . $this->oAuth->getLastResponse()); } } catch (\OAuthException $e) { e('OAuthException: ' . $e->getMessage() . ' ' . print_r($e, 1)); throw new \Exception('Something went wrong during authorization. Please try again later' . $e->getMessage()); } return $this; }
protected function returnResult() { /** * @todo translate string */ $message = '@@Question closed@@'; $requested = 'A request to close this question has been sent to moderators<br> The final decision about closing the question or leaving it open will be up to moderators'; if (Request::isAjax()) { $res = !$this->requested ? $message : $requested; $ret = array('alert' => $res); /** * If item was actually deleted then * add 'reload' => 2 to return * which will cause page reload * in 1.5 seconds. */ if (!$this->requested) { $ret['reload'] = 1500; } Responder::sendJSON($ret); } Responder::redirectToPage($this->Resource->getUrl()); }
public function main() { /** * Will not check for the valid 'form token' * in this form because potential * hacher has nothing to gain by * exploiting CSRF of a login form because * the user using this form is be definition * 'not yet logged in', so there is really * nothing to gain by tricking someonw to login */ $bRemember = isset($this->Request['chkRemember']) ? (bool) $this->Request['chkRemember'] : false; d('$bRemember ' . $bRemember . ' $this->Request ' . print_r($this->Request->getArrayCopy(), 1)); try { $oCheckLogin = new UserAuth($this->Registry); $User = $oCheckLogin->validateLogin($this->Request['login'], $this->Request['pwd']); /** * If user logged in that means he got the email * with password, * thus we confirmed email address * and can activate user */ $User->activate(); } catch (\Lampcms\LoginException $e) { /** * @todo may add extra setting to !config.ini to send login errors * to special dedicated email address that will receive all security (hacking attempts) * related errors. */ d('Login error: ' . $e->getMessage() . ' in file: ' . $e->getFile() . ' on line: ' . $e->getLine()); if (Request::isAjax()) { Responder::sendJSON(array('error' => $e->getMessage())); } $_SESSION['login_error'] = $e->getMessage(); d('$_SESSION[login_error] ' . $_SESSION['login_error']); Responder::redirectToPage(); } d('User: '******'onUserLogin'); if ($bRemember) { \Lampcms\Cookie::sendLoginCookie($User->getUid(), $User['rs']); } Responder::redirectToPage(); }
/** * * Process submitted form values */ protected function process() { $formVals = $this->Form->getSubmittedValues(); d('formVals: ' . print_r($formVals, 1)); $oAdapter = new QuestionParser($this->Registry); try { $Question = $oAdapter->parse(new SubmittedQuestionWWW($this->Registry, $formVals)); d('cp created new question'); d('title: ' . $Question['title']); Responder::redirectToPage($Question->getUrl()); } catch (QuestionParserException $e) { $this->Form->setFormError($e->getMessage()); $this->showFormWithErrors(); } }
protected function returnResult() { Responder::redirectToPage($this->Resource->getUrl()); }
/** * Generate oAuth request token * and redirect to Linkedin for authentication * * @throws \Exception in case something goes wrong during * this stage * @return object $this */ protected function step1() { d('cp'); try { $_SESSION['linkedin_oauth'] = $this->oAuth->getRequestToken(self::REQUEST_TOKEN_URL, $this->callback); $aDebug = $this->oAuth->getLastResponseInfo(); d('debug: ' . print_r($aDebug, 1)); d('$_SESSION[\'linkedin_oauth\']: ' . \print_r($_SESSION['linkedin_oauth'], 1)); if (!empty($_SESSION['linkedin_oauth']) && !empty($_SESSION['linkedin_oauth']['oauth_token'])) { d('cp'); Responder::redirectToPage(self::AUTHORIZE_URL . '?oauth_token=' . $_SESSION['linkedin_oauth']['oauth_token']); } else { /** * Here throw regular Exception, not Lampcms\Exception * so that it will be caught ONLY by the index.php and formatted * on a clean page, without any template */ throw new \Exception("Failed fetching request token, response was: " . $this->oAuth->getLastResponse()); } } catch (\OAuthException $e) { e('OAuthException: ' . $e->getMessage()); $aDebug = $this->oAuth->getLastResponseInfo(); d('debug: ' . print_r($aDebug, 1)); throw new \Exception('Something went wrong during authorization. Please try again later' . $e->getMessage()); } return $this; }
protected function setReturn() { if (Request::isAjax()) { $ret = array('alert' => 'User group updated', 'reload' => 1000); Responder::sendJSON($ret); } Responder::redirectToPage(); }
/** * Unsets all session variables and unsets some cookies * This is all that is needed to logout * * @param array $arrParams array or GET or POST parameters */ public function main() { $this->Registry->Dispatcher->post($this, 'onBeforeUserLogout'); /** * Don't forget about the 'dnd' cookies * that may have been set previosly * Whith dnd set to 1 a user may register * with external auth and will never * be asked to provide email address * This is designed so that a user may say, hey, don't * bother me with this again, I don't want to provide * an email address * * But once the user logges out * treat them as another guest! */ $aDelete = array('uid', 'dnd'); /** * If current viewer is logged in * with Google Friend Connect * then the logout process is somewhat * different: we need to delete user's fcauth cookie(s) * */ if ($this->Registry->Viewer instanceof UserGfc) { $GfcSiteID = $this->Registry->Ini->GFC_ID; if (!empty($GfcSiteID)) { $gfc = sprintf(self::GFC_SIGNOUT, $GfcSiteID); $gfc = Responder::PAGE_OPEN . $gfc . Responder::PAGE_CLOSE; d('sending out GFC Logout page: ' . $gfc); $fcauthSession = 'fcauth' . $GfcSiteID . '-s'; $fcauthRegular = 'fcauth' . $GfcSiteID; $aDelete[] = $fcauthSession; $aDelete[] = $fcauthRegular; } } //d('logging out Facebook User'); //$aFB = $this->Registry->Ini->getSection('FACEBOOK'); //if(!empty($aFB) && !empty($aFB['APP_ID'])){ // $fb_cookie = 'fbsr_'.$aFB['APP_ID']; // d('deleting Facebook cookie '.$fb_cookie.' len: '.strlen($fb_cookie)); // $aDelete[] = $fb_cookie; //} d('Delete these cookies: ' . print_r($aDelete, 1)); Cookie::delete($aDelete); /** * Get copy of user data * because we going to need * it's values AFTER the user loggs * out and after the $this->oViewer has been destroyed * */ $aUser = $this->Registry->Viewer->getArrayCopy(); $this->Registry->Viewer = null; session_destroy(); $_SESSION = array(); $this->Registry->Dispatcher->post($this, 'onUserLogout', $aUser); d('Logged out SESSION: ' . print_r($_SESSION, 1)); /*if (Request::isAjax()) { $sLoginForm = \Lampcms\LoginForm::makeLoginForm($this->Registry); $arrJSON = array('message'=> $sLoginForm); d('sending json: '.$sLoginForm); Responder::sendJSON($arrJSON); }*/ /** * For Google Friend Connect sendout * the html with logout JavaScript - that's * the only right way to logout */ if (isset($gfc)) { exit($gfc); } Responder::redirectToPage('/index.php?logout=1'); }
/** * Generate oAuth request token * and redirect to twitter for authentication * * @throws Exception * @throws \Exception in case something goes wrong during * this stage * @return object $this */ protected function startOauthDance() { try { $uri = $this->Registry->Ini->SITE_URL . '{_WEB_ROOT_}/{_logintwitter_}'; $routerCallback = $this->Registry->Router->getCallback(); $callbackUrl = $routerCallback($uri); /** * urlencode() is not longer necessary since now callback url is passed in header * but if you are having problems with this method try to uncomment urlencode() line below * This behaviour may depend on version of php oauth extension */ //$callbackUrl = \urlencode($callbackUrl); d('$callbackUrl' . $callbackUrl); // State 0 - Generate request token and redirect user to Twitter to authorize $_SESSION['oauth'] = $this->oAuth->getRequestToken(self::REQUEST_TOKEN_URL, $callbackUrl); $aDebug = $this->oAuth->getLastResponseInfo(); d('debug: ' . \print_r($aDebug, 1)); d('$_SESSION[\'oauth\']: ' . print_r($_SESSION['oauth'], 1)); if (!empty($_SESSION['oauth']) && !empty($_SESSION['oauth']['oauth_token'])) { $authorizeUrl = self::AUTHORIZE_URL . '?oauth_token=' . $_SESSION['oauth']['oauth_token']; d('redirecting to url: ' . $authorizeUrl); Responder::redirectToPage($authorizeUrl); } else { /** * Here throw regular Exception, not Lampcms\Exception * so that it will be caught ONLY by the index.php and formatted * on a clean page, without any template */ throw new \Exception("@@Failed fetching request token, response was@@: " . $this->oAuth->getLastResponse()); } } catch (\OAuthException $e) { e('OAuthException: ' . $e->getMessage()); $aDebug = $this->oAuth->getLastResponseInfo(); d('debug: ' . print_r($aDebug, 1)); throw new \Exception('@@Something went wrong during authorization. Please try again later@@' . $e->getMessage()); } return $this; }
protected function returnResult() { if (Request::isAjax()) { $message = '@@User Shredded@@<hr>@@Banned IPs@@:' . implode('<br>', array_keys($this->aIPs)) . '<hr><br>@@Countries@@: ' . implode('<br>', array_keys($this->aCountries)); Responder::sendJSON(array('alert' => $message)); } Responder::redirectToPage(); }
protected function handleReturn() { $isAjax = Request::isAjax(); d('$isAjax: ' . $isAjax); if ($isAjax) { $ret = array('vote' => array('v' => $this->Resource->getScore(), 't' => $this->resType, 'rid' => $this->resID)); Responder::sendJSON($ret); } Responder::redirectToPage($this->Resource->getUrl()); }
protected function main() { $this->setApi(); $email = $this->Registry->Viewer->email; $this->Form = new \Lampcms\Forms\Apiclient($this->Registry); if ($this->Form->isSubmitted() && $this->Form->validate()) { d('$this->oApi: ' . print_r($this->oApi->getArrayCopy(), 1)); $this->save(); $this->Registry->Dispatcher->post($this->Form, 'onApiClientSave'); $url = '/index.php?a=viewapp&app_id=' . $this->oApi['_id']; Responder::redirectToPage($url); } else { $this->setForm(); $this->aPageVars['body'] = $this->Form->getForm(); } }
protected function returnResult() { $message = '@@Thank you for caring!<br>Moderators have been notified@@'; if (Request::isAjax()) { Responder::sendJSON(array('alert' => $message)); } Responder::redirectToPage($this->Resource->getUrl()); }
/** * Handle creation of new account * OR logging in existing user * * @return void */ protected function main() { if (is_array($_GET) && !empty($_GET['error'])) { d('Received error response from Google API: ' . $_GET['error']); $this->closeWindow(''); } $this->configSection = $this->Registry->Ini->getSection('GOOGLE_API'); $tplRedirect = '{_WEB_ROOT_}/{_logingoogle_}/'; $uriMapper = $this->Router->getCallback(); $this->redirectUri = $uriMapper($tplRedirect, true); $this->scopes = $this->configSection['SCOPE']; if (!isset($_GET['code'])) { Responder::redirectToPage($this->makeAuthUrl()); } else { $this->validateState(); $this->getToken(); $this->getUserInfo(); $this->createOrUpdate(); } }
/** * Redirect back to the question page * */ protected function redirect() { Responder::redirectToPage($this->Question->getUrl()); }
protected function main() { $locale = $this->Registry->Router->getSegment(1); /** * Redirect url is passed as query string (?redirect=http://someurl) * because we cannot pass the url as a uri segment because url itself * has many segments */ $redirect = $_GET['redirect']; if (isset($_SESSION['guest_block'])) { unset($_SESSION['guest_block']); } if (isset($_SESSION['langs'])) { unset($_SESSION['langs']); } if (isset($_SESSION['welcome'])) { unset($_SESSION['welcome']); } if (isset($_SESSION['welcome_guest'])) { unset($_SESSION['welcome_guest']); } $_SESSION['locale'] = $locale; $this->Registry->Locale->set($locale); Cookie::set('locale', $locale, 126144000); if (!empty($_SESSION['langs'])) { unset($_SESSION['langs']); } Responder::redirectToPage($redirect); }