您好,请为创建用户创建新表单。使用自定义路由和控制器。 但是对于重置密码,我使用的是默认auth。 目前我想做,管理员创建该用户后,将密码重置(忘记)链接发送给该用户。 当前,我在单击邮件链接后输入错误消息“此密码重置令牌无效”。
下面是我使用的自定义控制器和邮件功能。
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
}
当前我有两个问题,正在将此URL放入邮件中
(http:// password / reset / VVdVMzZrMTZ3VXFITWhIWDVBak5SZk9CYUVuOEM1WWJPYzZBVEk4WHZ3eHpiR1dRYzhkZHFycWJrU1BI5fa7fa2d5gmail8?email = praful06.rambade%40>
如果我添加(http://127.0.0.1:8000/),则正确打开带有该电子邮件ID的邮件重置表单。但是遇到了这个问题“此密码重置令牌无效”
请找到附件 enter image description here
如果我在这方面做错了,请帮助我,并指导我。