Skip to content

Instantly share code, notes, and snippets.

@aletoropov
Forked from eivko/adduser.php
Created July 9, 2023 09:04
Show Gist options
  • Save aletoropov/7a0645bc79e80fc1ef631b5f04733699 to your computer and use it in GitHub Desktop.
Save aletoropov/7a0645bc79e80fc1ef631b5f04733699 to your computer and use it in GitHub Desktop.
Создание Super User-а для MODX
<?php
$username = 'vasya';
$password = 'qwerty';
$email = 'vasya@yandex.ru';
$sudo = true;
require 'config.core.php';
require MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
if ((!$modx) || (!$modx instanceof modX)) {
echo 'Could not create MODX class';
}
$modx->initialize('mgr');
$modx->getService('error', 'error.modError', '', '');
$user = $modx->newObject('modUser');
$profile = $modx->newObject('modUserProfile');
if ($user && $profile) {
$user->set('username', $username);
$user->set('password', $password);
$profile->set('blocked', 0);
$profile->set('blockeduntil', 0);
$profile->set('blockedafter', 0);
$profile->set('email', $email);
$user->addOne($profile);
$user->setSudo($sudo);
if ($user->save()) {
echo 'Пользователь успешно создан';
$user->joinGroup('Administrator');
} else {
echo 'Не получилось создать указанного пользователя';
}
} else {
echo 'Не получилось создать пользователя';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment