added current password to the password changing form

This commit is contained in:
Čarodej
2022-01-21 07:41:26 +01:00
parent 6b71eabfa2
commit 4fc61afc11
8 changed files with 131 additions and 67 deletions
@@ -14,7 +14,7 @@ class UpdatePasswordController extends Controller
$user = Auth::user();
// Check if is demo
abort_if(is_demo_account($user->email), 204, 'Changed!');
abort_if(is_demo_account(), 204, 'Changed!');
// Store new password
$user->update([
@@ -2,6 +2,7 @@
namespace App\Users\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Users\Rules\PasswordMatchWithCurrent;
class UpdateUserPasswordRequest extends FormRequest
{
@@ -23,6 +24,7 @@ class UpdateUserPasswordRequest extends FormRequest
public function rules()
{
return [
'current' => ['required', 'string', new PasswordMatchWithCurrent()],
'password' => 'required|string|min:6|confirmed',
];
}
@@ -0,0 +1,25 @@
<?php
namespace App\Users\Rules;
use Auth;
use Hash;
use Illuminate\Contracts\Validation\Rule;
class PasswordMatchWithCurrent implements Rule
{
/**
* Determine if the validation rule passes.
*/
public function passes($attribute, $value): bool
{
return Hash::check($value, Auth::user()->password);
}
/**
* Get the validation error message.
*/
public function message(): string
{
return "Your current password doesn't match.";
}
}