Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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());
- }
Add Comment
Please, Sign In to add comment