2012-09-05 13:46:24 +02:00
< ? php
2021-08-24 17:35:09 +02:00
/**
2012-09-05 13:46:24 +02:00
* Reset a password
2012-09-18 15:30:32 +02:00
*
2012-09-05 13:46:24 +02:00
* arg0 = email
* arg1 = new password
2021-08-24 17:35:09 +02:00
* @ deprecated Use UserShell instead
2012-09-05 13:46:24 +02:00
*/
class PasswordShell extends AppShell {
2012-09-18 15:30:32 +02:00
2020-02-10 15:15:59 +01:00
public $uses = array ( 'User' );
2012-09-05 13:46:24 +02:00
2020-02-10 15:15:59 +01:00
public function main ()
{
2024-01-12 11:57:02 +01:00
$this -> deprecated ( 'cake user change_pw [user] [password]' );
2021-12-19 14:05:27 +01:00
2020-02-10 15:15:59 +01:00
if ( ! isset ( $this -> args [ 0 ]) || empty ( $this -> args [ 0 ]) || ! isset ( $this -> args [ 1 ]) || empty ( $this -> args [ 1 ])) echo 'MISP password reset command line tool.' . PHP_EOL . 'To assign a new password for a user:' . PHP_EOL . APP . 'Console/cake Password [email] [password]' . PHP_EOL ;
else {
// get the users that need their password hashed
$results = $this -> User -> find ( 'first' , array ( 'conditions' => array ( 'email' => $this -> args [ 0 ]), 'recursive' => - 1 ));
if ( empty ( $results )) {
echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Password [email] [password]' . PHP_EOL ;
exit ;
}
$results [ 'User' ][ 'password' ] = $this -> args [ 1 ];
$results [ 'User' ][ 'confirm_password' ] = $this -> args [ 1 ];
2019-04-06 20:44:45 +02:00
$change_pw = 1 ;
if ( ! empty ( $this -> params [ 'override_password_change' ])) {
$change_pw = 0 ;
}
2020-02-10 15:15:59 +01:00
$results [ 'User' ][ 'change_pw' ] = $change_pw ;
if ( ! $this -> User -> save ( $results )) {
echo 'Could not update account for User.id = ' , $results [ 'User' ][ 'id' ], PHP_EOL ;
echo json_encode ( $this -> User -> validationErrors ) . PHP_EOL ;
$this -> out ( print_r ( $this -> User -> invalidFields (), true ));
}
echo 'Updated ' , PHP_EOL ;
}
exit ;
}
2019-04-06 20:44:45 +02:00
public function getOptionParser ()
{
$parser = parent :: getOptionParser ();
$parser -> addOption ( 'override_password_change' , array (
'short' => 'o' ,
'help' => __ ( 'override password change' ),
'boolean' => 1
));
return $parser ;
}
2015-09-09 20:52:01 +02:00
}