Exemplo n.º 1
0
 /**
  * Makes permanent redirect to provided URL or URI.
  *
  * @param string $redirectTo
  */
 public function redirect($redirectTo = null)
 {
     // if empty redirect location -> current URI is used
     if ($redirectTo === null) {
         $redirectTo = OW::getRequest()->getRequestUri();
     }
     // if URI is provided need to add site home URL
     if (!strstr($redirectTo, 'http://') && !strstr($redirectTo, 'https://')) {
         $redirectTo = OW::getRouter()->getBaseUrl() . UTIL_String::removeFirstAndLastSlashes($redirectTo);
     }
     UTIL_Url::redirect($redirectTo);
 }
Exemplo n.º 2
0
 public function redirect()
 {
     if (OW::getRequest()->isAjax()) {
         $handler = OW::getRequestHandler()->getHandlerAttributes();
         if ($handler[OW_RequestHandler::ATTRS_KEY_CTRL] == 'BASE_CTRL_User' && $handler[OW_RequestHandler::ATTRS_KEY_ACTION] == 'ajaxSignIn') {
             OW::getSession()->delete(ANTIBRUTEFORCE_BOL_Service::SESSION_NAME);
             exit(json_encode(array('result' => TRUE, 'message' => '')));
         } else {
             if ($handler[OW_RequestHandler::ATTRS_KEY_CTRL] == 'BASE_CTRL_Captcha' && $handler[OW_RequestHandler::ATTRS_KEY_ACTION] == 'ajaxResponder') {
                 OW::getSession()->delete(ANTIBRUTEFORCE_BOL_Service::SESSION_NAME);
                 exit(json_encode(array('result' => FALSE, 'reload' => OW::getRouter()->urlForRoute('antibruteforce.authenticate_fail'))));
             } else {
                 if ($handler[OW_RequestHandler::ATTRS_KEY_CTRL] == 'SMARTCAPTCHA_CTRL_SmartCaptcha' && $handler[OW_RequestHandler::ATTRS_KEY_ACTION] == 'ajaxResponder') {
                     OW::getSession()->delete(ANTIBRUTEFORCE_BOL_Service::SESSION_NAME);
                     exit(json_encode(array('result' => FALSE, 'reload' => OW::getRouter()->urlForRoute('antibruteforce.authenticate_fail'))));
                 }
             }
         }
     } else {
         OW::getSession()->delete(ANTIBRUTEFORCE_BOL_Service::SESSION_NAME);
         UTIL_Url::redirect(OW::getRouter()->urlForRoute('antibruteforce.authenticate_fail'));
     }
 }
Exemplo n.º 3
0
 /**
  * Makes header redirect to provided URL or URI.
  *
  * @param string $redirectTo
  */
 public function redirect($redirectTo = null, $switchContextTo = false)
 {
     if ($switchContextTo !== false && in_array($switchContextTo, array(self::CONTEXT_DESKTOP, self::CONTEXT_MOBILE))) {
         OW::getSession()->set(self::CONTEXT_NAME, $switchContextTo);
     }
     // if empty redirect location -> current URI is used
     if ($redirectTo === null) {
         $redirectTo = OW::getRequest()->getRequestUri();
     }
     // if URI is provided need to add site home URL
     if (!strstr($redirectTo, 'http://') && !strstr($redirectTo, 'https://')) {
         $redirectTo = OW::getRouter()->getBaseUrl() . UTIL_String::removeFirstAndLastSlashes($redirectTo);
     }
     UTIL_Url::redirect($redirectTo);
 }
Exemplo n.º 4
0
 /**
  * Returns processed catch all requests attributes.
  *
  * @return string
  */
 protected function processCatchAllRequestsAttrs()
 {
     if (empty($this->catchAllRequestsAttributes)) {
         return null;
     }
     $catchRequest = true;
     $lastKey = array_search(end($this->catchAllRequestsAttributes), $this->catchAllRequestsAttributes);
     foreach ($this->catchAllRequestsExcludes[$lastKey] as $exclude) {
         if ($exclude[self::CATCH_ALL_REQUEST_KEY_CTRL] == $this->handlerAttributes[self::ATTRS_KEY_CTRL]) {
             if ($exclude[self::CATCH_ALL_REQUEST_KEY_ACTION] === null || $exclude[self::CATCH_ALL_REQUEST_KEY_ACTION] == $this->handlerAttributes[self::ATTRS_KEY_ACTION]) {
                 if ($exclude[self::CATCH_ALL_REQUEST_KEY_PARAMS] === null || $exclude[self::CATCH_ALL_REQUEST_KEY_PARAMS] == $this->handlerAttributes[self::ATTRS_KEY_VARLIST]) {
                     $catchRequest = false;
                     break;
                 }
             }
         }
     }
     if ($catchRequest) {
         if (isset($this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_REDIRECT]) && (bool) $this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_REDIRECT]) {
             $route = isset($this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_ROUTE]) ? trim($this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_ROUTE]) : null;
             $params = isset($this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_PARAMS]) ? $this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_PARAMS] : array();
             $redirectUrl = $route !== null ? OW::getRouter()->urlForRoute($route, $params) : OW::getRouter()->urlFor($this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_CTRL], $this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_ACTION], $params);
             $redirectUrl = OW::getRequest()->buildUrlQueryString($redirectUrl, array('back_uri' => OW::getRequest()->getRequestUri()));
             if (isset($this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_JS]) && (bool) $this->catchAllRequestsAttributes[$lastKey][self::CATCH_ALL_REQUEST_KEY_JS]) {
                 // TODO resolve hotfix
                 // hotfix for splash screen + members only case
                 if (array_key_exists('base.members_only', $this->catchAllRequestsAttributes)) {
                     if (in_array($this->handlerAttributes[self::CATCH_ALL_REQUEST_KEY_CTRL], array('BASE_CTRL_User', 'BASE_MCTRL_User')) && $this->handlerAttributes[self::CATCH_ALL_REQUEST_KEY_ACTION] === 'standardSignIn') {
                         $backUri = isset($_GET['back_uri']) ? $_GET['back_uri'] : OW::getRequest()->getRequestUri();
                         OW::getDocument()->addOnloadScript("window.location = '" . OW::getRequest()->buildUrlQueryString($redirectUrl, array('back_uri' => $backUri)) . "'");
                         return null;
                     } else {
                         $ru = OW::getRequest()->buildUrlQueryString(OW::getRouter()->urlForRoute('static_sign_in'), array('back_uri' => OW::getRequest()->getRequestUri()));
                         OW::getApplication()->redirect($ru);
                     }
                 }
                 OW::getDocument()->addOnloadScript("window.location = '" . $redirectUrl . "'");
                 return null;
             }
             UTIL_Url::redirect($redirectUrl);
         }
         return $this->getCatchAllRequestsAttributes($lastKey);
     }
     return null;
 }
Exemplo n.º 5
0
 public function checkSession()
 {
     $stamp = BOL_QuestionService::getInstance()->getQuestionsEditStamp();
     $sessionStamp = OW::getSession()->get(self::SESSION_START_STAMP);
     if (!empty($sessionStamp) && $stamp > $sessionStamp) {
         OW::getSession()->delete(self::SESSION_ALL_QUESTION_LIST);
         OW::getSession()->delete(self::SESSION_JOIN_DATA);
         OW::getSession()->delete(self::SESSION_JOIN_STEP);
         OW::getSession()->delete(self::SESSION_REAL_QUESTION_LIST);
         OW::getSession()->delete(self::SESSION_START_STAMP);
         if (OW::getRequest()->isPost()) {
             UTIL_Url::redirect(OW::getRouter()->urlForRoute('base_join'));
         }
     }
 }
