FR *_*TAR 5 token forgot-password reset-password laravel-5.5
我想覆盖/自定义现有的laravel忘记和重置密码功能。主要是由于我的表不包含和“电子邮件”列,因此我们有自己的电子邮件发送方法。因此,我如下更新了ForgotPasswordController.php:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Contracts\Auth\PasswordBroker;
use App\People;
use Illuminate\Http\Request;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$people = People::where('username_email', $request['email'] )->first();
if (!empty($people->cust_id)) { // user found
$password_broker = app(PasswordBroker::class); //so we can have dependency injection
$people->email = $people->username_email; // because below createToken function is looking for email field in the people table
$token = $password_broker->createToken($people); //create reset password token
$link = getHTTPURL(true) .'/profile/password/reset/'.$token;
$objemail = new \email();
$objemail->body = "
You can reset the password via : ". $link ."<br /><br />";
$objemail->to_address = $request['email'];
$objemail->send(true);
return array('error' =>0, 'succuss'=> 1);
}
return array('error' =>0, 'succuss'=> 0);
/*$password_broker->emailResetLink($user, $token, function (Message $message) {
$message->subject('Custom Email title');
});//send email.*/
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我提交默认的laravel密码重置表单,则在视图文件中出现“ 此密码重置令牌无效。 ”错误。
注意:我覆盖ResetPasswordController.php中的凭据功能,如下所示:
protected function credentials(Request $request)
{
return $request->only(
'username_email', 'password', 'password_confirmation', 'token'
);
}
Run Code Online (Sandbox Code Playgroud)
任何想法,怎么了?
小智 2
您可以在 Laravel 中自定义忘记和重置密码功能。这里有一点需要注意。
通过电子邮件发送给用户的令牌实际上是您的APP_KEY.
$this->hashKey is actually APP_KEY.
$token = hash_hmac('sha256', Str::random(40), $this->hashKey);
But the token that is stored in your database is bcrypt of that sha256.
bcrypt(hash_hmac('sha256', Str::random(40), $this->hashKey));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2051 次 |
| 最近记录: |