public function setProfile() { $this->profile = $this->object->getOne('Profile'); if (empty($this->profile)) { $this->profile = $this->modx->newObject('modUserProfile'); $this->profile->set('internalKey', $this->object->get('id')); $this->profile->save(); $this->object->addOne($this->profile, 'Profile'); } $this->profile->fromArray($this->getProperties()); return $this->profile; }
/** * Setup the user data and create the user/profile objects * * @return void */ public function setUserFields() { $fields = $this->dictionary->toArray(); /* allow overriding of class key */ if (empty($fields['class_key'])) { $fields['class_key'] = 'modUser'; } $fields = $this->filterAllowedFields($fields); /* set user and profile */ $this->user->fromArray($fields); $this->user->set('username', $fields[$this->controller->getProperty('usernameField', 'username')]); $this->user->set('active', 0); $version = $this->modx->getVersionData(); /* 2.1.x+ */ if (version_compare($version['full_version'], '2.1.0-rc1') >= 0) { $this->user->set('password', $fields[$this->controller->getProperty('passwordField', 'password')]); } else { /* 2.0.x */ $this->user->set('password', md5($fields[$this->controller->getProperty('passwordField', 'password')])); } $this->profile->fromArray($fields); $this->profile->set('email', $this->dictionary->get($this->controller->getProperty('emailField', 'email'))); $this->user->addOne($this->profile, 'Profile'); /* add user groups, if set */ $userGroupsField = $this->controller->getProperty('usergroupsField', ''); $userGroups = !empty($userGroupsField) && array_key_exists($userGroupsField, $fields) ? $fields[$userGroupsField] : array(); $this->setUserGroups($userGroups); }
/** * @return modUserProfile */ public function addProfile() { $this->profile = $this->modx->newObject('modUserProfile'); $this->profile->fromArray($this->getProperties()); $this->profile->set('blocked', $this->getProperty('blocked', false)); $this->profile->set('photo', ''); $this->object->addOne($this->profile, 'Profile'); return $this->profile; }
/** * Set the form fields to the user * @return void */ public function setFields() { $allowedFields = $this->controller->getProperty('allowedFields', ''); $allowedFields = !empty($allowedFields) ? explode(',', $allowedFields) : array(); $fields = $this->controller->dictionary->toArray(); foreach ($fields as $key => $value) { $isValidField = true; if (!empty($allowedFields)) { if (!in_array($key, $allowedFields)) { $isValidField = false; } } if ($isValidField) { $this->profile->set($key, $value); } } }
public function checkBlocked() { /* blocked until */ $blockedUntil = $this->processor->getProperty('blockeduntil'); if (!empty($blockedUntil)) { $blockedUntil = str_replace('-', '/', $blockedUntil); if (!($blockedUntil = strtotime($blockedUntil))) { $this->processor->addFieldError('blockeduntil', $this->modx->lexicon('user_err_not_specified_blockeduntil')); } $this->processor->setProperty('blockeduntil', $blockedUntil); $this->profile->set('blockeduntil', $blockedUntil); } /* blocked after */ $blockedAfter = $this->processor->getProperty('blockedafter'); if (!empty($blockedAfter)) { $blockedAfter = str_replace('-', '/', $blockedAfter); if (!($blockedAfter = strtotime($blockedAfter))) { $this->processor->addFieldError('blockedafter', $this->modx->lexicon('user_err_not_specified_blockedafter')); } $this->processor->setProperty('blockedafter', $blockedAfter); $this->profile->set('blockedafter', $blockedAfter); } }
/** * Sync the User's Profile with the ActiveDirectory data * * TODO: After Revo 2.0.1, move this to modActiveDirectoryUser. Cant now * because class isnt accessible from onauthenticate * * @param modUserProfile $profile * @param array $data An array of userinfo data * @return boolean */ public function syncProfile(modUserProfile &$profile, $data) { /* map of ActiveDirectory => MODx Profile fields */ $map = array('name' => 'fullname', 'mail' => 'email', 'streetaddress' => 'address', 'l' => 'city', 'st' => 'state', 'co' => 'country', 'postalcode' => 'zip', 'mobile' => 'mobilephone', 'telephonenumber' => 'phone', 'info' => 'comment', 'wwwhomepage' => 'website'); foreach ($data as $k => $v) { if (!is_array($v) || !array_key_exists($k, $map)) { continue; } $this->modx->log(xPDO::LOG_LEVEL_DEBUG, '[ActiveDirectory] Syncing field "' . $map[$k] . '" to: "' . $v[0] . '"'); $profile->set($map[$k], $v[0]); } $id = $profile->get('internalKey'); if (!empty($id)) { $saved = $profile->save(); } //$saved = $user->syncProfile($userInfo); if (!$saved) { $this->modx->log(modX::LOG_LEVEL_INFO, '[ActiveDirectory] User Profile information was unable to be synced.'); } return $saved; }