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); }
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; }
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; }