Example #1
0
 public function checkPassword()
 {
     $newPassword = $this->processor->getProperty('newpassword', null);
     $id = $this->processor->getProperty('id');
     if ($newPassword !== null && $newPassword != 'false' || empty($id)) {
         $passwordNotifyMethod = $this->processor->getProperty('passwordnotifymethod', null);
         if (empty($passwordNotifyMethod)) {
             $this->processor->addFieldError('password_notify_method', $this->modx->lexicon('user_err_not_specified_notification_method'));
         }
         $passwordGenerationMethod = $this->processor->getProperty('passwordgenmethod', 'g');
         if ($passwordGenerationMethod == 'g') {
             $len = $this->modx->getOption('password_generated_length', null, 8);
             $autoPassword = $this->generatePassword($len);
             $this->user->set('password', $autoPassword);
             $this->processor->newPassword = $autoPassword;
         } else {
             $specifiedPassword = $this->processor->getProperty('specifiedpassword');
             $confirmPassword = $this->processor->getProperty('confirmpassword');
             if (empty($specifiedPassword)) {
                 $this->processor->addFieldError('specifiedpassword', $this->modx->lexicon('user_err_not_specified_password'));
             } elseif ($specifiedPassword != $confirmPassword) {
                 $this->processor->addFieldError('confirmpassword', $this->modx->lexicon('user_err_password_no_match'));
             } elseif (strlen($specifiedPassword) < $this->modx->getOption('password_min_length', null, 6)) {
                 $this->processor->addFieldError('specifiedpassword', $this->modx->lexicon('user_err_password_too_short'));
             } elseif (!preg_match('/^[^\'\\x3c\\x3e\\(\\);\\x22]+$/', $specifiedPassword)) {
                 $this->processor->addFieldError('specifiedpassword', $this->modx->lexicon('user_err_password_invalid'));
             } else {
                 $this->user->set('password', $specifiedPassword);
                 $this->processor->newPassword = $specifiedPassword;
             }
         }
     }
     return $this->processor->newPassword;
 }
Example #2
0
 public function process()
 {
     $fields = $this->getProperties();
     if (!$this->validate($fields)) {
         return $this->failure();
     }
     /* create membership */
     /** @var modUserGroupMember $membership */
     $membership = $this->modx->newObject('modUserGroupMember');
     $membership->set('user_group', $this->userGroup->get('id'));
     $membership->set('member', $this->user->get('id'));
     $membership->set('role', $fields['role']);
     $rank = $this->getNewRank();
     $membership->set('rank', $rank);
     /* save membership */
     if ($membership->save() == false) {
         return $this->failure($this->modx->lexicon('user_group_member_err_save'));
     }
     /* set as primary group if the only group for user */
     if ($rank == 0) {
         $this->user->set('primary_group', $this->userGroup->get('id'));
         $this->user->save();
     }
     return $this->success('', $membership);
 }
Example #3
0
 public function setUserGroups()
 {
     $memberships = array();
     $groups = $this->getProperty('groups', null);
     if ($groups !== null) {
         $primaryGroupId = 0;
         /* remove prior user group links */
         $oldMemberships = $this->object->getMany('UserGroupMembers');
         /** @var modUserGroupMember $membership */
         foreach ($oldMemberships as $membership) {
             $membership->remove();
         }
         /* create user group links */
         $groups = is_array($groups) ? $groups : $this->modx->fromJSON($groups);
         foreach ($groups as $group) {
             $membership = $this->modx->newObject('modUserGroupMember');
             $membership->set('user_group', $group['usergroup']);
             $membership->set('role', $group['role']);
             $membership->set('member', $this->object->get('id'));
             $membership->set('rank', $group['rank']);
             if (empty($group['rank'])) {
                 $primaryGroupId = $group['usergroup'];
             }
             $memberships[] = $membership;
         }
         $this->object->addMany($memberships, 'UserGroupMembers');
         $this->object->set('primary_group', $primaryGroupId);
     }
     return $memberships;
 }
 public function process()
 {
     $this->verifyManifest();
     $this->getUser();
     $this->validatePassword();
     $this->onBeforeUserActivate();
     /* activate user */
     $this->user->set('active', 1);
     $this->user->set('cachepwd', '');
     if (!$this->user->save()) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[Register] Could not save activated user: '******'username'));
         return '';
     }
     /* invoke OnUserActivate event */
     $this->modx->invokeEvent('OnUserActivate', array('user' => &$this->user));
     $this->addSessionContexts();
     $this->redirectBack();
     return '';
 }
Example #5
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;
 }
Example #6
0
 /**
  * Change the User's password to the new one
  * @return bool
  */
 public function changePassword()
 {
     $saved = true;
     /* change password */
     $version = $this->modx->getVersionData();
     if (version_compare($version['full_version'], '2.1.0-rc1') >= 0) {
         $this->user->set('password', $this->password);
     } else {
         $this->user->set('password', md5($this->password));
     }
     if (!$this->getProperty('debug', false, 'isset')) {
         $saved = $this->user->save();
     }
     return $saved;
 }
 public function setCachePassword($password)
 {
     /* now set new password to registry to prevent middleman attacks.
      * Will read from the registry on the confirmation page. */
     $this->modx->getService('registry', 'registry.modRegistry');
     $this->modx->registry->addRegister('login', 'registry.modFileRegister');
     $this->modx->registry->login->connect();
     $this->modx->registry->login->subscribe('/useractivation/');
     $this->modx->registry->login->send('/useractivation/', array($this->user->get('username') => $password), array('ttl' => $this->controller->getProperty('activationttl', 180) * 60));
     /* set cachepwd here to prevent re-registration of inactive users */
     $this->user->set('cachepwd', md5($password));
     if ($this->live) {
         $success = $this->user->save();
     } else {
         $success = true;
     }
     if (!$success) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[Login] Could not update cachepwd for activation for User: '******'username'));
     }
     return $success;
 }
Example #8
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);
 }