gpt4 book ai didi

php - 在 laravel 5.6 中重置密码时从所有浏览器注销用户

转载 作者:行者123 更新时间:2023-12-04 00:31:04 24 4
gpt4 key购买 nike

当用户更改密码时,他们将从浏览器中注销。但是,如果他们同时登录到另一个浏览器,他们将在另一个浏览器上保持登录状态。

我想在用户重置密码时从他们登录的所有浏览器中注销用户。

这里登录 Controller 。

function checklogin(Request $request)
{

$this->validate($request, ['email' => 'required|email', 'password' => 'required|string|min:3']);

$user_data = array(
'email' => $request->get('email') ,
'password' => $request->get('password')
);

$remember_me = $request->has('remember') ? true : false;

if (Auth::attempt($user_data, $remember_me))
{
return redirect()->intended('dashboard');
}
else
{
return back()->with('error', 'Wrong Login Details');
}
}

发送邮件功能如下

function sendEmail(Request $request)
{

$this->validate($request, ['email' => 'required|exists:users']);

$email = $request->email;

$name = User::where('email', $email)->first();
$name = $name->name;

$token = Password::getRepository()->createNewToken();
$link = url("password/reset?email=$email&token=$token");

$value = Password_resets::where('email', $email)->first();

if (isset($value))
{
Password_resets::where('email', $email)->update(['email' => $email, 'token' => $token]);
}
else
{
Password_resets::insert(['email' => $email, 'token' => $token]);
}

Mail::to($email)->send(new \App\Mail\ResetPassword($link, $name));

return redirect()->back()->with('success', 'Please check your Email for Password Reset');
}

密码重置功能如下

function resetpasswordchange(Request $request)
{

$passwordtoken = $request->input('passwordtoken');
$email = $request->input('email');
$user_password = $request->input('user_password');

$users['user'] = Password_resets::where('token', $passwordtoken)->where('email', $email)->get();
if (empty($users['user'][0]))
{
$settoken = '0';

}
else
{
$settoken = $users['user'][0]->token;

}

if (($settoken) == $passwordtoken)
{

$update = array(
'password' => bcrypt($user_password) ,
);

User::where('email', $email)->update($update);
/* Auth::logout();
auth()->logoutOtherDevices(bcrypt($user_password),'password');*/

return redirect()->route('login')->with('success', 'Password has been Updated.');

}
else
{
return redirect()->back()->with('error', 'Token & Email Not Match!.');
}
}

如何从所有已登录的浏览器中注销用户?

最佳答案

打开 App\Http\Kernel 并在 protected $middlewareGroups 属性中取消注释 \Illuminate\Session\Middleware\AuthenticateSession::class中间件。这将比较用户的密码哈希,以查看 session 是否有效。

关于php - 在 laravel 5.6 中重置密码时从所有浏览器注销用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54141325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com