v2-hub
v2-hub copied to clipboard
Resetting passwords when user driver is set to Redis
Describe the bug
When you have the user driver set to redis and you request a password reset, an email is sent however the token is invalid.
To Reproduce Steps to reproduce the behavior:
- Install Statamic 2
- Create a new user
- Set the user driver to
redisinsite/settings/users.yaml - Request a password reset link
- Open the link sent in the reset email in your browser, it should say the token is invalid.
Expected behavior Instead of erroring out saying the token is invalid, it should accept the token and allow the user to reset their password.
Screenshots

Environment details (please complete the following information):
- Statamic Version [e.g. 2.11.19]
- Fresh Install or Upgrade: Upgrade (years old)
- OS: [e.g. macOS 10.12.6, Ubuntu 16.04] macOS 10.14.06, Windows 10, Recently provisioned Laravel Forge server
- Browser: [e.g. chrome, safari] Chrome
- Web Server: [eg. Apache, Nginx, Valet] Nginx
- PHP Version: [eg. 7.1] 7.3.9
- Addons installed: Impersonator, Loop, Profiler, Recaptcha, Workshop
Additional context Add any other context about the problem here.
I have managed to make a hacky solution that works for now as it was rather annoying the client.
In the Statamic\Data\Users\Redis\User class, I rewrote the setPasswordResetToken and getPasswordResetToken` methods to look like this.
public function setPasswordResetToken($token)
{
$this->set('password_reset_token', $token);
$yaml = YAML::parse(File::get($this->passwordResetPath(), ''));
$yaml[$this->id()] = $token;
$yaml = array_filter($yaml);
File::put($this->passwordResetPath(), YAML::dump($yaml));
}
private function passwordResetPath()
{
return cache_path('password_resets.yaml');
}
/**
* Get the reset token/code for a password reset
*
* @return string
*/
public function getPasswordResetToken()
{
$yaml = YAML::parse(File::get($this->passwordResetPath(), ''));
return array_get($yaml, $this->id());
}
I'm not sure if this really is a Statamic bug or something that we're doing wrong when using Redis.