public static function ResolveProfileLinkById($userid)
 {
     $user = UserModel::Construct($userid);
     if (!$user) {
         return false;
     }
     return self::ResolveProfileLink($user);
 }
/**
 * Convert a user id to a username and display that to the template.
 *
 * @todo Finish documentation of smarty_function_user
 *
 * @param array  $params  Associative (and/or indexed) array of smarty parameters passed in from the template
 * @param Smarty $smarty  Parent Smarty template object
 *
 * @return string
 * @throws SmartyException
 *
 * <h3>Usage Example</h3>
 *
 * <p>Typical usage for the Smarty user function</p>
 *
 * <code lang="text/html">
 * User Name: {user $userid}&lt;br/&gt;
 * </code>
 */
function smarty_function_user($params, $smarty){
	if(isset($params['user'])){
		$userid = $params['user'];
	}
	elseif(isset($params[0])){
		$userid = $params[0];
	}
	else{
		throw new SmartyException('Required parameter [user] not provided for user!');
	}

	/** @var UserModel $user */
	$user = UserModel::Construct($userid);

	if(!$user) return '';

	$username = $user->getDisplayName();
	return $username;
}
 public function badge()
 {
     $view = $this->getView();
     $request = $this->getRequest();
     $uid = $request->getParameter('user');
     if ($uid instanceof UserModel) {
         $user = $uid;
         $uid = $user->get('id');
     } else {
         $user = UserModel::Construct($uid);
     }
     $direction = $request->getParameter('direction') ? $request->getParameter('direction') : 'horizontal';
     $orientation = $request->getParameter('orientation') ? $request->getParameter('orientation') : 'left';
     $view->assign('enableavatar', \ConfigHandler::Get('/user/enableavatar'));
     $view->assign('link', UserSocialHelper::ResolveProfileLink($user));
     $view->assign('user', $user);
     $view->assign('profiles', $user->get('external_profiles'));
     $view->assign('direction', $direction);
     $view->assign('orientation', $orientation);
     $view->assign('title', $request->getParameter('title'));
 }
 /**
  * View a user's public profile
  */
 public function view()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     $manager = \Core\user()->checkAccess('p:/user/users/manage');
     // Current user an admin?
     // First argument here will either be the username or user id.
     $arg1 = $request->getParameter(0);
     $user = UserModel::Construct($arg1);
     if (!($user && $user->exists())) {
         // Try by username instead.
         $match = UserUserConfigModel::Find(array('key' => 'username', 'value' => $arg1), 1);
         if (!$match) {
             return View::ERROR_NOTFOUND;
         }
         $user = UserModel::Construct($match->get('user_id'));
     }
     if (!$user) {
         return View::ERROR_NOTFOUND;
     }
     // If the UA requested the user by ID but the user has a username set, return a 404 as well.
     // This should help cut down on scanning attempts for userdata.
     if (is_numeric($arg1) && $user->get('username')) {
         return View::ERROR_NOTFOUND;
     }
     // Now see why username needs to not begin with a number? :p
     /** @var $user UserModel */
     // Only allow this if the user is either the same user or has the user manage permission.
     if ($user->get('id') == \Core\user()->get('id') || $manager) {
         $editor = true;
     } else {
         $editor = false;
     }
     $view->controls = ViewControls::DispatchModel($user);
     $view->title = $user->getDisplayName();
     $view->assign('user', $user);
     $view->assign('profiles', $user->get('external_profiles'));
 }
	/**
	 * Render this form element and return the HTML content.
	 *
	 * @return string
	 */
	public function render() {
		$file = $this->getTemplateName();

		$tpl = \Core\Templates\Template::Factory($file);

		if($this->get('value')){
			/** @var UserModel $user */
			$user = UserModel::Construct($this->get('value'));
		}
		else{
			$user = null;
		}

		$tpl->assign('element', $this);
		$tpl->assign('can_lookup', \Core\user()->checkAccess('p:/user/search/autocomplete'));
		$tpl->assign('username', ($user ? $user->getDisplayName() : ''));

		return $tpl->fetch();
	}
	public function now(){
		$request = $this->getPageRequest();
		$view = $this->getView();

		if(!$request->isJSON()) return View::ERROR_BADREQUEST;
		$view->contenttype = View::CTYPE_JSON;
		$view->mode = View::MODE_AJAX;
		$view->record = false;

		$limit = $this->_getQueryLimit();
		$duration = 60;
		// Use FindRaw because it's faster than using full Models for everything, especially when dealing with 20k + records.
		$listings = UserActivityModel::FindRaw('datetime >= ' . (Time::GetCurrent() - $duration), $limit, 'datetime DESC');


		$data = array();

		// Performance reports
		$data['information'] = array(
			'duration' => $duration,
		);
		$data['performance'] = array('get' => 0, 'post' => 0);
		$data['requests'] = array('get' => 0, 'post' => 0);
		$users = array();
		$bots = array();

		$guestname = \ConfigHandler::Get('/user/displayname/anonymous');

		foreach($listings as $log){
			if($log['type'] == 'GET'){
				$data['performance']['get'] += $log['processing_time'];
				$data['requests']['get']++;
			}
			elseif($log['type'] == 'POST'){
				$data['performance']['post'] += $log['processing_time'];
				$data['requests']['post']++;
			}

			$ua = new \Core\UserAgent($log['useragent']);
			
			if(class_exists('\\geocode\\IPLookup')){
				// If the geo library is available, use that to resolve the IP to something more meaningful than just a number.
				$lookup = new \geocode\IPLookup($log['ip_addr']);

				$file = \Core\Filestore\Factory::File('assets/images/iso-country-flags/' . strtolower($lookup->country) . '.png');
				
				if($lookup->province && $lookup->city){
					$title = $lookup->city . ', ' . $lookup->province . ', ' . $lookup->getCountryName();
				}
				elseif($lookup->province){
					$title = $lookup->province . ', ' . $lookup->getCountryName();
				}
				elseif($lookup->city){
					$title = $lookup->city . ' ' . $lookup->getCountryName();
				}
				else{
					$title =  $lookup->getCountryName();
				}

				$ip = '<span title="' . $title . '">';
				if($file->exists()){
					$ip .= '<img src="' . $file->getPreviewURL('20x20') . '" alt="' . $lookup->country . '"/> ';
				}
				$ip .= $log['ip_addr'];
				$ip .= '</span>';
			}
			else{
				$ip = $log['ip_addr'];
			}

			// Bots have their own data, because, well... they're bots.
			// Damn bots!
			if($ua->isBot()){
				if(!isset($bots[ $log['ip_addr'] ])){
					$bots[ $log['ip_addr'] ] = array(
						'ip'        => $ip,
						'useragent' => $log['useragent'],
						'lastpage'  => $log['request'],
						'status'    => $log['status'],
						//'type'      => $ua->,
						'browser'   => $ua->getAsHTML(),
						'count'     => 1,
					);
				}
				else{
					$bots[$log['ip_addr']]['count']++;
				}
			}
			// The user agent information I want to know on a per-user basis, not a per-click basis.
			else{
				if(!isset($users[ $log['session_id'] ])){
					$thisuser = UserModel::Construct($log['user_id']);

					$users[ $log['session_id'] ] = array(
						'session'   => $log['session_id'],
						'ip'        => $ip,
						'user_id'   => $log['user_id'],
						'username'  => ($thisuser ? $thisuser->getDisplayName() : $guestname),
						'useragent' => $log['useragent'],
						'lastpage'  => $log['request'],
						//'type'      => $ua->type,
						'browser'   => $ua->getAsHTML(),
						'os'        => '',
						'count'     => 1,
					);
				}
				else{
					$users[$log['session_id']]['count'] ++;
				}
			}
		}
//UserAgent::Test(); die();
		if($data['requests']['get'] > 0) $data['performance']['get'] = round($data['performance']['get'] /  $data['requests']['get'], 2);
		if($data['requests']['post'] > 0) $data['performance']['post'] = $data['performance']['post'] /  $data['requests']['post'];

		$data['users'] = array_values($users);
		$data['bots'] = array_values($bots);

		//var_dump($data, $users, $listings); die();
		$view->jsondata = $data;
	}
 /**
  * View a specific cron execution and its details.
  */
 public function view()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     $view->mode = View::MODE_PAGEORAJAX;
     if (!\Core\user()->checkAccess('p:/security/viewlog')) {
         return View::ERROR_ACCESSDENIED;
     }
     $logid = $request->getParameter(0);
     $log = SecurityLogModel::Construct($logid);
     if (!$log->exists()) {
         return View::ERROR_NOTFOUND;
     }
     if ($log->get('user_id')) {
         $userobject = UserModel::Construct($log->get('user_id'));
         $user = $userobject->getDisplayName();
     } else {
         $user = null;
     }
     if ($log->get('affected_user_id')) {
         $userobject = UserModel::Construct($log->get('affected_user_id'));
         $affected_user = $userobject->getDisplayName();
     } else {
         $affected_user = null;
     }
     $view->addBreadcrumb('Security Log', '/security/log');
     $view->title = 'Details';
     $view->assign('entry', $log);
     $view->assign('user', $user);
     $view->assign('affected_user', $affected_user);
 }
	public function getDisplayName(){
		if($this->get('user_id')){
			$user = UserModel::Construct($this->get('user_id'));
			$uname = $user->getDisplayName();
		}
		else{
			$uname = ConfigHandler::Get('/user/displayname/anonymous');
		}

		return $uname;
	}
	/**
	 * Hook receiver for /core/controllinks/user/view
	 *
	 * @param int $userid
	 *
	 * @return array
	 */
	public static function GetUserControlLinks($userid){

		$enabled = \Core\User\Helper::GetEnabledAuthDrivers();
		if(!isset($enabled['datastore'])){
			// GPG isn't enabled at all, disable any control links from the system.
			return [];
		}

		if($userid instanceof UserModel){
			$user = $userid;
		}
		else{
			/** @var UserModel $user */
			$user = UserModel::Construct($userid);
		}

		if(!$user->exists()){
			// Invalid user.
			return [];
		}

		$isself = (\Core\user()->get('id') == $user->get('id'));
		$isadmin = \Core\user()->checkAccess('p:/user/users/manage');

		if(!($isself || $isadmin)){
			// Current user does not have access to manage the provided user's data.
			return [];
		}

		try{
			// If this throws an exception, then it's not enabled!
			$user->getAuthDriver('datastore');
		}
		catch(Exception $e){
			if($isself){
				return [
					[
						'link' => '/datastoreauth/forgotpassword',
						'title' => t('STRING_ENABLE_PASSWORD_LOGIN'),
						'icon' => 'key',
					]
				];
			}
		}

		$ret = [];
		$ret[] = [
			'link' => '/datastoreauth/password/' . $user->get('id'),
			'title' => t('STRING_CHANGE_PASSWORD'),
			'icon' => 'key',
		];

		if(sizeof($user->getEnabledAuthDrivers()) > 1){
			$ret[] = [
				'link' => '/datastoreauth/disable/' . $user->get('id'),
				'title' => t('STRING_DISABLE_PASSWORD_LOGIN'),
				'icon' => 'ban',
				'confirm' => 'Are you sure you want to disable password-based logins?  (They can be re-enabled if requested.)',
			];
		}


		return $ret;

	}
