Exemplo n.º 1
0
 /**
  * Method to call when redirected back from google after authentication
  * Grab the return URL if set and handle denial of app privileges from google
  *
  * @param   object  $credentials
  * @param   object  $options
  * @return  void
  */
 public function login(&$credentials, &$options)
 {
     $b64dreturn = '';
     // Check the state for our return variable
     if ($return = Request::getVar('state', '', 'method', 'base64')) {
         $b64dreturn = base64_decode($return);
         if (!\Hubzero\Utility\Uri::isInternal($b64dreturn)) {
             $b64dreturn = '';
         }
     }
     $options['return'] = $b64dreturn;
     // Set up the config for the google api instance
     $client = new Google_Client();
     $client->setClientId($this->params->get('app_id'));
     $client->setClientSecret($this->params->get('app_secret'));
     $client->setRedirectUri(self::getRedirectUri('google'));
     // If we have a code comeing back, the user has authorized our app, and we can authenticate
     if ($code = Request::getVar('code', NULL)) {
         // Authenticate the user
         $client->authenticate($code);
         // Add the access token to the session
         $session = App::get('session');
         $session->set('google.token', $client->getAccessToken());
     } else {
         // User didn't authorize our app or clicked cancel
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return), Lang::txt('PLG_AUTHENTICATION_GOOGLE_MUST_AUTHORIZE_TO_LOGIN', Config::get('sitename')), 'error');
     }
 }
Exemplo n.º 2
0
 /**
  * Get the redirect URL
  *
  * @param   object  $params  Registry The module options.
  * @param   string  $type    Type
  * @return  string
  */
 static function getReturnURL($params, $type)
 {
     $url = null;
     if ($itemid = $params->get($type)) {
         $db = App::get('db');
         $query = $db->getQuery(true);
         $query->select($db->quoteName('link'));
         $query->from($db->quoteName('#__menu'));
         $query->where($db->quoteName('published') . '=1');
         $query->where($db->quoteName('id') . '=' . $db->quote($itemid));
         $db->setQuery($query);
         if ($link = $db->loadResult()) {
             $url = 'index.php?Itemid=' . $itemid;
         }
     }
     if (!$url) {
         // stay on the same page
         $uri = clone Uri::getInstance();
         $vars = $uri->parse($uri->toString());
         unset($vars['lang']);
         if (isset($vars['Itemid'])) {
             $itemid = $vars['Itemid'];
             $item = App::get('menu')->getItem($itemid);
             unset($vars['Itemid']);
             if (isset($item) && $vars == $item->query) {
                 $url = 'index.php?Itemid=' . $itemid;
             } else {
                 $url = 'index.php?' . $uri->buildQuery($vars) . '&Itemid=' . $itemid;
             }
         } else {
             $url = 'index.php?' . $uri->buildQuery($vars);
         }
     }
     return base64_encode($url);
 }
Exemplo n.º 3
0
 /**
  * Actions to perform when logging in a user session
  *
  * @param   array  $credentials  login credentials
  * @param   array  $options      login options
  * @return  void
  */
 public function login(&$credentials, &$options)
 {
     // Check for return param
     if ($return = Request::getVar('return', '', 'method', 'base64')) {
         $return = base64_decode($return);
         if (!\Hubzero\Utility\Uri::isInternal($return)) {
             $return = '';
         }
     }
     $options['return'] = $return;
 }
Exemplo n.º 4
0
 /**
  * Method to call when redirected back from twitter after authentication
  * Grab the return URL if set and handle denial of app privileges from twitter
  *
  * @param   object  $credentials
  * @param   object  $options
  * @return  void
  */
 public function login(&$credentials, &$options)
 {
     if ($return = Request::getVar('return', '', 'method', 'base64')) {
         $b64dreturn = base64_decode($return);
         if (!\Hubzero\Utility\Uri::isInternal($b64dreturn)) {
             $b64dreturn = '';
         }
     }
     $options['return'] = $b64dreturn;
     // Check to make sure they didn't deny our application permissions
     if (Request::getWord('denied', false)) {
         // User didn't authorize our app or clicked cancel
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return), Lang::txt('PLG_AUTHENTICATION_TWITTER_MUST_AUTHORIZE_TO_LOGIN', Config::get('sitename')), 'error');
         return;
     }
 }
