Guest User

Untitled

a guest
May 19th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2. require 'autoload.php';
  3.  
  4. $script = eZScript::instance(array(
  5. 'description' => ( "Cambio password\n\n" ),
  6. 'use-session' => false,
  7. 'use-modules' => true,
  8. 'use-extensions' => true
  9. ));
  10.  
  11. $script->startup();
  12.  
  13. $options = $script->getOptions('[user:][new:]',
  14. '',
  15. array(
  16. 'user' => 'Id o nome utente o email degli utenti da aggiornare',
  17. 'new' => 'Nuova password'
  18. )
  19. );
  20. $script->initialize();
  21. $script->setUseDebugAccumulators(true);
  22.  
  23. try {
  24. $output = new ezcConsoleOutput();
  25.  
  26. $ini = eZINI::instance();
  27.  
  28. $user = $options['user'];
  29. if (is_numeric($user)) {
  30. $userToChange = eZUser::fetch((int)$user);
  31. } elseif (strpos($user, '@') !== false) {
  32. $userToChange = eZUser::fetchByEmail($user);
  33. } else {
  34. $userToChange = eZUser::fetchByName($user);
  35. }
  36.  
  37. if (!$userToChange instanceof eZUser) {
  38. throw new Exception("User $user not found");
  39. }
  40.  
  41. $newPassword = $options['new'];
  42.  
  43.  
  44. $minPasswordLength = $ini->hasVariable('UserSettings', 'MinPasswordLength') ? $ini->variable('UserSettings',
  45. 'MinPasswordLength') : 3;
  46. if (strlen($newPassword) < $minPasswordLength) {
  47. throw new Exception("Password troppo breve");
  48. }
  49.  
  50. $question = ezcConsoleQuestionDialog::YesNoQuestion(
  51. $output,
  52. "Cambio la password per l'utente " . $userToChange->attribute('contentobject')->attribute('name'),
  53. "y"
  54. );
  55. if (ezcConsoleDialogViewer::displayDialog($question) == "y") {
  56. eZUserOperationCollection::password($userToChange->attribute('contentobject_id'), $newPassword);
  57. }
  58.  
  59.  
  60. $script->shutdown();
  61. } catch (Exception $e) {
  62. $errCode = $e->getCode();
  63. $errCode = $errCode != 0 ? $errCode : 1; // If an error has occured, script must terminate with a status other than 0
  64. $script->shutdown($errCode, $e->getMessage());
  65. }
Add Comment
Please, Sign In to add comment