Exemple #10
0
 * Created by JetBrains PhpStorm.
 * User: powellc
 * Date: 1/17/13
 * Time: 10:20 PM
 * This is the upgrade file from 1.2.1 to 1.3.0.
 *
 * The blog system in 1.3.0 and later utilizes a dedicated Page entry for each blog entry.  This helps to have more
 * fine grain control over each entry's settings and data, as well as making use of the insertable system.
 */
// Create a page for each BlogArticle!
// Since this runs prior to the blog system being enabled, I need to manually include the model files.
require_once ROOT_PDIR . 'components/blog/models/BlogArticleModel.php';
require_once ROOT_PDIR . 'components/blog/models/BlogModel.php';
$articles = BlogArticleModel::Find();
foreach ($articles as $article) {
    /** @var $article BlogArticleModel */
    /** @var $blog BlogModel */
    $blog = $article->getLink('Blog');
    /** @var $page PageModel */
    $page = $article->getLink('Page');
    $page->setFromArray(array('title' => $article->get('title'), 'rewriteurl' => $blog->get('rewriteurl') . '/' . $article->get('id') . '-' . \Core\str_to_url($article->get('title')), 'parenturl' => $blog->get('baseurl'), 'fuzzy' => 0, 'admin' => 0));
    if ($article->get('authorid')) {
        $user = UserModel::Construct($article->get('authorid'));
        $page->setMeta('author', $user->getDisplayName());
        $page->setMeta('authorid', $user->get('id'));
    }
    $page->setMeta('description', $article->get('description'));
    $page->setMeta('keywords', $article->get('keywords'));
    $page->save();
}
// return
<?php

