Skip to content

Commit

Permalink
Use the setUserPassword method from the trait ...
Browse files Browse the repository at this point in the history
Closes #2795

Looks like we were overriding the entire resetPassword method because it was before a setUserPassword method was extracted in laravel/framework#30218

Seems like that PR was created for almost the same reason.
  • Loading branch information
jasonvarga committed Dec 2, 2020
1 parent 0163066 commit 9c971e2
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Http/Controllers/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
namespace Statamic\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Statamic\Auth\Passwords\PasswordReset;
use Statamic\Auth\ResetsPasswords;
use Statamic\Contracts\Auth\User;
use Statamic\Http\Middleware\RedirectIfAuthenticated;

class ResetPasswordController extends Controller
{
use ResetsPasswords {
resetPassword as protected traitResetPassword;
}
use ResetsPasswords;

public function __construct()
{
Expand Down Expand Up @@ -44,14 +44,17 @@ public function redirectPath()
return request('redirect') ?? route('statamic.site');
}

protected function resetPassword($user, $password)
protected function setUserPassword($user, $password)
{
// We override because the parent (trait) method hashes the password first,
// but the Statamic User class's password method also hashes, which would
// result in a double-hashed password. Also, it uses the mutator style.
$user->password($password);

$this->traitResetPassword($user, $password);
// The Statamic user class has a password method that will hash a given plain
// text password. If we're using the "statamic" user provider, we'll get a
// Statamic user. Otherwise (i.e. using the "eloquent" provider), we'd
// just a User model, which requires the password to be pre-hashed.
if ($user instanceof User) {
$user->password($password);
} else {
$user->password = Hash::make($password);
}
}

public function broker()
Expand Down

0 comments on commit 9c971e2

Please sign in to comment.