示例#1
0
 public function prepare()
 {
     $properties = $this->getProperties();
     /* format and set data */
     $dob = $this->getProperty('dob');
     if (!empty($dob)) {
         $properties['dob'] = strtotime($dob);
     }
     $this->profile->fromArray($properties);
 }
 /**
  * Get the Profile of the active User
  * @return modUserProfile
  */
 public function getProfile()
 {
     $this->profile = $this->modx->user->getOne('Profile');
     if (empty($this->profile)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not find profile for user: '******'username'));
     } else {
         $placeholders = array_merge($this->profile->toArray(), array('username' => $this->modx->user->get('username'), 'id' => $this->modx->user->get('id')));
         $this->modx->setPlaceholders($placeholders, $this->getProperty('placeholderPrefix', 'logcp.'));
     }
     return $this->profile;
 }
示例#3
0
 /**
  * Fetch the user to update, also allowing external user updating
  * @return modUser
  */
 public function fetchUser()
 {
     $fields = $this->dictionary->toArray();
     $this->usernameField = 'username';
     $alias = 'modUser';
     if (empty($fields['username']) && !empty($fields['email'])) {
         $this->usernameField = 'email';
         $alias = 'Profile';
     }
     /* if the preHook didn't set the user info, find it by email/username */
     if (empty($fields[Login::FORGOT_PASSWORD_EXTERNAL_USER])) {
         /* get the user dependent on the retrieval method */
         $this->user = $this->login->getUserByField($this->usernameField, $fields[$this->usernameField], $alias);
         if ($this->user) {
             $fields = array_merge($fields, $this->user->toArray());
             $this->profile = $this->user->getOne('Profile');
             if ($this->profile) {
                 /* merge in profile */
                 $fields = array_merge($this->profile->toArray(), $fields);
             }
         }
     }
     $this->dictionary->fromArray($fields);
     return $this->user;
 }
 /**
  * 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;
 }
示例#5
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);
     }
 }
 /**
  * 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'));
 }
 public function setUp()
 {
     parent::setUp();
     $this->user = $this->modx->newObject('modUser');
     $this->user->fromArray(array('id' => 12345678, 'username' => 'unit.test.user', 'password' => md5('a test password'), 'cachepwd' => '', 'class_key' => 'modUser', 'active' => false, 'hash_class' => 'hashing.modMD5', 'salt' => '', 'primary_group' => 1, 'email' => LoginTestHarness::$properties['email']));
     $this->profile = $this->modx->newObject('modUserProfile');
     $this->profile->fromArray(array('internalKey' => 12345678, 'email' => LoginTestHarness::$properties['email'], 'blocked' => false));
     /** @var modUserGroup $userGroup */
     $userGroup = $this->modx->newObject('modUserGroup');
     $userGroup->fromArray(array('name' => 'UnitTest UserGroup 1'));
     $userGroup->save();
     $userGroup = $this->modx->newObject('modUserGroup');
     $userGroup->fromArray(array('name' => 'UnitTest UserGroup 2'));
     $userGroup->save();
     $_POST = array('username' => 'unit.test.user', 'password' => 'a test password', 'email' => '*****@*****.**', 'nospam' => '', 'submitVar' => 'unit-test-register-btn');
     $this->controller = $this->login->loadController('Register');
     $this->controller->initialize();
     $this->controller->setProperties(array('activation' => true, 'activationResourceId' => 1, 'activationEmailSubject' => 'Login Unit Test Activation Email', 'moderatedResourceId' => 1, 'preHooks' => '', 'postHooks' => '', 'submitVar' => 'unit-test-register-btn', 'submittedResourceId' => 1, 'usergroups' => '', 'validate' => 'nospam:blank'));
     $this->controller->loadDictionary();
     $this->processor = $this->controller->loadProcessor('Register');
     $this->processor->user =& $this->user;
     $this->processor->profile =& $this->profile;
 }
 /**
  * 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;
 }
示例#9
0
 /**
  * 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;
 }
示例#11
0
 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;
 }
示例#13
0
 /**
  * @param array $data
  */
 public function OnUserSave(array $data)
 {
     if (!defined('SMF') || SMF != 'API') {
         return;
     }
     /** @var modUser $user */
     $user = $data['user'];
     if (!$user || !$user instanceof modUser) {
         return;
     }
     /** @var modUserProfile $profile */
     $profile = $user->getOne('Profile');
     $password = !empty($_REQUEST['specifiedpassword']) && !empty($_REQUEST['confirmpassword']) && $_REQUEST['specifiedpassword'] == $_REQUEST['confirmpassword'] ? $_REQUEST['specifiedpassword'] : '';
     $username = !empty($this->_user) ? $this->_user->username : $user->username;
     if (!smfapi_getUserByUsername($username)) {
         $this->addUserToSMF($user->username);
     } else {
         $update = array('member_name' => 'username', 'email_address' => 'email', 'real_name' => 'fullname', 'date_registered' => 'createdon', 'birthdate' => 'dob', 'website_url' => 'website', 'location' => 'city', 'gender' => 'gender');
         // New MODX user
         if (empty($this->_user)) {
             /*
             if (!$this->modx->getOption('smf_forced_sync')) {
             	$this->modx->log(modX::LOG_LEVEL_ERROR, "[SMF] Could not update existing SMF user \"{$username}\" because of \"smf_forced_sync\" is disabled");
             
             	return;
             }
             */
             $new = array_merge($user->toArray(), $profile->toArray());
             foreach ($update as $k => $v) {
                 if (!empty($new[$v])) {
                     if ($k == 'birthdate') {
                         $update[$k] = date('Y-m-d', $new[$v]);
                     } else {
                         $update[$k] = $new[$v];
                     }
                 } else {
                     unset($update[$k]);
                 }
             }
             $update['is_activated'] = $user->active && !$profile->blocked ? 1 : 3;
         } else {
             $current = array_merge($this->_user->toArray(), $this->_profile->toArray());
             $new = array_merge($user->toArray(), $profile->toArray());
             foreach ($update as $k => $v) {
                 if ($new[$v] != $current[$v]) {
                     if ($k == 'birthdate') {
                         $update[$k] = date('Y-m-d', $new[$v]);
                     } else {
                         $update[$k] = $new[$v];
                     }
                 } else {
                     unset($update[$k]);
                 }
             }
             if ($this->_user->active != $user->active || $this->_profile->blocked != $profile->blocked) {
                 $update['is_activated'] = $user->active && !$profile->blocked ? 1 : 3;
             }
         }
         if (!empty($password)) {
             $update['passwd'] = sha1(strtolower($username) . smfapi_unHtmlspecialchars($password));
         }
         if (!empty($update)) {
             $response = smfapi_updateMemberData($username, $update);
             if (is_array($response)) {
                 $this->modx->log(modX::LOG_LEVEL_ERROR, "[SMF] Could not update user \"{$username}\" {$this->modx->event->name} in SMF: " . print_r($response, true));
             } elseif (!empty($update['passwd'])) {
                 $contexts = $this->smfGetContexts();
                 if (in_array($this->modx->context->key, $contexts) && $this->modx->user->username == $user->username) {
                     smfapi_logout($username);
                     smfapi_login($user->username);
                 }
             }
         }
     }
 }