/**
 * Upgrade file for migrating user data from the user user configs to the new supplemental user table.
 */
// The migrations for source (user_user_config) to destination (user).
$migrations = ['first_name' => 'first_name', 'last_name' => 'last_name', 'phone' => 'phone', 'bio' => 'bio', 'username' => 'username'];
// Lookup each key and the corresponding user attached.
$sources = \Core\Datamodel\Dataset::Init()->select(['user_id', 'key', 'value'])->table('user_user_config')->where('key IN ' . implode(',', array_keys($migrations)))->executeAndGet();
$users = [];
foreach ($sources as $s) {
    if (!isset($users[$s['user_id']])) {
        $users[$s['user_id']] = UserModel::Construct($s['user_id']);
    }
    /** @var UserModel $u */
    $u = $users[$s['user_id']];
    $nk = $migrations[$s['key']];
    $nv = $s['value'];
    $u->set($nk, $nv);
}
// Now save each user loaded into the array.
foreach ($users as $u) {
    /** @var UserModel $u */
    $u->save();
}
 *
 * @package Core
 */

// I'm using raw objects here because if there are a lot of user accounts in the system,
// creating a giant array of them all may take quite a bit of memory.
// FindRaw returns simply arrays, so less memory is required.
$userdat = UserModel::FindRaw();

