Files
luos/workflow/engine/classes/model/UsersProperties.php

544 lines
20 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
2017-08-01 12:16:06 -04:00
use ProcessMaker\Plugins\PluginRegistry;
2010-12-02 23:34:41 +00:00
require_once 'classes/model/om/BaseUsersProperties.php';
/**
* Skeleton subclass for representing a row from the 'USERS_PROPERTIES' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
2010-12-02 23:34:41 +00:00
* long as it does not already exist in the output directory.
2011-02-03 11:13:21 +00:00
*/
/**
*
* @package workflow.engine.classes.model
2010-12-02 23:34:41 +00:00
*/
class UsersProperties extends BaseUsersProperties
{
public $fields = null;
public $usrID = '';
public $lang = 'en';
2017-12-04 13:25:35 +00:00
public function __construct()
{
2017-12-04 13:25:35 +00:00
$this->lang = defined('SYS_LANG') ? SYS_LANG : 'en';
}
2017-12-04 13:25:35 +00:00
public function UserPropertyExists($sUserUID)
{
2017-12-04 13:25:35 +00:00
$oUserProperty = UsersPropertiesPeer::retrieveByPk($sUserUID);
if (! is_null($oUserProperty) && is_object($oUserProperty) && get_class($oUserProperty) == 'UsersProperties') {
$this->fields = $oUserProperty->toArray(BasePeer::TYPE_FIELDNAME);
$this->fromArray($this->fields, BasePeer::TYPE_FIELDNAME);
return true;
} else {
return false;
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
public function load($sUserUID)
{
2017-12-04 13:25:35 +00:00
$oUserProperty = UsersPropertiesPeer::retrieveByPK($sUserUID);
if (! is_null($oUserProperty)) {
$aFields = $oUserProperty->toArray(BasePeer::TYPE_FIELDNAME);
$this->fromArray($aFields, BasePeer::TYPE_FIELDNAME);
return $aFields;
} else {
2017-12-04 13:25:35 +00:00
throw new Exception("User with $sUserUID does not exist!");
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
public function create($aData)
{
2017-12-04 13:25:35 +00:00
$oConnection = Propel::getConnection(UsersPropertiesPeer::DATABASE_NAME);
try {
$oUserProperty = new UsersProperties();
2017-12-04 13:25:35 +00:00
$oUserProperty->fromArray($aData, BasePeer::TYPE_FIELDNAME);
if ($oUserProperty->validate()) {
$oConnection->begin();
$iResult = $oUserProperty->save();
$oConnection->commit();
return true;
} else {
$sMessage = '';
$aValidationFailures = $oUserProperty->getValidationFailures();
foreach ($aValidationFailures as $oValidationFailure) {
$sMessage .= $oValidationFailure->getMessage() . '<br />';
}
2017-12-04 13:25:35 +00:00
throw (new Exception('The registry cannot be created!<br />' . $sMessage));
}
} catch (Exception $oError) {
$oConnection->rollback();
throw ($oError);
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
public function update($aData)
{
2017-12-04 13:25:35 +00:00
$oConnection = Propel::getConnection(UsersPropertiesPeer::DATABASE_NAME);
try {
2017-12-04 13:25:35 +00:00
$oUserProperty = UsersPropertiesPeer::retrieveByPK($aData['USR_UID']);
if (! is_null($oUserProperty)) {
$oUserProperty->fromArray($aData, BasePeer::TYPE_FIELDNAME);
if ($oUserProperty->validate()) {
$oConnection->begin();
$iResult = $oUserProperty->save();
$oConnection->commit();
return $iResult;
} else {
$sMessage = '';
$aValidationFailures = $oUserProperty->getValidationFailures();
foreach ($aValidationFailures as $oValidationFailure) {
$sMessage .= $oValidationFailure->getMessage() . '<br />';
}
2017-12-04 13:25:35 +00:00
throw (new Exception('The registry cannot be updated!<br />' . $sMessage));
}
} else {
2017-12-04 13:25:35 +00:00
throw (new Exception('This row doesn\'t exist!'));
}
} catch (Exception $oError) {
$oConnection->rollback();
throw ($oError);
2010-12-02 23:34:41 +00:00
}
}
2017-12-04 13:25:35 +00:00
public function loadOrCreateIfNotExists($sUserUID, $aUserProperty = array())
{
2017-12-04 13:25:35 +00:00
if (! $this->UserPropertyExists($sUserUID)) {
$aUserProperty['USR_UID'] = $sUserUID;
2017-12-04 13:25:35 +00:00
if (! isset($aUserProperty['USR_LAST_UPDATE_DATE'])) {
$aUserProperty['USR_LAST_UPDATE_DATE'] = date('Y-m-d H:i:s');
}
2017-12-04 13:25:35 +00:00
if (! isset($aUserProperty['USR_LOGGED_NEXT_TIME'])) {
$aUserProperty['USR_LOGGED_NEXT_TIME'] = 0;
}
2017-12-04 13:25:35 +00:00
$this->create($aUserProperty);
} else {
$aUserProperty = $this->fields;
}
return $aUserProperty;
2010-12-02 23:34:41 +00:00
}
2018-10-26 16:14:37 -04:00
/**
* This function will be validate the password policies
*
* @param string $password
* @param string $lastUpdate
* @param integer $changePassword
* @param boolean $nowLogin
*
* @return array
*/
public function validatePassword($password, $lastUpdate, $changePassword, $nowLogin = false)
{
2018-10-26 16:14:37 -04:00
if (!defined('PPP_MINIMUM_LENGTH')) {
2017-12-04 13:25:35 +00:00
define('PPP_MINIMUM_LENGTH', 5);
2010-12-02 23:34:41 +00:00
}
2018-10-26 16:14:37 -04:00
if (!defined('PPP_MAXIMUM_LENGTH')) {
2017-12-04 13:25:35 +00:00
define('PPP_MAXIMUM_LENGTH', 20);
2010-12-02 23:34:41 +00:00
}
2018-10-26 16:14:37 -04:00
if (!defined('PPP_NUMERICAL_CHARACTER_REQUIRED')) {
2017-12-04 13:25:35 +00:00
define('PPP_NUMERICAL_CHARACTER_REQUIRED', 0);
}
2018-10-26 16:14:37 -04:00
if (!defined('PPP_UPPERCASE_CHARACTER_REQUIRED')) {
2017-12-04 13:25:35 +00:00
define('PPP_UPPERCASE_CHARACTER_REQUIRED', 0);
}
2018-10-26 16:14:37 -04:00
if (!defined('PPP_SPECIAL_CHARACTER_REQUIRED')) {
2017-12-04 13:25:35 +00:00
define('PPP_SPECIAL_CHARACTER_REQUIRED', 0);
}
2018-10-26 16:14:37 -04:00
if (!defined('PPP_EXPIRATION_IN')) {
2017-12-04 13:25:35 +00:00
define('PPP_EXPIRATION_IN', 0);
}
2018-10-26 16:14:37 -04:00
$lengthPassword = function_exists('mb_strlen') ? mb_strlen($password): strlen($password);
$listErrors = [];
//The password has the minimum length
if ($lengthPassword < PPP_MINIMUM_LENGTH || $nowLogin) {
$listErrors[] = 'ID_PPP_MINIMUM_LENGTH';
}
2018-10-26 16:14:37 -04:00
//The password has the maximum length
if ($lengthPassword > PPP_MAXIMUM_LENGTH || $nowLogin) {
$listErrors[] = 'ID_PPP_MAXIMUM_LENGTH';
}
2018-10-26 16:14:37 -04:00
//The password requires a number
if (PPP_NUMERICAL_CHARACTER_REQUIRED == 1) {
2018-10-26 16:14:37 -04:00
if (preg_match_all('/[0-9]/', $password, $aMatch,
PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) == 0 || $nowLogin) {
$listErrors[] = 'ID_PPP_NUMERICAL_CHARACTER_REQUIRED';
}
}
2018-10-26 16:14:37 -04:00
//The password requires a upper case
if (PPP_UPPERCASE_CHARACTER_REQUIRED == 1) {
2018-10-26 16:14:37 -04:00
if (preg_match_all('/[A-Z]/', $password, $aMatch,
PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) == 0 || $nowLogin) {
$listErrors[] = 'ID_PPP_UPPERCASE_CHARACTER_REQUIRED';
}
}
2018-10-26 16:14:37 -04:00
//The password requires a special character
if (PPP_SPECIAL_CHARACTER_REQUIRED == 1) {
2018-10-26 16:14:37 -04:00
if (preg_match_all('/[<5B><>\\!|"@<40>#$~%<25>&<26>\/()=\'?<3F><>*+\-_.:,;]/', $password, $aMatch,
PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) == 0 || $nowLogin) {
$listErrors[] = 'ID_PPP_SPECIAL_CHARACTER_REQUIRED';
}
}
2018-10-26 16:14:37 -04:00
//The configuration PPP_EXPIRATION_IN is saved in hours
if (PPP_EXPIRATION_IN > 0) {
2018-10-26 16:14:37 -04:00
$hoursBetweenDates = (strtotime(date('Y-m-d H:i:s')) - strtotime($lastUpdate)) / (60 * 60);
if ($hoursBetweenDates > PPP_EXPIRATION_IN || $nowLogin) {
$listErrors[] = 'ID_PPP_EXPIRATION_IN';
$changePassword = 1;
}
2018-10-26 16:14:37 -04:00
}
//Spaces not supported at the end of passwords
if (substr($password, -1) === " ") {
$listErrors[] = 'ID_PPP_SPACES_NOT_SUPPORTED_AT_THE_END_OF_PASSWORD';
}
2018-10-26 16:14:37 -04:00
if ($changePassword == 1) {
$listErrors[] = 'ID_PPP_CHANGE_PASSWORD_AFTER_NEXT_LOGIN';
}
2018-10-26 16:14:37 -04:00
return $listErrors;
}
/**
* This function will be get the message for show what policies does not complied
*
* @param array $errorsInPassword
* @param boolean $afterFillingPass
* @param boolean $onlyText
*
* @return array
*/
public function getMessageValidatePassword($errorsInPassword, $afterFillingPass = true, $onlyText = false){
$messPassword = [];
$policyErrors = false;
if ($afterFillingPass) {
$policyMessage = G::LoadTranslation('ID_POLICY_ALERT');
} else {
$policyMessage = G::LoadTranslation('ID_POLICY_ALERT_INFO');
}
$policyMessage .= ($onlyText) ? ' ' : '<br/><br/>';
foreach ($errorsInPassword as $error) {
switch ($error) {
case 'ID_PPP_CHANGE_PASSWORD_AFTER_NEXT_LOGIN':
//Does not consider a policy for the final user, the administrator request to change password
$messPassword[substr($error, 3)] = PPP_MINIMUM_LENGTH;
break;
case 'ID_PPP_MINIMUM_LENGTH':
$policyErrors = true;
$policyMessage .= '- ' . G::LoadTranslation($error) . ': ' . PPP_MINIMUM_LENGTH;
$policyMessage .= ($onlyText) ? '. ' : '<br/>';
$messPassword[substr($error, 3)] = PPP_MINIMUM_LENGTH;
$messPassword['PPP_MINIMUN_LENGTH'] = PPP_MINIMUM_LENGTH;
break;
case 'ID_PPP_MAXIMUM_LENGTH':
$policyErrors = true;
$policyMessage .= '- ' . G::LoadTranslation($error) . ': ' . PPP_MAXIMUM_LENGTH;
$policyMessage .= ($onlyText) ? '. ' : '<br/>';
$messPassword[substr($error, 3)] = PPP_MAXIMUM_LENGTH;
$messPassword['PPP_MAXIMUN_LENGTH'] = PPP_MAXIMUM_LENGTH;
break;
case 'ID_PPP_EXPIRATION_IN':
//Does not consider a policy for the final user, this is enhanced login configuration
$messPassword[substr($error, 3)] = PPP_EXPIRATION_IN;
break;
default:
//PPP_NUMERICAL_CHARACTER_REQUIRED
//PPP_UPPERCASE_CHARACTER_REQUIRED
//PPP_SPECIAL_CHARACTER_REQUIRED
$policyErrors = true;
$policyMessage .= '- ' . G::LoadTranslation($error);
$policyMessage .= ($onlyText) ? '. ' : '<br/>';
$messPassword[substr($error, 3)] = 1;
break;
}
}
2018-10-26 16:14:37 -04:00
if ($afterFillingPass){
$policyMessage .= G::LoadTranslation('ID_PLEASE_CHANGE_PASSWORD_POLICY');
}
2018-10-26 16:14:37 -04:00
$messPassword['DESCRIPTION'] = ($policyErrors) ? $policyMessage : '';
return $messPassword;
2010-12-02 23:34:41 +00:00
}
/**
* get user location
* defined by precedence plugin->ux->default
*/
2017-12-04 13:25:35 +00:00
public function redirectTo($usrID, $lang = '')
{
$this->usrID = $usrID;
2017-12-04 13:25:35 +00:00
$this->lang = empty($lang) ? $this->lang : $lang;
2010-12-02 23:34:41 +00:00
$url = $this->_getPluginLocation();
2017-12-04 13:25:35 +00:00
if (empty($url)) {
$url = $this->_getUXLocation();
}
$urlUx = $this->_getUXSkinVariant();
2017-12-04 13:25:35 +00:00
if (empty($url) && ! empty($urlUx)) {
$_SESSION['_defaultUserLocation'] = $url;
$url = $urlUx;
}
2017-12-04 13:25:35 +00:00
if (empty($url)) {
$url = $this->_getDefaultLocation();
}
return $url;
}
/**
* get user location
* defined by precedence plugin->default
* note that is getting location without User Inbox Simplified varification
*/
2017-12-04 13:25:35 +00:00
public function getUserLocation($usrID, $lang = 'en')
{
$this->usrID = $usrID;
2017-12-04 13:25:35 +00:00
$this->lang = empty($lang) ? $this->lang : $lang;
$url = $this->_getPluginLocation();
2017-12-04 13:25:35 +00:00
if (empty($url)) {
$url = $this->_getDefaultLocation();
}
$urlUx = $this->_getUXSkinVariant();
2017-12-04 13:25:35 +00:00
if (! empty($urlUx)) {
$_SESSION['_defaultUserLocation'] = $url;
$url = $urlUx;
}
return $url;
}
/**
* to verify if the user is using some "ux..." skin variant
* if that is the case, the redirection will change to 'main' controller
*/
2017-12-04 13:25:35 +00:00
public function _getUXSkinVariant()
{
$url = '';
2017-12-04 13:25:35 +00:00
if (substr(SYS_SKIN, 0, 2) == 'ux' && SYS_SKIN != 'uxs') {
if (isset($_COOKIE['workspaceSkin'])) {
2017-12-04 13:25:35 +00:00
if (substr($_COOKIE['workspaceSkin'], 0, 2) != 'ux') {
$url = $this->_getDefaultLocation();
return $url;
} else {
2017-10-10 12:33:25 -04:00
$url = '/sys' . config("system.workspace") . '/' . $this->lang . '/' . $_COOKIE['workspaceSkin'] . '/main';
}
} else {
2017-10-10 12:33:25 -04:00
$url = '/sys' . config("system.workspace") . '/' . $this->lang . '/' . SYS_SKIN . '/main';
}
global $RBAC;
$oConf = new Configurations();
2017-12-04 13:25:35 +00:00
$oConf->loadConfig($x, 'USER_PREFERENCES', '', '', $_SESSION['USER_LOGGED'], '');
2019-07-26 08:36:37 -04:00
if (isset($oConf->aConfig['DEFAULT_MENU'])) {
if ($oConf->aConfig['DEFAULT_MENU'] == 'PM_USERS') {
$oConf->aConfig['DEFAULT_MENU'] = 'PM_SETUP';
}
$getUrl = null;
switch ($oConf->aConfig['DEFAULT_MENU']) {
case 'PM_SETUP':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_SETUP') == 1) {
$getUrl = 'admin';
}
break;
case 'PM_FACTORY':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_FACTORY') == 1) {
$getUrl = 'designer';
}
break;
case 'PM_CASES':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_CASES') == 1) {
$getUrl = 'home';
}
break;
case 'PM_USERS':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_USERS') == 1) {
$getUrl = 'admin';
}
break;
case 'PM_DASHBOARD':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_DASHBOARD') == 1) {
$getUrl = 'dashboard';
}
break;
}
$url = $url . (($getUrl != null) ? "?st=" . $getUrl : null);
}
}
return $url;
}
/**
* get the plugins, and check if there is redirectLogins
* if yes, then redirect goes according his Role
*/
2017-12-04 13:25:35 +00:00
public function _getPluginLocation()
{
global $RBAC;
$url = '';
2017-12-04 13:25:35 +00:00
if (class_exists('redirectDetail')) {
//to do: complete the validation
2017-12-04 13:25:35 +00:00
if (isset($RBAC->aUserInfo['PROCESSMAKER']['ROLE']['ROL_CODE'])) {
$userRole = $RBAC->aUserInfo['PROCESSMAKER']['ROLE']['ROL_CODE'];
}
2017-08-01 12:16:06 -04:00
$oPluginRegistry = PluginRegistry::loadSingleton();
$aRedirectLogin = $oPluginRegistry->getRedirectLogins();
2017-08-04 09:32:25 -04:00
if (isset($aRedirectLogin) && is_array($aRedirectLogin)) {
/** @var \ProcessMaker\Plugins\Interfaces\RedirectDetail $detail */
foreach ($aRedirectLogin as $detail) {
$pathMethod = $detail->getPathMethod();
if (isset($pathMethod) && $detail->equalRoleCodeTo($userRole)) {
if (isset($_COOKIE['workspaceSkin'])) {
2017-10-10 12:33:25 -04:00
$url = '/sys' . config("system.workspace") . '/' . $this->lang . '/' . $_COOKIE['workspaceSkin'] . '/' . $pathMethod;
} else {
2017-10-10 12:33:25 -04:00
$url = '/sys' . config("system.workspace") . '/' . $this->lang . '/' . SYS_SKIN . '/' . $pathMethod;
}
}
}
}
}
return $url;
}
/**
* New feature - User Experience Redirector
*
* @author Erik Amaru Ortiz <erik@colosa.com>
*/
2017-12-04 13:25:35 +00:00
public function _getUXLocation()
{
require_once 'classes/model/Users.php';
2017-12-04 13:25:35 +00:00
$u = UsersPeer::retrieveByPK($this->usrID);
$url = '';
$uxType = $u->getUsrUx();
$_SESSION['user_experience'] = 'NORMAL';
// find a group setting
if ($uxType == '' || $uxType == 'NORMAL') {
require_once 'classes/model/GroupUser.php';
$gu = new GroupUser();
2017-12-04 13:25:35 +00:00
$ugList = $gu->getAllUserGroups($this->usrID);
foreach ($ugList as $row) {
if ($row['GRP_UX'] != 'NORMAL' && $row['GRP_UX'] != '') {
$uxType = $row['GRP_UX'];
break;
}
}
}
switch ($uxType) {
case 'SIMPLIFIED':
case 'SWITCHABLE':
case 'SINGLE':
$_SESSION['user_experience'] = $uxType;
$_SESSION['user_last_skin'] = SYS_SKIN;
2017-10-10 12:33:25 -04:00
$url = '/sys' . config("system.workspace") . '/' . $this->lang . '/uxs/' . 'home';
break;
}
return $url;
}
/**
* get user preferences for default redirect
* verifying if it has any preferences on configurations table
*/
2017-12-04 13:25:35 +00:00
public function _getDefaultLocation()
{
global $RBAC;
$oConf = new Configurations();
2017-12-04 13:25:35 +00:00
$oConf->loadConfig($x, 'USER_PREFERENCES', '', '', $_SESSION['USER_LOGGED'], '');
if (isset($_COOKIE['workspaceSkin'])) {
2017-10-10 12:33:25 -04:00
$baseUrl = '/sys' . config("system.workspace") . '/' . $this->lang . '/' . $_COOKIE['workspaceSkin'] . '/';
} else {
2017-10-10 12:33:25 -04:00
$baseUrl = '/sys' . config("system.workspace") . '/' . $this->lang . '/' . SYS_SKIN . '/';
}
$url = '';
2019-07-26 08:36:37 -04:00
if (isset($oConf->aConfig['DEFAULT_MENU'])) {
// this user has a configuration record
// backward compatibility, because now, we don't have user and dashboard menu.
if ($oConf->aConfig['DEFAULT_MENU'] == 'PM_USERS') {
$oConf->aConfig['DEFAULT_MENU'] = 'PM_SETUP';
}
switch ($oConf->aConfig['DEFAULT_MENU']) {
case 'PM_SETUP':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_SETUP') == 1 || $RBAC->userCanAccess('PM_USERS') == 1) {
$url = 'setup/main';
}
break;
case 'PM_FACTORY':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_FACTORY') == 1) {
$url = 'processes/main';
}
break;
case 'PM_CASES':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_CASES') == 1) {
$url = 'cases/main';
}
break;
case 'PM_USERS':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_USERS') == 1) {
$url = 'setup/main';
}
break;
case 'PM_DASHBOARD':
2017-12-04 13:25:35 +00:00
if ($RBAC->userCanAccess('PM_DASHBOARD') == 1) {
$url = 'dashboard/main';
}
break;
2015-04-06 11:45:30 -04:00
/*----------------------------------********---------------------------------*/
case 'PM_STRATEGIC_DASHBOARD':
2017-12-04 13:25:35 +00:00
$licensedFeatures = PMLicensedFeatures::getSingleton();
if ($licensedFeatures->verifyfeature('r19Vm5DK1UrT09MenlLYjZxejlhNUZ1b1NhV0JHWjBsZEJ6dnpJa3dTeWVLVT0=') && $RBAC->userCanAccess('PM_SETUP') == 1) {
$url = 'strategicDashboard/main';
}
break;
2015-04-06 11:45:30 -04:00
/*----------------------------------********---------------------------------*/
}
}
2017-12-04 13:25:35 +00:00
if (empty($url)) {
if ($RBAC->userCanAccess('PM_FACTORY') == 1) {
$url = 'processes/main';
2017-12-04 13:25:35 +00:00
} elseif ($RBAC->userCanAccess('PM_SETUP') == 1) {
$url = 'setup/main';
2017-12-04 13:25:35 +00:00
} elseif ($RBAC->userCanAccess('PM_CASES') == 1) {
$url = 'cases/main';
2017-12-04 13:25:35 +00:00
} elseif ($RBAC->userCanAccess('PM_USERS') == 1) {
$url = 'setup/main';
2017-12-04 13:25:35 +00:00
} elseif ($RBAC->userCanAccess('PM_DASHBOARD') == 1) {
$url = 'dashboard/dashboard';
} else {
$url = 'users/myInfo';
}
}
2010-12-02 23:34:41 +00:00
return $baseUrl . $url;
2010-12-02 23:34:41 +00:00
}
}