Exemplo n.º 5
0
 /**
  * Method to call when redirected back from ORCID after authentication
  * Grab the return URL if set and handle denial of app privileges from ORCID
  *
  * @param   object  $credentials
  * @param   object  $options
  * @return  void
  */
 public function login(&$credentials, &$options)
 {
     $b64dreturn = '';
     // Check the state for our return variable
     if ($return = Request::getVar('state', '', 'method', 'base64')) {
         $b64dreturn = base64_decode($return);
         if (!\Hubzero\Utility\Uri::isInternal($b64dreturn)) {
             $b64dreturn = '';
         }
     }
     $options['return'] = $b64dreturn;
     // If we have a code coming back, the user has authorized our app, and we can authenticate
     if (!Request::getVar('code', NULL)) {
         // User didn't authorize our app or clicked cancel
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return), Lang::txt('PLG_AUTHENTICATION_ORCID_MUST_AUTHORIZE_TO_LOGIN', Config::get('sitename')), 'error');
     }
 }
Exemplo n.º 6
0
 /**
  * Method to handle an error condition.
  *
  * @param   Exception  &$error  The Exception object to be handled.
  * @return  void
  */
 public static function handleError(&$error)
 {
     include_once PATH_CORE . DS . 'components' . DS . 'com_redirect' . DS . 'models' . DS . 'link.php';
     $renderer = new \Hubzero\Error\Renderer\Page(App::get('document'), App::get('template')->template, App::get('config')->get('debug'));
     // Make sure the error is a 404 and we are not in the administrator.
     if (!App::isAdmin() and $error->getCode() == 404) {
         // Render the error page.
         $renderer->render($error);
     }
     // Get the full current URI.
     $uri = \Hubzero\Utility\Uri::getInstance();
     $current = $uri->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment'));
     // Attempt to ignore idiots.
     if (strpos($current, 'mosConfig_') !== false || strpos($current, '=http://') !== false) {
         // Render the error page.
         $renderer->render($error);
     }
     // See if the current url exists in the database as a redirect.
     $link = \Components\Redirect\Models\Link::all()->whereEquals('old_url', $current)->row();
     // If no published redirect was found try with the server-relative URL
     if (!$link->id || $link->published != 1) {
         $currRel = $uri->toString(array('path', 'query', 'fragment'));
         $link = \Components\Redirect\Models\Link::all()->whereEquals('old_url', $currRel)->row();
     }
     // If a redirect exists and is published, permanently redirect.
     if ($link->id && $link->published == 1) {
         App::redirect($link->new_url, null, null, true, false);
     } else {
         $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
         $row = \Components\Redirect\Models\Link::all()->whereEquals('old_url', $current)->row();
         if (!$row->get('id')) {
             $row->set(['old_url' => $current, 'new_url' => '', 'referer' => $referer, 'comment' => '', 'hits' => 1, 'published' => 0, 'created_date' => Date::toSql()]);
         } else {
             $row->set('hits', intval($row->get('hits')) + 1);
         }
         $row->save();
         // Render the error page.
         $renderer->render($error);
     }
 }
Exemplo n.º 7
0
 /**
  * Method to call when redirected back from linkedin after authentication
  * Grab the return URL if set and handle denial of app privileges from linkedin
  *
  * @param   object  $credentials
  * @param   object  $options
  * @return  void
  */
 public function login(&$credentials, &$options)
 {
     $jsession = App::get('session');
     $b64dreturn = '';
     // Check to see if a return parameter was specified
     if ($return = Request::getVar('return', '', 'method', 'base64')) {
         $b64dreturn = base64_decode($return);
         if (!\Hubzero\Utility\Uri::isInternal($b64dreturn)) {
             $b64dreturn = '';
         }
     }
     // Set the return variable
     $options['return'] = $b64dreturn;
     // Set up linkedin configuration
     $linkedin_config['appKey'] = $this->params->get('api_key');
     $linkedin_config['appSecret'] = $this->params->get('app_secret');
     $linkedin_config['callbackUrl'] = self::getRedirectUri('linkedin');
     // Create Object
     $linkedin_client = new LinkedIn($linkedin_config);
     if (!Request::getVar('oauth_verifier', NULL)) {
         // User didn't authorize our app, or, clicked cancel
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return), Lang::txt('PLG_AUTHENTICATION_LINKEDIN_MUST_AUTHORIZE_TO_LOGIN', Config::get('sitename')), 'error');
     }
     // LinkedIn has sent a response, user has granted permission, take the temp access token,
     // the user's secret and the verifier to request the user's real secret key
     $request = $jsession->get('linkedin.oauth.request');
     $reply = $linkedin_client->retrieveTokenAccess($request['oauth_token'], $request['oauth_token_secret'], Request::getVar('oauth_verifier'));
     if ($reply['success'] === TRUE) {
         // The request went through without an error, gather user's 'access' tokens
         $jsession->set('linkedin.oauth.access', $reply['linkedin']);
         // Set the user as authorized for future quick reference
         $jsession->set('linkedin.oauth.authorized', TRUE);
     } else {
         return new Exception(Lang::txt('PLG_AUTHENTICATION_LINKEDIN_ERROR'), 500);
     }
 }
