X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FchangePassword.php;h=e4063f9c9cf3d417df88387bbdf0ce110e7df886;hb=d266f40a2f828810d0249de1fdd7107a026066d4;hp=10ed826929b16647ff3b4a80eb3d8e6390c4f52b;hpb=30468dbcf754c38a8f4e534951015159748776bc;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/changePassword.php b/maintenance/changePassword.php index 10ed826929..e4063f9c9c 100644 --- a/maintenance/changePassword.php +++ b/maintenance/changePassword.php @@ -2,6 +2,8 @@ /** * Change the password of a given user * + * Copyright © 2005, Ævar Arnfjörð Bjarmason + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -17,35 +19,47 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * + * @file * @author Ævar Arnfjörð Bjarmason - * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * @ingroup Maintenance */ -require_once( "Maintenance.php" ); +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); +/** + * Maintenance script to change the password of a given user. + * + * @ingroup Maintenance + */ class ChangePassword extends Maintenance { public function __construct() { parent::__construct(); - $this->addOption( "user", "The username to operate on", true, true ); + $this->addOption( "user", "The username to operate on", false, true ); + $this->addOption( "userid", "The user id to operate on", false, true ); $this->addOption( "password", "The password to use", true, true ); $this->mDescription = "Change a user's password"; } - + public function execute() { - $user = User::newFromName( $this->getOption('user') ); - if( !$user->getId() ) { - $this->error( "No such user: " . $this->getOption('user'), true ); + if ( $this->hasOption( "user" ) ) { + $user = User::newFromName( $this->getOption( 'user' ) ); + } elseif ( $this->hasOption( "userid" ) ) { + $user = User::newFromId( $this->getOption( 'userid' ) ); + } else { + $this->error( "A \"user\" or \"userid\" must be set to change the password for" , true ); + } + if ( !$user || !$user->getId() ) { + $this->error( "No such user: " . $this->getOption( 'user' ), true ); } try { - $user->setPassword( $this->getOption('password') ); + $user->setPassword( $this->getOption( 'password' ) ); $user->saveSettings(); - } catch( PasswordError $pwe ) { + $this->output( "Password set for " . $user->getName() . "\n" ); + } catch ( PasswordError $pwe ) { $this->error( $pwe->getText(), true ); } } } $maintClass = "ChangePassword"; -require_once( DO_MAINTENANCE ); +require_once( RUN_MAINTENANCE_IF_MAIN );