Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[5.2] expose token methods to user in password broker#13054

Merged
taylorotwell merged 1 commit into
laravel:5.2from
browner12:password-resets
Apr 7, 2016
Merged

[5.2] expose token methods to user in password broker#13054
taylorotwell merged 1 commit into
laravel:5.2from
browner12:password-resets

Conversation

@browner12
Copy link
Copy Markdown
Contributor

this PR references internals issue 12. please read my initial comment on that page for my reason behind submitting this PR.

by giving the user access to the token repository, they now have full control over resetting passwords. the user is given free reign over validating the input, sending emails, and other things they would like to do.

here is how i would use it in a controller or service class.

class PasswordService
{
    public function __construct(\Illuminate\Contracts\Auth\PasswordBroker $broker)
    {
        $this->broker = $broker;
    }

    public function request(array $input)
    {
            //retrieve user
            $user = $this->broker->getUser($input);

            //no user found with email
            if (is_null($user)) {
                throw new Exception('User not found.');
            }

            //get token
            $token = $this->broker->generateToken($user);

            //send email
        }
    }

    public function reset(array $input)
    {
            //retrieve user
            $user = $this->broker->getUser($input);

            //no user found with email
            if (is_null($user)) {
                throw new Exception('User not found.');
            }

            //reset password
            if($this->broker->validateToken($user, $input['token'])){

                $user->password = bcrypt($password);
                $user->save();

                $this->broker->deleteToken($input['token'];
            } 

            throw new Exception('token was invalid');
    }
}

@GrahamCampbell GrahamCampbell changed the title expose token methods to user in password broker [5.2] expose token methods to user in password broker Apr 6, 2016
@taylorotwell
Copy link
Copy Markdown
Member

Can all this be done by calling ->getRepository() and then calling whatever methods you want? You're just wanting these methods for convenience?

@taylorotwell taylorotwell merged commit bea5690 into laravel:5.2 Apr 7, 2016
@browner12
Copy link
Copy Markdown
Contributor Author

i guess technically yes. this makes the code feel a little more descriptive and easy to follow to me, and hopefully others as well.

thanks.

@browner12 browner12 deleted the password-resets branch April 8, 2016 20:01
@tillkruss
Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants