[英]Laravel 5.2 : Password reset email against username
My case is that a user's unique email can have many accounts . 我的情况是用户的唯一电子邮件可以有很多帐户。 Means that one email is associated with many accounts on unique username's.
表示一封电子邮件与唯一用户名上的许多帐户相关联。
My current code works for mail, I want to send email on their username, Means that user will enter his username then the email associate with that username will get the password reset link 我目前的代码适用于邮件,我想用他们的用户名发送电子邮件,意味着用户将输入他的用户名,然后与该用户名关联的电子邮件将获得密码重置链接
Current working code for direct email : 直接电子邮件的当前工作代码:
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');
}
}
I have added the following line : 我添加了以下行:
$usernameToEmail = App\\User::where('name','=', Input::get());
And then i passed $usernameToEmail->email
to 然后我通过
$usernameToEmail->email
到
$response = $this->passwords->sendResetLink($usernameToEmail->email,
function($message)
{
$message->subject('Password Reminder');
});
Which throws the following error : 这会引发以下错误:
Type error: Argument 1 passed to Illuminate\Auth\Passwords\PasswordBroker::sendResetLink() must be of the type array, string given
This is happening because the PasswordBroker is trying to retrieve a use by the credentials that you give and it will make a DB query to get a user. 发生这种情况是因为PasswordBroker正在尝试通过您提供的凭据检索使用情况,并且它将进行数据库查询以获取用户。 So if your username is unique you could do it like this:
因此,如果您的用户名是唯一的,您可以这样做:
$this->passwords->sendResetLink(
['username' => $username],
function($message){...}
);
This will not work you need to have unique email and username.
这不起作用您需要具有唯一的电子邮件和用户名。
as token is generated against a unique users row in table and used when resetting. 因为令牌是针对表中的唯一用户行生成的,并在重置时使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.