此密码重置令牌在laravel 7中无效
您好,我是为创建用户创建新表单的。使用自定义路由和控制器。 但对于重置密码,我使用默认身份验证。 目前我想做的,发送密码重置(忘记)链接到用户时,管理员创建该用户。 目前我正在发送邮件后,点击邮件链接给出错误“此密码重置令牌无效” 下面是我使用的自定义控制器和邮件功能此密码重置令牌在laravel 7中无效,laravel,laravel-7,Laravel,Laravel 7,您好,我是为创建用户创建新表单的。使用自定义路由和控制器。 但对于重置密码,我使用默认身份验证。 目前我想做的,发送密码重置(忘记)链接到用户时,管理员创建该用户。 目前我正在发送邮件后,点击邮件链接给出错误“此密码重置令牌无效” 下面是我使用的自定义控制器和邮件功能 public function contactSave(Request $request) { // $token = app(PasswordBroker::class)->createToken(
public function contactSave(Request $request)
{
// $token = app(PasswordBroker::class)->createToken($request->mail);
// $token = $request->_token;
$password = Hash::make($request->name);
$token = uniqid(base64_encode(Str::random(60)));
$validate = $request->validate([
'name' => 'required|regex:/^[\pL\s\-]+$/u',
'email' => 'email',
'phone' => 'digits:10',
'address' => 'required',
'country' => 'required',
'state' => 'required',
// 'comment' => 'required',
'organization' => 'required',
'captcha' => 'required|captcha'
],
[
'captcha.captcha' => 'Incorrect Captcha'
]
);
$user= new User;
$user->name = $request->name;
$user->email = $request->email;
$user->password = $password;
$user->remember_token = Str::random(32);
$user->save();
if($user->id)
{
$CustomerContact= new CustomerContact;
// $CustomerContact->name = $request->name;
// $CustomerContact->email = $request->email;
$CustomerContact->phone = $request->phone;
$CustomerContact->address = $request->address;
$CustomerContact->user_id = $user->id;
$CustomerContact->country_id = $request->country;
$CustomerContact->state_id = $request->state;
$CustomerContact->comment = $request->comment;
$CustomerContact->organization = $request->organization;
$CustomerContact->captcha = $request->captcha;
$CustomerContact->save();
//New Mail
DB::table('password_resets')->insert([
'email' => $request->email,
'token' => $token,
'created_at' => Carbon::now()
]);
$tokenData = DB::table('password_resets')->where('email', $request->email)->first();
$this->sendResetEmail($request->email, $token);
}
return redirect('contacts')->with('success', 'User created successfully.');
}
这是该控制器中的邮件功能
private function sendResetEmail($email, $token)
{
//Retrieve the user from the database
$user = DB::table('users')->where('email', $email)->select('name', 'email')->first();
//Generate, the password reset link. The token generated is embedded in the link
$link = config('base_url') . 'password/reset/'. $token .'?email='.urlencode($user->email);
$details = [
'title' => 'Hi '.$user->name.'',
'body' => 'Your account has been created successfully. Request you set your password with this link',
// 'link' => URL::route('password/reset/'.$token)
'url' => $link
];
\Mail::to($email)->send(new \App\Mail\ContactMail($details));
//Here send the link with CURL with an external email API
}
目前,我有两个问题,我正在把这个网址的邮件
(http://password/reset/VVdVMzZrMTZ3VXFITWhIWDVBak5SZk9CYUVuOEM1WWJPYzZBVEk4WHZ3eHpiR1dRYzhkZHFycWJrU1BI5fa7fa2d5dec8?email=praful06.rambade%40gmail.com)
如果我添加()则正确地使用该电子邮件id打开邮件重置表单。但指出此问题“此密码重置令牌无效”
请查收附件
如果我在这方面做错了什么,请帮助我,并指导我。我认为,您只需要将
$token
更改为Hash::make($token)
确保您添加了使用照明\Support\Facades\Hash代码>在顶部,让我知道它是否有效,@sta if I do hash:make then error comes 404 | not found。不工作。您可以使用$token=app(\illumb\Auth\Passwords\PasswordBroker::class)->createToken($user)
或应用程序('auth.password.broker')->createToken($user)
@sta$user的确切含义是什么?如果你看到我的控制器第一行评论,我想我用了,但得到的错误。我想要完美的解决方案。从过去的2-3天起,我就被困在这里面了。在用户创建或删除后,我需要将$token放置在何处?