/** * Get extended fields for a user * @return array */ public function getExtended() { $extended = array(); if ($this->getProperty('useExtended', true, 'isset')) { $extended = $this->profile->get('extended'); } return (array) $extended; }
/** * 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); } }
/** * Set the user data as placeholders * @return void */ public function setFieldPlaceholders() { $placeholders = $this->profile->toArray(); /* add extended fields to placeholders */ if ($this->getProperty('useExtended', true, 'isset')) { $extended = $this->profile->get('extended'); if (!empty($extended) && is_array($extended)) { $placeholders = array_merge($extended, $placeholders); } } $this->modx->toPlaceholders($placeholders, $this->getProperty('placeholderPrefix')); }
/** * 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; }
/** * Set the user data as placeholders * @return void */ public function setFieldPlaceholders() { $placeholders = $this->profile->toArray(); $placeholderPrefix = rtrim($this->getProperty('placeholderPrefix'), '.'); /* add extended fields to placeholders */ if ($this->getProperty('useExtended', true)) { $extended = $this->profile->get('extended'); if (!empty($extended) && is_array($extended)) { $placeholders = array_merge($extended, $placeholders); } } $this->modx->toPlaceholders($placeholders, $placeholderPrefix); foreach ($placeholders as $k => $v) { if (is_array($v)) { $this->modx->setPlaceholder($placeholderPrefix . '.' . $k, json_encode($v)); } } }
/** * Allow changing of username for user via syncUsername property * @return boolean */ public function syncUsername() { $synced = true; $syncUsername = $this->controller->getProperty('syncUsername', false, 'isset'); $this->oldUsername = $this->controller->user->get('username'); if (!empty($syncUsername)) { $newUsername = $this->profile->get($syncUsername); if (!empty($newUsername) && strcmp($newUsername, $this->oldUsername) != 0) { $alreadyExists = $this->modx->getCount('modUser', array('username' => $newUsername)); if (!empty($alreadyExists)) { $synced = false; } else { $this->controller->user->set('username', $newUsername); $this->usernameChanged = true; $synced = $this->controller->user->save(); } } } return $synced; }
/** * 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; }