-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Harden security/profile/get processor (#16439)
- 2.x backport of #16437
- Loading branch information
Showing
1 changed file
with
93 additions
and
94 deletions.
There are no files selected for viewing
187 changes: 93 additions & 94 deletions
187
core/model/modx/processors/security/profile/get.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,93 @@ | ||
<?php | ||
/* | ||
* This file is part of MODX Revolution. | ||
* | ||
* Copyright (c) MODX, LLC. All Rights Reserved. | ||
* | ||
* For complete copyright and license information, see the COPYRIGHT and LICENSE | ||
* files found in the top-level directory of this distribution. | ||
*/ | ||
|
||
/** | ||
* Get a user profile | ||
* | ||
* @param integer $id The ID of the user | ||
* | ||
* @package modx | ||
* @subpackage processors.security.profile | ||
*/ | ||
class modProfileGetProcessor extends modProcessor { | ||
/** @var modUser $user */ | ||
public $user; | ||
|
||
public function checkPermissions() { | ||
return $this->modx->hasPermission('change_profile'); | ||
} | ||
|
||
public function getLanguageTopics() { | ||
return array('user'); | ||
} | ||
|
||
public function initialize() { | ||
$id = $this->getProperty('id'); | ||
if (empty($id)) return $this->modx->lexicon('user_err_ns'); | ||
$this->user = $this->modx->getObject('modUser',$id); | ||
if (!$this->user) return $this->modx->lexicon('user_err_not_found'); | ||
return true; | ||
} | ||
|
||
public function process() { | ||
/* if set, get groups for user */ | ||
if ($this->getProperty('getGroups',false)) { | ||
$this->getUserGroups(); | ||
} | ||
|
||
$userArray = $this->user->toArray(); | ||
$profile = $this->user->getOne('Profile'); | ||
if ($profile) { | ||
$userArray = array_merge($profile->toArray(),$userArray); | ||
} | ||
|
||
$userArray['dob'] = !empty($userArray['dob']) ? strftime('%m/%d/%Y',$userArray['dob']) : ''; | ||
$userArray['blockeduntil'] = !empty($userArray['blockeduntil']) ? strftime('%m/%d/%Y %I:%M %p',$userArray['blockeduntil']) : ''; | ||
$userArray['blockedafter'] = !empty($userArray['blockedafter']) ? strftime('%m/%d/%Y %I:%M %p',$userArray['blockedafter']) : ''; | ||
$userArray['lastlogin'] = !empty($userArray['lastlogin']) ? strftime('%m/%d/%Y',$userArray['lastlogin']) : ''; | ||
|
||
return $this->success('',$userArray); | ||
} | ||
|
||
/** | ||
* Get the User Groups for the user | ||
* @return array | ||
*/ | ||
public function getUserGroups() { | ||
$c = $this->modx->newQuery('modUserGroupMember'); | ||
$c->leftJoin('modUserGroupRole','UserGroupRole'); | ||
$c->innerJoin('modUserGroup','UserGroup'); | ||
$c->where(array( | ||
'member' => $this->user->get('id'), | ||
)); | ||
$c->select($this->modx->getSelectColumns('modUserGroupMember','modUserGroupMember')); | ||
$c->select(array( | ||
'role_name' => 'UserGroupRole.name', | ||
'user_group_name' => 'UserGroup.name', | ||
)); | ||
$members = $this->modx->getCollection('modUserGroupMember',$c); | ||
|
||
$data = array(); | ||
/** @var modUserGroupMember $member */ | ||
foreach ($members as $member) { | ||
$roleName = $member->get('role_name'); | ||
if ($member->get('role') == 0) { $roleName = $this->modx->lexicon('none'); } | ||
$data[] = array( | ||
$member->get('user_group'), | ||
$member->get('user_group_name'), | ||
$member->get('member'), | ||
$member->get('role'), | ||
empty($roleName) ? '' : $roleName, | ||
); | ||
} | ||
$this->user->set('groups','(' . $this->modx->toJSON($data) . ')'); | ||
return $data; | ||
} | ||
} | ||
return 'modProfileGetProcessor'; | ||
<?php | ||
/* | ||
* This file is part of MODX Revolution. | ||
* | ||
* Copyright (c) MODX, LLC. All Rights Reserved. | ||
* | ||
* For complete copyright and license information, see the COPYRIGHT and LICENSE | ||
* files found in the top-level directory of this distribution. | ||
*/ | ||
|
||
/** | ||
* Get a user profile | ||
* | ||
* @param integer $id The ID of the user | ||
* | ||
* @package modx | ||
* @subpackage processors.security.profile | ||
*/ | ||
class modProfileGetProcessor extends modProcessor { | ||
/** @var modUser $user */ | ||
public $user; | ||
|
||
public function checkPermissions() { | ||
return $this->modx->hasPermission('change_profile'); | ||
} | ||
|
||
public function getLanguageTopics() { | ||
return array('user'); | ||
} | ||
|
||
public function initialize() { | ||
$this->user = $this->modx->user; | ||
if (!$this->user) return $this->modx->lexicon('user_err_not_found'); | ||
return true; | ||
} | ||
|
||
public function process() { | ||
/* if set, get groups for user */ | ||
if ($this->getProperty('getGroups',false)) { | ||
$this->getUserGroups(); | ||
} | ||
|
||
$userArray = $this->user->toArray(); | ||
$profile = $this->user->getOne('Profile'); | ||
if ($profile) { | ||
$userArray = array_merge($profile->toArray(),$userArray); | ||
} | ||
|
||
$userArray['dob'] = !empty($userArray['dob']) ? strftime('%m/%d/%Y',$userArray['dob']) : ''; | ||
$userArray['blockeduntil'] = !empty($userArray['blockeduntil']) ? strftime('%m/%d/%Y %I:%M %p',$userArray['blockeduntil']) : ''; | ||
$userArray['blockedafter'] = !empty($userArray['blockedafter']) ? strftime('%m/%d/%Y %I:%M %p',$userArray['blockedafter']) : ''; | ||
$userArray['lastlogin'] = !empty($userArray['lastlogin']) ? strftime('%m/%d/%Y',$userArray['lastlogin']) : ''; | ||
|
||
unset($userArray['password'], $userArray['cachepwd'], $userArray['sessionid'], $userArray['salt']); | ||
return $this->success('',$userArray); | ||
} | ||
|
||
/** | ||
* Get the User Groups for the user | ||
* @return array | ||
*/ | ||
public function getUserGroups() { | ||
$c = $this->modx->newQuery('modUserGroupMember'); | ||
$c->leftJoin('modUserGroupRole','UserGroupRole'); | ||
$c->innerJoin('modUserGroup','UserGroup'); | ||
$c->where(array( | ||
'member' => $this->user->get('id'), | ||
)); | ||
$c->select($this->modx->getSelectColumns('modUserGroupMember','modUserGroupMember')); | ||
$c->select(array( | ||
'role_name' => 'UserGroupRole.name', | ||
'user_group_name' => 'UserGroup.name', | ||
)); | ||
$members = $this->modx->getCollection('modUserGroupMember',$c); | ||
|
||
$data = array(); | ||
/** @var modUserGroupMember $member */ | ||
foreach ($members as $member) { | ||
$roleName = $member->get('role_name'); | ||
if ($member->get('role') == 0) { $roleName = $this->modx->lexicon('none'); } | ||
$data[] = array( | ||
$member->get('user_group'), | ||
$member->get('user_group_name'), | ||
$member->get('member'), | ||
$member->get('role'), | ||
empty($roleName) ? '' : $roleName, | ||
); | ||
} | ||
$this->user->set('groups','(' . $this->modx->toJSON($data) . ')'); | ||
return $data; | ||
} | ||
} | ||
return 'modProfileGetProcessor'; |