【问题标题】:Laravel 5.2 : Password reset email against usernameLaravel 5.2:针对用户名的密码重置电子邮件
【发布时间】:2016-09-25 15:12:00
【问题描述】:

我的情况是用户的唯一电子邮件可以有多个帐户。 意味着一封电子邮件与具有唯一用户名的多个帐户相关联。

我当前的代码适用于邮件,我想使用他们的用户名发送电子邮件,这意味着用户将输入他的用户名,然后与该用户名关联的电子邮件将获得密码重置链接

直接电子邮件的当前工作代码:

public function postEmail(Request $request)
{
    $validator = Validator::make(Input::get(),
        [
            'email' => 'required|email'
        ]
    );
    if ($validator->fails()) {
        return redirect()
            ->back()
            ->withErrors($validator->errors())
            ->with('message', 'Please fix your form fields.')
            ->with('form', 'recover')
            ->withInput(Input::except('password'));
    }
    $response = $this->passwords->sendResetLink($request->only('email'), function($message)
    {
        $message->subject('Password Reminder');
    });
    switch ($response)
    {
        case PasswordBroker::RESET_LINK_SENT:
            return redirect()
                ->back()
                ->with('message', 'A verification email was sent to your email inbox.')
                ->with('form', 'recover')
                ->withInput(Input::except('password'));

        case PasswordBroker::INVALID_USER:
            dd('true');
    }
}

我添加了以下行:

$usernameToEmail = App\User::where('name','=', Input::get());

然后我将$usernameToEmail->email 传递给

$response = $this->passwords->sendResetLink($usernameToEmail->email, 

    function($message)
       {
          $message->subject('Password Reminder');
       });

这会引发以下错误:

Type error: Argument 1 passed to Illuminate\Auth\Passwords\PasswordBroker::sendResetLink() must be of the type array, string given

【问题讨论】:

    标签: php laravel laravel-5.2


    【解决方案1】:

    发生这种情况是因为 PasswordBroker 正在尝试通过您提供的凭据检索使用,并且它将进行数据库查询以获取用户。因此,如果您的用户名是唯一的,您可以这样做:

    $this->passwords->sendResetLink(
        ['username' => $username], 
        function($message){...}
    );
    

    【讨论】:

    • 能否请您扩展您的答案意味着请编辑我的代码!
    • 只需将$usernameToEmail->email 更改为包含在数组中的用户的用户名,如下所示:['username' => $username]
    【解决方案2】:

    这不起作用,您需要拥有唯一的电子邮件和用户名。

    因为令牌是针对表中的唯一用户行生成并在重置时使用。

    【讨论】:

    • 试图获取无对象的属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2016-03-01
    • 2016-08-07
    相关资源
    最近更新 更多