Exemplo n.º 8
0
 /**
  * Display module content
  *
  * @return  void
  */
 public function display()
 {
     // Field labels
     $this->name_label = $this->params->get('name_label', Lang::txt('MOD_RAPID_CONTACT_FIELD_NAME'));
     $this->email_label = $this->params->get('email_label', Lang::txt('MOD_RAPID_CONTACT_FIELD_EMAIL'));
     $this->subject_label = $this->params->get('subject_label', Lang::txt('MOD_RAPID_CONTACT_FIELD_SUBJECT'));
     $this->message_label = $this->params->get('message_label', Lang::txt('MOD_RAPID_CONTACT_FIELD_MESSAGE'));
     // Button text
     $this->button_text = $this->params->get('button_text', Lang::txt('MOD_RAPID_CONTACT_SEND'));
     // Pre text
     $this->pre_text = $this->params->get('pre_text', '');
     // Thank you message
     $this->page_text = $this->params->get('page_text', Lang::txt('MOD_RAPID_CONTACT_THANK_YOU'));
     // Error messages
     $this->error_text = $this->params->get('error_text', Lang::txt('MOD_RAPID_CONTACT_ERROR_SENDING'));
     $this->no_email = $this->params->get('no_email', Lang::txt('MOD_RAPID_CONTACT_ERROR_NO_EMAIL'));
     $this->invalid_email = $this->params->get('invalid_email', Lang::txt('MOD_RAPID_CONTACT_ERROR_INVALID_EMAIL'));
     // From
     $this->from_name = $this->params->get('from_name', Lang::txt('MOD_RAPID_CONTACT'));
     $this->from_email = $this->params->get('from_email', '*****@*****.**');
     // To
     $this->recipient = $this->params->get('email_recipient', Config::get('mailfrom'));
     if (!trim($this->recipient)) {
         $this->recipient = Config::get('mailfrom');
     }
     // Enable Anti-spam?
     $this->enable_anti_spam = $this->params->get('enable_anti_spam', true);
     $this->anti_spam_q = $this->params->get('anti_spam_q', Lang::txt('MOD_RAPID_CONTACT_ANTIPSAM'));
     $this->anti_spam_a = $this->params->get('anti_spam_a', '2');
     $this->mod_class_suffix = $this->params->get('moduleclass_sfx', '');
     $disable_https = $this->params->get('disable_https', false);
     $exact_url = $this->params->get('exact_url', true);
     if (!$exact_url) {
         $this->url = filter_var(\Hubzero\Utility\Uri::getInstance()->toString(), FILTER_SANITIZE_URL);
     } else {
         if (!$disable_https) {
             $this->url = !empty($_SERVER['HTTPS']) ? 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
         } else {
             $this->url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
         }
     }
     //$qs = str_replace(array('"', '?'), '', urldecode($_SERVER['QUERY_STRING']));
     //$aqs = explode('?', $this->url);
     //$this->url = $aqs[0] . '?' . urlencode($qs);
     $fixed_url = $this->params->get('fixed_url', true);
     if ($fixed_url) {
         $this->url = $this->params->get('fixed_url_address', '');
     }
     $this->error = '';
     $this->replacement = '';
     $this->posted = array('name' => '', 'email' => '', 'subject' => '', 'message' => '');
     if (isset($_POST['rp'])) {
         $this->posted = Request::getVar('rp', array(), 'post');
         if ($this->enable_anti_spam) {
             if (!isset($this->posted['anti_spam_answer']) || $this->posted['anti_spam_answer'] != $this->anti_spam_a) {
                 $this->error = Lang::txt('MOD_RAPID_CONTACT_INVALID_ANTIPSAM_ANSWER');
             }
         }
         if ($this->posted['email'] === '') {
             $this->error = $this->no_email;
         }
         if (!preg_match("#^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$#i", $this->posted['email'])) {
             $this->error = $this->invalid_email;
         }
         if ($this->error == '') {
             $mySubject = Sanitize::clean($this->posted['subject']);
             $myMessage = Lang::txt('MOD_RAPID_CONTACT_MESSAGE_FROM', $this->posted['name'], $this->posted['email'], Request::getVar('HTTP_REFERER', '', 'SERVER'), Config::get('sitename'));
             $myMessage .= "\n\n" . Sanitize::clean($this->posted['message']);
             $this->from_email = $this->posted['email'];
             $this->from_name = isset($this->posted['name']) && Sanitize::clean($this->posted['name']) ? Sanitize::clean($this->posted['name']) : $this->posted['email'];
             $mailSender = new Message();
             $mailSender->setSubject($mySubject)->addFrom($this->from_email, $this->from_name)->addTo($this->recipient)->addReplyTo($this->posted['email'], $this->posted['name'])->setBody($myMessage);
             if (!$mailSender->send()) {
                 $this->error = $this->error_text;
             } else {
                 $this->replacement = $this->page_text;
             }
             // Reset the message field
             $this->posted['subject'] = '';
             $this->posted['message'] = '';
         }
     }
     require $this->getLayoutPath($this->params->get('layout', 'default'));
 }
Exemplo n.º 9
0
 /**
  * Actions to perform when logging in a user session
  *
  * @param      unknown &$credentials Parameter description (if any) ...
  * @param      array &$options Parameter description (if any) ...
  * @return     void
  */
 public function login(&$credentials, &$options)
 {
     if ($return = Request::getVar('return', '', 'method', 'base64')) {
         $return = base64_decode($return);
         if (!\Hubzero\Utility\Uri::isInternal($return)) {
             $return = '';
         }
     }
     $options['return'] = $return;
     // If someone is logged in already, then we're linking an account
     if (!User::get('guest')) {
         self::log('already logged in, redirect for link');
         list($service, $com_user, $task) = self::getLoginParams();
         App::redirect($service . '/index.php?option=' . $com_user . '&task=' . $task . '&authenticator=shibboleth&shib-session=' . urlencode($_COOKIE['shib-session']));
     }
     // extract variables set by mod_shib, if any
     // https://www.incommon.org/federation/attributesummary.html
     if ($sid = isset($_SERVER['REDIRECT_Shib-Session-ID']) ? $_SERVER['REDIRECT_Shib-Session-ID'] : (isset($_SERVER['Shib-Session-ID']) ? $_SERVER['Shib-Session-ID'] : NULL)) {
         $attrs = array('id' => $sid, 'idp' => isset($_SERVER['REDIRECT_Shib-Identity-Provider']) ? $_SERVER['REDIRECT_Shib-Identity-Provider'] : $_SERVER['Shib-Identity-Provider']);
         foreach (array('email', 'eppn', 'displayName', 'givenName', 'sn', 'mail') as $key) {
             if (isset($_SERVER[$key])) {
                 $attrs[$key] = $_SERVER[$key];
             } elseif (isset($_SERVER['REDIRECT_' . $key])) {
                 $attrs[$key] = $_SERVER['REDIRECT_' . $key];
             }
         }
         if (isset($attrs['mail']) && strpos($attrs['mail'], '@')) {
             $attrs['email'] = $attrs['mail'];
             unset($attrs['mail']);
         }
         // normalize things a bit
         if (!isset($attrs['username']) && isset($attrs['eppn'])) {
             $attrs['username'] = preg_replace('/@.*$/', '', $attrs['eppn']);
         }
         // eppn is sometimes or maybe always in practice an email address
         if (!isset($attrs['email']) && isset($attrs['eppn']) && strpos($attrs['eppn'], '@')) {
             $attrs['email'] = $attrs['eppn'];
         }
         if (!isset($attrs['displayName']) && isset($attrs['givenName']) && $attrs['sn']) {
             $attrs['displayName'] = $attrs['givenName'] . ' ' . $attrs['sn'];
         }
         $options['shibboleth'] = $attrs;
         self::log('session attributes: ', $attrs);
         self::log('cookie', $_COOKIE);
         self::log('server attributes: ', $_SERVER);
         //JFactory::getSession()->set('shibboleth.session', $attrs);
         $key = trim(base64_encode(openssl_random_pseudo_bytes(128)));
         setcookie('shib-session', $key);
         $dbh = App::get('db');
         $dbh->setQuery('INSERT INTO #__shibboleth_sessions(session_key, data) VALUES(' . $dbh->quote($key) . ', ' . $dbh->quote(json_encode($attrs)) . ')');
         $dbh->execute();
     }
 }
Exemplo n.º 10
0
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// no direct access
defined('_HZEXEC_') or die;
//$base = Request::getVar('REQUEST_URI', rtrim(Request::base(true), '/'), 'server');
$base = filter_var(\Hubzero\Utility\Uri::getInstance()->toString(), FILTER_SANITIZE_URL);
if ($this->params->get('button', 0) == 1) {
    ?>
	<div id="content-header-extra">
		<ul id="useroptions">
			<li>
				<a href="<?php 
    echo Route::url('index.php?option=com_feedback&task=success_story');
    ?>
" class="icon-add btn add">
					<?php 
    echo Lang::txt('MOD_QUOTES_ADD_YOUR_STORY');
    ?>
				</a>
			</li>
		</ul>