Last active
May 18, 2018 15:58
-
-
Save lrealdi/44dc164604a012f36263be64ff979443 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require 'autoload.php'; | |
| $script = eZScript::instance(array( | |
| 'description' => ( "Cambio password\n\n" ), | |
| 'use-session' => false, | |
| 'use-modules' => true, | |
| 'use-extensions' => true | |
| )); | |
| $script->startup(); | |
| $options = $script->getOptions('[user:][new:]', | |
| '', | |
| array( | |
| 'user' => 'Id o nome utente o email degli utenti da aggiornare', | |
| 'new' => 'Nuova password' | |
| ) | |
| ); | |
| $script->initialize(); | |
| $script->setUseDebugAccumulators(true); | |
| try { | |
| $output = new ezcConsoleOutput(); | |
| $ini = eZINI::instance(); | |
| $user = $options['user']; | |
| if (is_numeric($user)) { | |
| $userToChange = eZUser::fetch((int)$user); | |
| } elseif (strpos($user, '@') !== false) { | |
| $userToChange = eZUser::fetchByEmail($user); | |
| } else { | |
| $userToChange = eZUser::fetchByName($user); | |
| } | |
| if (!$userToChange instanceof eZUser) { | |
| throw new Exception("User $user not found"); | |
| } | |
| $newPassword = $options['new']; | |
| $minPasswordLength = $ini->hasVariable('UserSettings', 'MinPasswordLength') ? $ini->variable('UserSettings', | |
| 'MinPasswordLength') : 3; | |
| if (strlen($newPassword) < $minPasswordLength) { | |
| throw new Exception("Password troppo breve"); | |
| } | |
| $question = ezcConsoleQuestionDialog::YesNoQuestion( | |
| $output, | |
| "Cambio la password per l'utente " . $userToChange->attribute('contentobject')->attribute('name'), | |
| "y" | |
| ); | |
| if (ezcConsoleDialogViewer::displayDialog($question) == "y") { | |
| eZUserOperationCollection::password($userToChange->attribute('contentobject_id'), $newPassword); | |
| } | |
| $script->shutdown(); | |
| } catch (Exception $e) { | |
| $errCode = $e->getCode(); | |
| $errCode = $errCode != 0 ? $errCode : 1; // If an error has occured, script must terminate with a status other than 0 | |
| $script->shutdown($errCode, $e->getMessage()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment