FEATURE: change directory structure
This commit is contained in:
@@ -14,13 +14,13 @@ class ChangePassword extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:change-password {userID} {newPassword}';
|
||||
protected $signature = 'user:change-password {email}';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Change password for user with given ID';
|
||||
protected $description = 'Change password for user with given e-mail';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -29,18 +29,26 @@ class ChangePassword extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$id = $this->argument('userID');
|
||||
$newPassword = $this->argument('newPassword');
|
||||
|
||||
$email = $this->argument('email');
|
||||
try {
|
||||
$user = User::findOrFail($id);
|
||||
$user = User::where(['email' => $email])
|
||||
->first();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
$this->error('Invalid user ID ' . $id . '. Please see table `users` for correct IDs.');
|
||||
exit(1);
|
||||
$this->error('Invalid user ' . $email . '.');
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
$password = $this->secret('Password');
|
||||
$passwordAgain = $this->secret('Password again');
|
||||
|
||||
if ($password !== $passwordAgain) {
|
||||
$this->error('Passwords does not match');
|
||||
}
|
||||
} while ($passwordAgain !== $password || strlen($password) === 0);
|
||||
|
||||
// set new password
|
||||
$user->password = Hash::make($newPassword);
|
||||
$user->password = Hash::make($password);
|
||||
$user->save();
|
||||
|
||||
$this->info('Password successfully changed.');
|
||||
|
||||
Reference in New Issue
Block a user