statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Resetting passwords when user driver is set to Redis #2499

Open duncanmcclean opened 4 years ago

duncanmcclean commented 4 years ago

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:

  1. Install Statamic 2
  2. Create a new user
  3. Set the user driver to redis in site/settings/users.yaml
  4. Request a password reset link
  5. 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 image

Environment details (please complete the following information):

Additional context Add any other context about the problem here.

duncanmcclean commented 4 years ago

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 andgetPasswordResetToken` 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.