简体   繁体   中英

Reuse password broker logic to send activation email

I've got a simple CRUD application in which is possible to add users, through a form, the ideal flow is

  • an admin fills the form with user name and password
  • an email is sent to the user with a link to set the password
  • the user is logged in

Now at the end of the day what I really want is that the PasswordBroker does, but instead to send the emails.passsowrd view I want a different one, and the rest of the logic can be the same

Is there an easy way so create a valid isntace of the passwordBroker and passing a different view?

the property emailWiew is protected so I cannot override it, I tried to create a new instance out of the IoC

$tokens = $this->app['auth.password.tokens'];

$users = $this->app['auth']->driver()->getProvider();

$view = "emails.createPassword";

$password =  new PasswordBroker(
    $tokens, $users, $this->app['mailer'], $view
);
dd($users->retrieveByCredentials(["email@user.com"])); //i get null and the user email is valid

$response = $password->sendResetLink(["email@user.com"], function (Message $message) {
    $message->subject("Set your password");
});
dd($response); // I get "passwords.user" wich is an error

but when I pass the email address I get an invalid user error

any idea?

The problem is that you're not providing the key to retrieve the credentials, so it's trying to get a field in the users table by the name of "0". use the following and it will work:

$response = $password->sendResetLink(
    ["email" => "email@user.com"], 
    function (Message $message) {
        $message->subject("Set your password");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM