简体   繁体   English

重用密码代理逻辑发送激活电子邮件

[英]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 我有一个简单的CRUD应用程序,可以通过表格添加用户,理想的流程是

  • 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 现在,到最后,我真正想要的是PasswordBroker所做的,但是我要发送emails.passsowrd视图,我想要一个不同的视图,其余逻辑可以相同

Is there an easy way so create a valid isntace of the passwordBroker and passing a different view? 有没有一种简单的方法,因此可以创建passwordBroker的有效密码并传递不同的视图?

the property emailWiew is protected so I cannot override it, I tried to create a new instance out of the IoC 该属性emailWiew受保护,因此我无法覆盖它,我尝试在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". 问题在于您没有提供检索凭证的密钥,因此它试图在用户表中获取名称为“ 0”的字段。 use the following and it will work: 使用以下内容,它将起作用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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