foreach($userdat as $dat){
	/** @var array $dat */

	if($dat['avatar'] == ''){
		// Skip empty avatars, they don't get updated.
		continue;
	}

	if(strpos($dat['avatar'], 'public/') === 0){
		// Skip avatars that are already resolved.  They don't need to be updated.
		continue;
	}

	/** @var $u UserModel */
	$u = UserModel::Construct($dat['id']);
	// User avatars prior to 2.8.0 were saved in public/user.
	// After they are relocated to public/user/avatar, but with the Core relative path saved in the database, it'll be fine.
	// Saves me from having to copy all the files over to public/user/avatar!
	$u->set('avatar', 'public/user/' . $u->get('avatar'));
	$u->save();
}
/**
 * Created by JetBrains PhpStorm.
 * User: powellc
 * Date: 1/17/13
 * Time: 10:20 PM
 * This is the upgrade file from 1.4.3 to 1.4.4
 *
 * Required because with the file input change in 2.6.0 returning core resolved paths,
 * the data in the database will contain that path now.
 */
$images = GalleryImageModel::Find();
foreach ($images as $i) {
    /** @var $i GalleryImageModel */
    // Just in case
    if (strpos($i->get('file'), 'public/') !== 0) {
        $i->set('file', 'public/galleryalbum/' . $i->get('file'));
        $i->save();
    }
    // Don't forget to copy over the meta data too!
    // This is because the gallery system will use the new version of metadata.
    $u = UserModel::Construct($i->get('uploaderid'));
    $helper = new \Core\Filestore\FileMetaHelper($i->getOriginalFile());
    $helper->setMeta('title', $i->get('title'));
    $helper->setMeta('keywords', explode(',', $i->get('keywords')));
    $helper->setMeta('description', $i->get('description'));
    $helper->setMeta('authorid', $i->get('uploaderid'));
    if ($u && $u instanceof User_Backend) {
        $helper->setMeta('author', $u->getDisplayName());
    }
}
 /**
  * Get the author of this article
  *
  * @return null|User_Backend
  */
 public function getAuthor()
 {
     $author = UserModel::Construct($this->get('authorid'));
     return $author;
 }
 private function _viewBlogArticle(BlogModel $blog, BlogArticleModel $article)
 {
     $view = $this->getView();
     /** @var $page PageModel */
     $page = $article->getLink('Page');
     //$articles = $blog->getLink('BlogArticle');
     $manager = \Core\user()->checkAccess('p:/blog/manage_all');
     $editor = \Core\user()->checkAccess($blog->get('manage_articles_permission ')) || $manager;
     $author = UserModel::Construct($article->get('authorid'));
     //$authorid = $author->get('id');
     //var_dump($page->getMeta('keywords')); die();
     if (!$article->isPublished()) {
         // Is it actually not published, or just marked for a future publish date?
         if ($article->get('status') == 'published') {
             $publishdate = new CoreDateTime($article->get('published'));
             Core::SetMessage('Article is set to be published on ' . $publishdate->getFormatted('F jS, Y \\a\\t h:ia'), 'info');
         } else {
             Core::SetMessage('Article not published yet!', 'info');
         }
     }
     //$view->templatename = $page->get('page_template') ? $page->get('page_template') : 'pages/blog/article_view.tpl';
     $view->templatename = 'pages/blog/article_view.tpl';
     //$view->addBreadcrumb($blog->get('title'), $blog->get('rewriteurl'));
     $view->title = $article->get('title');
     $view->meta['title'] = $article->get('title');
     $view->updated = $article->get('updated');
     $view->canonicalurl = \Core\resolve_link($article->get('rewriteurl'));
     $view->meta['og:type'] = 'article';
     if ($article->get('image')) {
         $image = \Core\Filestore\Factory::File($article->get('image'));
         $view->meta['og:image'] = $image->getPreviewURL('200x200');
     }
     //if($author){
     //	/** @var $author User */
     //	//$view->meta['author'] = $author->getDisplayName();
     //	$view->meta['author'] = $author;
     //}
     $view->meta['description'] = $article->getTeaser();
     $view->assign('author', $author->exists() ? $author : null);
     $view->assign('article', $article);
     $view->assign('body', \Core\parse_html($article->get('body')));
     if ($editor) {
         $view->addControl('Edit Article', '/blog/article/update/' . $article->get('id'), 'edit');
         if ($article->get('status') == 'draft') {
             $view->addControl(['title' => 'Publish Article', 'link' => '/blog/article/publish/' . $blog->get('id') . '/' . $article->get('id'), 'icon' => 'arrow-up', 'confirm' => 'Publish article?']);
         }
         $view->addControl(array('title' => 'Delete Article', 'link' => '/blog/article/delete/' . $article->get('id'), 'icon' => 'remove', 'confirm' => 'Remove blog article?'));
     }
     // Add the extra view types for this page
     $view->addHead('<link rel="alternate" type="application/atom+xml" title="' . $page->get('title') . ' Atom Feed" href="' . \Core\resolve_link($blog->get('baseurl')) . '.atom"/>');
     $view->addHead('<link rel="alternate" type="application/rss+xml" title="' . $page->get('title') . ' RSS Feed" href="' . \Core\resolve_link($blog->get('baseurl')) . '.rss"/>');
     $view->addControl('RSS Feed', \Core\resolve_link($blog->get('baseurl')) . '.rss', 'rss');
 }
	/**
	 * View to sudo as another user.
	 */
	public function sudo(){
		$view  = $this->getView();
		$req   = $this->getPageRequest();
		$id    = $req->getParameter(0);


		if($id){
			$model = UserModel::Construct($id);

			if(!\Core\user()->checkAccess('p:/user/users/sudo')){
				return View::ERROR_ACCESSDENIED;
			}

			if(!$req->isPost()){
				return View::ERROR_BADREQUEST;
			}

			if(!$model->exists()){
				return View::ERROR_NOTFOUND;
			}

			\Core\Session::Set('user_sudo', $model);
		}
		elseif(\Core\Session::Get('user_sudo') !== null){
			\Core\Session::UnsetKey('user_sudo');
		}

		\Core\redirect('/');
	}
Exemple #17
0
	/**
	 * Validate the verification email, part 2 of confirmation.
	 *
	 * @param string $nonce
	 * @param string $signature
	 *
	 * @return bool|string
	 */
	public static function ValidateVerificationResponse($nonce, $signature) {
		/** @var \NonceModel $nonce */
		$nonce = \NonceModel::Construct($nonce);

		if(!$nonce->isValid()){
			\SystemLogModel::LogSecurityEvent('/user/gpg/verified', 'FAILED to verify key (Invalid NONCE)', null);
			return 'Invalid nonce provided!';
		}

		// Now is where the real fun begins.

		$nonce->decryptData();

		$data = $nonce->get('data');

		/** @var \UserModel $user */
		$user   = \UserModel::Construct($data['user']);
		$gpg    = new \Core\GPG\GPG();
		$key    = $data['key'];
		$pubKey = $gpg->getKey($key);

		try{
			$sig = $gpg->verifyDataSignature($signature, $data['sentence']);
		}
		catch(\Exception $e){
			\SystemLogModel::LogSecurityEvent('/user/gpg/verified', 'FAILED to verify key ' . $key, null, $user->get('id'));
			return 'Invalid signature';
		}

		$fpr = str_replace(' ', '', $sig->fingerprint); // Trim spaces.
		if($key != $fpr && $key != $sig->keyID){
			// They must match!
			\SystemLogModel::LogSecurityEvent('/user/gpg/verified', 'FAILED to verify key ' . $key, null, $user->get('id'));
			return 'Invalid signature';
		}

		// Otherwise?
		$user->enableAuthDriver('gpg');
		$user->set('gpgauth_pubkey', $fpr);

		// Was there a photo attached to this public key?
		if(sizeof($pubKey->getPhotos()) > 0){
			$p = $pubKey->getPhotos();
			// I just want the first.
			/** @var \Core\Filestore\File $p */
			$p = $p[0];

			$localFile = \Core\Filestore\Factory::File('public/user/avatar/' . $pubKey->fingerprint . '.' . $p->getExtension());
			$p->copyTo($localFile);
			$user->set('avatar', $localFile->getFilename(false));
		}
		
		$user->save();

		$nonce->markUsed();

		\SystemLogModel::LogSecurityEvent('/user/gpg/verified', 'Verified key ' . $fpr, null, $user->get('id'));

		return true;
	}
/**
 * Get the current user model that is logged in.
 *
 * To support legacy systems, this will also return the User object if it's available instead.
 * This support is for < 2.8.x Core installations and will be removed after some amount of time TBD.
 *
 * If no user systems are currently available, null is returned.
 *
 * @return \UserModel
 */
function user(){
	static $_CurrentUserAccount = null;

	if(!class_exists('\\UserModel')){
		return null;
	}

	if($_CurrentUserAccount !== null){
		// Cache this for the page load.
		return $_CurrentUserAccount;
	}

	if(isset($_SERVER['HTTP_X_CORE_AUTH_KEY'])){
		// Allow an auth key to be used to authentication the requested user instead!
		$user = \UserModel::Find(['apikey = ' . $_SERVER['HTTP_X_CORE_AUTH_KEY']], 1);
		if($user){
			$_CurrentUserAccount = $user;
		}
	}
	elseif(Session::Get('user') instanceof \UserModel){
		// There is a valid user account in the session!
		// But check if this user is forced to be resynced first.
		if(isset(Session::$Externals['user_forcesync'])){
			// A force sync was requested by something that modified the original UserModel object.
			// Keep the user logged in, but reload the data from the database.
			$_CurrentUserAccount = \UserModel::Construct(Session::Get('user')->get('id'));
			// And cache this updated user model back to the session.
			Session::Set('user', $_CurrentUserAccount);
			unset(Session::$Externals['user_forcesync']);
		}
		else{
			$_CurrentUserAccount = Session::Get('user');
		}
	}

	if($_CurrentUserAccount === null){
		// No valid user found.
		$_CurrentUserAccount = new \UserModel();
	}

	// If this is in multisite mode, blank out the access string cache too!
	// This is because siteA may have some groups, while siteB may have another.
	// We don't want a user going to a site they have full access to, hopping to another and having cached permissions!
	if(\Core::IsComponentAvailable('multisite') && class_exists('MultiSiteHelper') && \MultiSiteHelper::IsEnabled()){
		$_CurrentUserAccount->clearAccessStringCache();
	}

	// Did this user request sudo access for another user?
	if(Session::Get('user_sudo') !== null){
		$sudo = Session::Get('user_sudo');

		if($sudo instanceof \UserModel){
			// It's a valid user!

			if($_CurrentUserAccount->checkAccess('p:/user/users/sudo')){
				// This user can SUDO!
				// (only if the other user is < SA or current == SA).
				if($sudo->checkAccess('g:admin') && !$_CurrentUserAccount->checkAccess('g:admin')){
					Session::UnsetKey('user_sudo');
					\SystemLogModel::LogSecurityEvent('/user/sudo', 'Authorized but non-SA user requested sudo access to a system admin!', null, $sudo->get('id'));
				}
				else{
					// Ok, everything is good.
					// Remap the current user over to this sudo'd account!
					$_CurrentUserAccount = $sudo;
				}
			}
			else{
				// This user can NOT sudo!!!
				Session::UnsetKey('user_sudo');
				\SystemLogModel::LogSecurityEvent('/user/sudo', 'Unauthorized user requested sudo access to another user!', null, $sudo->get('id'));
			}
		}
		else{
			Session::UnsetKey('user_sudo');
		}
	}

	return $_CurrentUserAccount;
}
 /**
  * Hook receiver for /core/controllinks/usermodel
  *
  * @param int $userid
  *
  * @return array
  */
 public static function GetUserControlLinks($userid)
 {
     $enabled = \Core\User\Helper::GetEnabledAuthDrivers();
     if (!isset($enabled['facebook'])) {
         // GPG isn't enabled at all, disable any control links from the system.
         return [];
     }
     /** @var UserModel $user */
     $user = UserModel::Construct($userid);
     if (!$user->exists()) {
         // Invalid user.
         return [];
     }
     $isself = \Core\user()->get('id') == $user->get('id');
     $isadmin = \Core\user()->checkAccess('p:/user/users/manage');
     if (!($isself || $isadmin)) {
         // Current user does not have access to manage the provided user's data.
         return [];
     }
     try {
         // If this throws an exception, then it's not enabled!
         $user->getAuthDriver('facebook');
     } catch (Exception $e) {
         if ($isself) {
             return [['link' => '/facebook/enable', 'title' => 'Enable Facebook Login', 'icon' => 'facebook']];
         }
     }
     if (sizeof($user->getEnabledAuthDrivers()) > 1) {
         return [['link' => '/facebook/disable/' . $user->get('id'), 'title' => 'Disable Facebook Login', 'icon' => 'ban', 'confirm' => 'Are you sure you want to disable Facebook-based logins?  (They can be re-enabled if requested.)']];
     }
     return [];
 }
	public function fetch(){

		if($this->contentkey){
			// Authorid is the meta tag used as of 2.4.1 from the builtin author autocomplete.
			$authorid = $this->contentkey;
		}
		else{
			$authorid = null;
		}

		if(!$this->content) return '';

		$data = array();

		// It's probably a User object!
		if(is_subclass_of($this->content, 'User')){
			// All profiles get at least the meta tag.
			$data['author'] = '<meta property="author" content="' . str_replace('"', '&quot;', $this->content->getDisplayName()) . '"/>';
			// "Socially enabled" sites also get the link attribute!
			if(Core::IsComponentAvailable('user-social')){
				$data['link-author'] = '<link rel="author" href="' . UserSocialHelper::ResolveProfileLink($this->content) . '"/>';
			}
		}
		// Otherwise, if the authorid is set, use that to look up the user.
		elseif($authorid){
			$user = UserModel::Construct($authorid);
			// All profiles get at least the meta tag.
			$data['author'] = '<meta property="author" content="' . str_replace('"', '&quot;', $user->getDisplayName()) . '"/>';
			// "Socially enabled" sites also get the link attribute!
			if(Core::IsComponentAvailable('user-social')){
				$data['link-author'] = '<link rel="author" href="' . UserSocialHelper::ResolveProfileLink($user) . '"/>';
			}
		}
		else{
			$data['author'] = '<meta property="author" content="' . str_replace('"', '&quot;', $this->content) . '"/>';
		}

		return $data;
	}