Exemplo n.º 6
0
    public function popup()
    {
        $document = OW::getDocument();
        $document->getMasterPage()->setTemplate(OW::getThemeManager()->getMasterPageTemplate(OW_MasterPage::TEMPLATE_BLANK));
        if (isset($_GET['error'])) {
            $document->addOnloadScript('window.close();');
            $this->assign('close', true);
            return;
        }
        //setting parameters
        $authcode = $_GET["code"];
        $clientId = OW::getConfig()->getValue('contactimporter', 'google_client_id');
        $clientSecret = OW::getConfig()->getValue('contactimporter', 'google_client_secret');
        $redirectUri = OW::getRouter()->urlForRoute('contact-importer-google-oauth');
        $fields = array('code' => urlencode($authcode), 'client_id' => urlencode($clientId), 'client_secret' => urlencode($clientSecret), 'redirect_uri' => urlencode($redirectUri), 'grant_type' => urlencode('authorization_code'));
        //url-ify the data for the POST
        $fieldsString = '';
        foreach ($fields as $key => $value) {
            $fieldsString .= $key . '=' . $value . '&';
        }
        $fieldsString = rtrim($fieldsString, '&');
        //open connection
        $ch = curl_init();
        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token');
        curl_setopt($ch, CURLOPT_POST, 5);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
        // Set so curl_exec returns the result instead of outputting it.
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //to trust any ssl certificates
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        //execute post
        $result = curl_exec($ch);
        //close connection
        curl_close($ch);
        //extracting access_token from response string
        $response = json_decode($result);
        if (empty($response->access_token)) {
            $authUrl = OW::getRequest()->buildUrlQueryString('https://accounts.google.com/o/oauth2/auth', array('response_type' => 'code', 'client_id' => $clientId, 'redirect_uri' => $redirectUri, 'state' => 'contacts', 'scope' => 'https://www.google.com/m8/feeds/'));
            UTIL_Url::redirect($authUrl);
        }
        $accessToken = $response->access_token;
        //passing accesstoken to obtain contact details
        $resultCount = 100;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/m8/feeds/contacts/default/full?max-results=' . $resultCount . '&oauth_token=' . $accessToken . '&alt=json');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('GData-Version: 2.0'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_HTTPGET, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        $jsonResponse = curl_exec($ch);
        curl_close($ch);
        //$jsonResponse =  file_get_contents('https://www.google.com/m8/feeds/contacts/default/full?max-results=' . $resultCount . '&oauth_token=' . $accessToken . '&alt=json');
        $response = json_decode($jsonResponse, true);
        if (!empty($response["error"]["message"])) {
            echo $response["error"]["message"];
            exit;
        }
        $out = array();
        $list = $response['feed']['entry'];
        $defaultImage = BOL_AvatarService::getInstance()->getDefaultAvatarUrl();
        $contexId = uniqid('ci');
        $jsArray = array();
        foreach ($list as $item) {
            if (empty($item['gd$email'][0]['address'])) {
                continue;
            }
            $address = $item['gd$email'][0]['address'];
            $image = $item['link'][1]['type'] != 'image/*' ? $defaultImage : $item['link'][1]['href'] . '?oauth_token=' . $accessToken;
            $title = empty($item['title']['$t']) ? $address : $item['title']['$t'];
            $uniqId = uniqid('cii');
            $out[] = array('title' => $title, 'image' => $image, 'address' => $address, 'uniqId' => $uniqId, 'fields' => empty($item['title']['$t']) ? '' : $address, 'avatar' => array('title' => $title, 'src' => $image));
            $jsArray[$address] = array('linkId' => $uniqId, 'userId' => $address);
        }
        OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('base')->getStaticJsUrl() . 'avatar_user_select.js');
        OW::getDocument()->addOnloadScript("\n            var cmp = new AvatarUserSelect(" . json_encode($jsArray) . ", '" . $contexId . "');\n            cmp.init();\n            OW.registerLanguageKey('base', 'avatar_user_select_empty_list_message', '" . OW::getLanguage()->text('base', 'avatar_user_select_empty_list_message') . "');\n         ");
        $this->assign('users', $out);
        $this->assign('contexId', $contexId);
        $countLabel = OW::getLanguage()->text('base', 'avatar_user_list_select_count_label');
        $buttonLabel = OW::getLanguage()->text('base', 'avatar_user_list_select_button_label');
        $langs = array('countLabel' => $countLabel, 'startCountLabel' => !empty($countLabel) ? str_replace('#count#', '0', $countLabel) : null, 'buttonLabel' => $buttonLabel, 'startButtonLabel' => str_replace('#count#', '0', $buttonLabel));
        $this->assign('langs', $langs);
        $rsp = json_encode(OW::getRouter()->urlFor('CONTACTIMPORTER_CTRL_Google', 'send'));
        OW::getDocument()->addOnloadScript('OW.bind("base.avatar_user_list_select", function( data ){
            var msg = $("#ci-message").val();
	    var inv = $("#ci-message").attr("inv");

	    msg = inv == msg ? "" : msg;
            window.opener.CONTACTIMPORTER_Google.send(' . $rsp . ', data, msg);
            window.close();
        });');
    }