-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Validator; | ||
|
||
class ResetPassword extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'reset:password'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Reset a password for an user'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
|
||
$this->info('Type in the email of the user you would like to reset'); | ||
|
||
$email = $this->ask('Email'); | ||
|
||
$validator = Validator::make([ | ||
'email' => $email | ||
], [ | ||
'email' => 'email', | ||
]); | ||
|
||
if ($validator->fails()) { | ||
$this->error($validator->errors()->first()); | ||
return Command::FAILURE; | ||
} | ||
|
||
$user = User::where('email', $email)->first(); | ||
|
||
if ($user === null) { | ||
$this->error('User does not exist.'); | ||
return Command::FAILURE; | ||
} | ||
|
||
$this->info('Type in a new password'); | ||
$password = $this->secret('Password'); | ||
$password2 = $this->secret('Re-entered password'); | ||
|
||
if ($password !== $password2) { | ||
$this->error('Re-entered password does not match password'); | ||
return Command::FAILURE; | ||
} | ||
|
||
$user->password = Hash::make($password); | ||
$user->save(); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
} |