Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  * @return mixed
  */
 public function process()
 {
     if ($this->modx->getOption('site_start') == $this->resource->get('id')) {
         return $this->failure($this->modx->lexicon('resource_err_delete_sitestart'));
     }
     if ($this->modx->getOption('site_unavailable_page') == $this->resource->get('id')) {
         return $this->failure($this->modx->lexicon('resource_err_delete_siteunavailable'));
     }
     /* check for locks on resource */
     if (!$this->addLock()) {
         return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->resource->get('id'), 'user' => $this->lockedUser->get('username'))));
     }
     $childrenIds = $this->getChildrenIds();
     $this->fireBeforeDelete($childrenIds);
     /* delete children */
     $this->deleteChildren();
     /* delete the document. */
     $this->resource->set('deleted', true);
     $this->resource->set('deletedby', $this->modx->user->get('id'));
     $this->resource->set('deletedon', $this->deletedTime);
     if ($this->resource->save() == false) {
         $this->resource->removeLock();
         return $this->failure($this->modx->lexicon('resource_err_delete'));
     }
     $this->fireAfterDelete($childrenIds);
     /* log manager action */
     $this->logManagerAction();
     $this->resource->removeLock();
     /* empty cache */
     $this->clearCache();
     return $this->success('', $this->resource->get(array('id', 'deleted', 'deletedby', 'deletedon')));
 }
Exemplo n.º 2
0
 public function process()
 {
     if (!$this->addLock()) {
         return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->resource->get('id'), 'user' => $this->lockedUser->get('username'))));
     }
     if ($this->isSiteStart()) {
         return $this->failure($this->modx->lexicon('resource_err_unpublish_sitestart'));
     }
     $this->resource->set('published', false);
     $this->resource->set('pub_date', false);
     $this->resource->set('unpub_date', false);
     $this->resource->set('editedby', $this->modx->user->get('id'));
     $this->resource->set('editedon', time(), 'integer');
     $this->resource->set('publishedby', false);
     $this->resource->set('publishedon', false);
     if ($this->resource->save() == false) {
         $this->resource->removeLock();
         return $this->failure($this->modx->lexicon('resource_err_unpublish'));
     }
     $this->fireAfterUnPublishEvent();
     $this->logManagerAction();
     $skipClearCache = $this->getProperty('skipClearCache', false);
     if ($skipClearCache == false) {
         $this->clearCache();
     }
     return $this->success('', $this->resource->get(array('id')));
 }
Exemplo n.º 3
0
 public function process()
 {
     if (!$this->addLock()) {
         return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->resource->get('id'), 'user' => $this->lockedUser->get('username'))));
     }
     /* 'undelete' the resource. */
     $this->resource->set('deleted', false);
     $this->resource->set('deletedby', 0);
     $this->resource->set('deletedon', 0);
     if ($this->resource->save() == false) {
         $this->resource->removeLock();
         return $this->failure($this->modx->lexicon('resource_err_undelete'));
     }
     $this->unDeleteChildren($this->resource->get('id'), $this->resource->get('deletedon'));
     $this->fireAfterUnDeleteEvent();
     /* log manager action */
     $this->logManagerAction();
     /* empty cache */
     $skipClearCache = $this->getProperty('skipClearCache', false);
     if ($skipClearCache == false) {
         $this->clearCache();
     }
     $this->removeLock();
     $deletedCount = $this->modx->getCount('modResource', array('deleted' => 1));
     $outputArray = $this->resource->get(array('id'));
     $outputArray['deletedCount'] = $deletedCount;
     return $this->modx->error->success('', $outputArray);
 }
Exemplo n.º 4
0
 public function process()
 {
     if (!$this->addLock()) {
         return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->resource->get('id'), 'user' => $this->lockedUser->get('username'))));
     }
     $duplicateAlias = $this->checkForDuplicateAlias();
     if ($duplicateAlias !== false) {
         return $this->failure($duplicateAlias);
     }
     /* publish resource */
     $this->resource->set('published', true);
     $this->resource->set('pub_date', false);
     $this->resource->set('unpub_date', false);
     $this->resource->set('editedby', $this->modx->user->get('id'));
     $this->resource->set('editedon', time(), 'integer');
     $this->resource->set('publishedby', $this->modx->user->get('id'));
     $this->resource->set('publishedon', time());
     $saved = $this->resource->save();
     $this->resource->removeLock();
     if (!$saved) {
         return $this->failure($this->modx->lexicon('resource_err_publish'));
     }
     $this->fireAfterPublish();
     $this->logManagerAction();
     $this->clearCache();
     return $this->success('', $this->resource->get(array('id', 'pub_date', 'unpub_date', 'editedby', 'editedon', 'publishedby', 'publishedon')));
 }
Exemplo n.º 5
0
 /** Actions after user is logged in
  *
  * @return array
  */
 public function afterLogin()
 {
     $this->addSessionContexts();
     $this->fireAfterLoginEvent();
     $this->modx->logManagerAction('login', 'modContext', $this->loginContext, $this->user->get('id'));
     return $this->prepareResponse();
 }
Exemplo n.º 6
0
 /**
  * If wanting to redirect after confirmed registration (for shopping carts)
  * Also allow &redirectBack parameter sent in confirmation email to redirect
  * to a form requiring registration
  */
 public function redirectBack()
 {
     $redirectBack = $this->modx->getOption('redirectBack', $_REQUEST, $this->getProperty('redirectBack', false, 'isset'));
     $redirectBackParams = $this->modx->getOption('redirectBackParams', $_REQUEST, $this->getProperty('redirectBackParams', ''));
     if (!empty($redirectBackParams)) {
         $redirectBackParams = $this->login->decodeParams($redirectBackParams);
     }
     $redirectTo = $this->getProperty('redirectTo', $redirectBack);
     if (!empty($redirectTo)) {
         /* allow custom redirection params */
         $redirectParams = $this->getProperty('redirectParams', $redirectBackParams);
         if (!empty($redirectParams) && !is_array($redirectParams)) {
             $redirectParams = $this->modx->fromJSON($redirectParams);
         }
         if (empty($redirectParams) || !is_array($redirectParams)) {
             $redirectParams = array();
         }
         /* handle persist params from Register snippet */
         $redirectUnsetDefaultParams = (bool) $this->getProperty('redirectUnsetDefaultParams', 0, 'isset');
         if (!$redirectUnsetDefaultParams) {
             $persistParams = $_GET;
             unset($persistParams['lp'], $persistParams['lu'], $persistParams['id']);
             $persistParams['username'] = $this->user->get('username');
             $persistParams['userid'] = $this->user->get('id');
             $redirectParams = array_merge($redirectParams, $persistParams);
             unset($redirectParams[$this->modx->getOption('request_param_alias', null, 'q')], $redirectParams['redirectBack']);
         }
         /* redirect user */
         $url = $this->modx->makeUrl($redirectTo, '', $redirectParams, 'full');
         $this->modx->sendRedirect($url);
     }
 }
Exemplo n.º 7
0
 /**
  * {@inheritDoc}
  * @return boolean|string
  */
 public function beforeSet()
 {
     $locked = $this->addLock();
     if ($locked !== true) {
         if ($this->lockedUser) {
             return $this->failure($this->modx->lexicon('resource_locked_by', array('id' => $this->object->get('id'), 'user' => $this->lockedUser->get('username'))));
         } else {
             return $this->failure($this->modx->lexicon('access_denied'));
         }
     }
     /* RTE workaround */
     $properties = $this->getProperties();
     if (isset($properties['ta'])) {
         $this->setProperty('content', $properties['ta']);
     }
     $this->workingContext = $this->modx->getContext($this->getProperty('context_key'));
     $this->trimPageTitle();
     $this->handleParent();
     $this->checkParentContext();
     $this->handleCheckBoxes();
     $this->checkFriendlyAlias();
     $this->setPublishDate();
     $this->setUnPublishDate();
     $this->checkPublishedOn();
     $this->checkPublishingPermissions();
     $this->checkForUnPublishOnSiteStart();
     $this->checkDeletedStatus();
     $this->handleResourceProperties();
     $this->unsetProperty('variablesmodified');
     return parent::beforeSet();
 }
Exemplo n.º 8
0
 /**
  * Return the pagetitle
  *
  * @return string
  */
 public function getPageTitle()
 {
     if ($this->user == null) {
         return $this->modx->lexicon('user_err_nf');
     } else {
         return $this->modx->lexicon('user') . ': ' . $this->user->get('username');
     }
 }
Exemplo n.º 9
0
 /**
  * Get the profile for the user
  * 
  * @return bool|modUserProfile
  */
 public function getProfile()
 {
     $this->profile = $this->user->getOne('Profile');
     if (empty($this->profile)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not find profile for user: '******'username'));
         return false;
     }
     return $this->profile;
 }
Exemplo n.º 10
0
 /**
  * Send the password notification email, if specified
  * @return void
  */
 public function sendNotificationEmail()
 {
     if ($this->getProperty('passwordnotifymethod') == 'e') {
         $message = $this->modx->getOption('signupemail_message');
         $placeholders = array('uid' => $this->object->get('username'), 'pwd' => $this->newPassword, 'ufn' => $this->profile->get('fullname'), 'sname' => $this->modx->getOption('site_name'), 'saddr' => $this->modx->getOption('emailsender'), 'semail' => $this->modx->getOption('emailsender'), 'surl' => $this->modx->getOption('url_scheme') . $this->modx->getOption('http_host') . $this->modx->getOption('manager_url'));
         foreach ($placeholders as $k => $v) {
             $message = str_replace('[[+' . $k . ']]', $v, $message);
         }
         $this->object->sendEmail($message);
     }
 }
Exemplo n.º 11
0
 /**
  * If allow_multiple_emails setting is false, prevent duplicate emails
  * @return void
  */
 public function preventDuplicateEmails()
 {
     $emailField = $this->getProperty('emailField', 'email');
     $email = $this->dictionary->get($emailField);
     if (!empty($email) && !$this->modx->getOption('allow_multiple_emails', null, false)) {
         $emailTaken = $this->modx->getObject('modUserProfile', array('email' => $email, 'internalKey:!=' => $this->user->get('id')));
         if ($emailTaken) {
             $this->validator->addError($emailField, $this->modx->lexicon('login.email_taken', array('email' => $email)));
         }
     }
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
0
 /**
  * Check for a redirect if the user was successfully registered. If one found, redirect.
  *
  * @return boolean
  */
 public function checkForRegisteredRedirect()
 {
     /* if provided a redirect id, will redirect to that resource, with the
      * GET params `username` and `email` for you to use */
     $submittedResourceId = $this->controller->getProperty('submittedResourceId', '');
     if (!empty($submittedResourceId)) {
         $persistParams = array_merge($this->persistParams, array('username' => $this->user->get('username'), 'email' => $this->profile->get('email')));
         $url = $this->modx->makeUrl($submittedResourceId, '', $persistParams, 'full');
         if (!$this->login->inTestMode) {
             $this->modx->sendRedirect($url);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
 public function alreadyExists($name)
 {
     return $this->modx->getCount('modUser', array('username' => $name, 'id:!=' => $this->user->get('id'))) > 0;
 }
Exemplo n.º 15
0
 /**
  * Called from modx plugin onlogin
  * @global modx $modx
  * @param modUser $oUser
  */
 public function onLoggedIn($oUser)
 {
     global $modx;
     FlexiLogger::info(__METHOD__, "user: "******"id")));
     $aGroupModel = $oUser->getMany("UserGroupMembers");
     $aGroup = array();
     FlexiLogger::info(__METHOD__, "Group cnt: " . count($aGroupModel));
     foreach ($aGroupModel as $oGroup) {
         $aDocGroup = $modx->getCollection("modAccessResourceGroup", array('principal_class' => 'modUserGroup', 'principal' => $oGroup->get("user_group")));
         //FlexiLogger::info(__METHOD__, "group id: " . $oGroup->get("user_group") . ", doc cnt: " . count($aDocGroup));
         foreach ($aDocGroup as $oDocGroup) {
             FlexiLogger::info(__METHOD__, "group id: " . $oDocGroup->get("target"));
             $aGroup[] = $docgroupid = $oDocGroup->get("target");
         }
     }
     $_SESSION['webDocgroups'] = $aGroup;
 }
Exemplo n.º 16
0
 /**
  * Prepare a user for listing
  * 
  * @param modUser $user
  * @return array
  */
 public function prepareUser(modUser $user)
 {
     return array('text' => $user->get('username'), 'id' => 'n_user_' . $user->get('id') . '_' . $this->userGroup->get('id'), 'leaf' => true, 'type' => 'user', 'cls' => 'icon-user');
 }
Exemplo n.º 17
0
 public function checkPolicy($criteria, $targets = null, modUser $user = null)
 {
     if (!$user) {
         $user =& $this->xpdo->user;
     }
     if ($criteria && $this->xpdo instanceof modX && $this->xpdo->getSessionState() == modX::SESSION_STATE_INITIALIZED) {
         if ($user->get('sudo')) {
             return true;
         }
         if (!is_array($criteria) && is_scalar($criteria)) {
             $criteria = array("{$criteria}" => true);
         }
         $policy = $this->findPolicy();
         if (!empty($policy)) {
             // print "sdfdfd";
             $principal = $user->getAttributes($targets);
             if (!empty($principal)) {
                 foreach ($policy as $policyAccess => $access) {
                     foreach ($access as $targetId => $targetPolicy) {
                         foreach ($targetPolicy as $policyIndex => $applicablePolicy) {
                             if ($this->xpdo->getDebug() === true) {
                                 $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'target pk=' . $this->getPrimaryKey() . '; evaluating policy: ' . print_r($applicablePolicy, 1) . ' against principal for user id=' . $user->id . ': ' . print_r($principal[$policyAccess], 1));
                             }
                             $principalPolicyData = array();
                             $principalAuthority = 9999;
                             if (isset($principal[$policyAccess][$targetId]) && is_array($principal[$policyAccess][$targetId])) {
                                 foreach ($principal[$policyAccess][$targetId] as $acl) {
                                     $principalAuthority = intval($acl['authority']);
                                     $principalPolicyData = $acl['policy'];
                                     $principalId = $acl['principal'];
                                     if ($applicablePolicy['principal'] == $principalId) {
                                         if ($principalAuthority <= $applicablePolicy['authority']) {
                                             if (!$applicablePolicy['policy']) {
                                                 return true;
                                             }
                                             if (empty($principalPolicyData)) {
                                                 $principalPolicyData = array();
                                             }
                                             $matches = array_intersect_assoc($principalPolicyData, $applicablePolicy['policy']);
                                             if ($matches) {
                                                 if ($this->xpdo->getDebug() === true) {
                                                     $this->xpdo->log(modX::LOG_LEVEL_DEBUG, 'Evaluating policy matches: ' . print_r($matches, 1));
                                                 }
                                                 $matched = array_diff_assoc($criteria, $matches);
                                                 if (empty($matched)) {
                                                     return true;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             return false;
         }
     }
     return true;
 }
Exemplo n.º 18
0
 public function getNewRank()
 {
     return $this->modx->getCount('modUserGroupMember', array('member' => $this->user->get('id')));
 }
Exemplo n.º 19
0
 public function getPageTitle()
 {
     return $this->modx->lexicon('discuss.user') . ': ' . $this->user->get('username');
 }
Exemplo n.º 20
0
 /**
  * See if the user is the active user
  * @return boolean
  */
 public function isSelf()
 {
     return $this->object->get('id') == $this->modx->user->get('id');
 }
Exemplo n.º 21
0
 /**
  * Test the overrides on xPDOObject::set for the user
  * 
  * @param string $field
  * @param mixed $value
  * @param mixed $expected
  * @dataProvider providerSet
  */
 public function testSet($field, $value, $expected)
 {
     $this->user->set($field, $value);
     $actual = $this->user->get($field);
     $this->assertEquals($expected, $actual);
 }
Exemplo n.º 22
0
 /**
  * Return the response chunk
  * @return string
  */
 public function getResponse()
 {
     $placeholders = array('username' => $this->user->get('username'), 'loginUrl' => $this->modx->makeUrl($this->getProperty('loginResourceId', 1)));
     return $this->login->getChunk($this->getProperty('tpl'), $placeholders, $this->getProperty('tplType', 'modChunk'));
 }
Exemplo n.º 23
0
 /**
  * @param modUser $user
  * @return bool
  */
 public function addLoginState($user)
 {
     $hash = '';
     $key = md5($_SERVER['REMOTE_ADDR'] . '/' . $_SERVER['HTTP_USER_AGENT'] . $user->id);
     $state = $this->getLoginState($key);
     if (empty($state)) {
         $ttl = $this->modx->getOption('admintools_authorization_ttl', null, 200);
         $hash = md5(uniqid(md5($user->get('email') . '/' . $key), true));
         $this->modx->registry->user->subscribe('/admintools/login/');
         $this->modx->registry->user->send('/admintools/login/', array($key => array('hash' => $hash, 'uid' => $user->get('id'))), array('ttl' => $ttl));
     }
     return $hash;
 }