/** * Modify user data * * @author Chris Smith <*****@*****.**> * @param string $user nick of the user to be changed * @param array $changes array of field/value pairs to be changed (password will be clear text) * @return bool */ public function modifyUser($user, $changes) { global $ACT; global $config_cascade; // sanity checks, user must already exist and there must be something to change if (($userinfo = $this->getUserData($user)) === false) { msg($this->getLang('usernotexists'), -1); return false; } // don't modify protected users if (!empty($userinfo['protected'])) { msg(sprintf($this->getLang('protected'), hsc($user)), -1); return false; } if (!is_array($changes) || !count($changes)) { return true; } // update userinfo with new data, remembering to encrypt any password $newuser = $user; foreach ($changes as $field => $value) { if ($field == 'user') { $newuser = $value; continue; } if ($field == 'pass') { $value = auth_cryptPassword($value); } $userinfo[$field] = $value; } $userline = $this->_createUserLine($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $userinfo['grps']); if (!io_replaceInFile($config_cascade['plainauth.users']['default'], '/^' . $user . ':/', $userline, true)) { msg('There was an error modifying your user data. You may need to register again.', -1); // FIXME, io functions should be fail-safe so existing data isn't lost $ACT = 'register'; return false; } $this->users[$newuser] = $userinfo; return true; }
/** * Delete lines that match $badline from $file. * * Be sure to include the trailing newline in $badline * * @author Patrick Brown <*****@*****.**> * * @param string $file filename * @param string $badline exact linematch to remove * @param bool $regex use regexp? * @return bool true on success */ function io_deleteFromFile($file, $badline, $regex = false) { return io_replaceInFile($file, $badline, null, $regex, 0); }
/** * Test passing an invalid parameter. * * @expectedException PHPUnit_Framework_Error_Warning */ function test_badparam() { /* The empty $oldline parameter should be caught before the file doesn't exist test. */ $this->assertFalse(io_replaceInFile(TMP_DIR . '/not_existing_file.txt', '', '', false, 0)); }