如何解决“logoutOtherDevices”不适用于 Laravel Sanctum
我想在 Laravel 8 中使用 Auth::logoutOtherDevices($currentPassword)
在更改密码后从其他设备注销用户。根据文档,我取消了对 \Illuminate\Session\Middleware\AuthenticateSession::class,
行的注释。但不幸的是,它不起作用。它说 Method Illuminate\Auth\RequestGuard::viaRemember does not exist.
谁能帮我整理一下如何在 Auth::logoutOtherDevices($currentPassword)
或任何手动方法的帮助下从其他设备功能添加注销?
这是我的代码:
$rules = [
'currentpass' => 'required','newpass' => 'required|min:6','confnewpass' => 'required|same:newpass|min:6'
];
$messages = [
'currentpass.required' => 'Please enter your current password.','newpass.required' => 'Please provide a new password.','newpass.min' => 'Password must contain minimum 6 characters.','confnewpass.required' => 'Please provide your new password again to confirm.','confnewpass.same' => 'Both new passwords must be same.','confnewpass.min' => 'Password must contain minimum 6 characters.'
];
$this->validate($request,$rules,$messages);
$currentPass = $request->input('currentpass');
$newPass = $request->input('newpass');
try {
$user = User::findOrFail(Auth::id());
} catch (ModelNotFoundException $ex) {
$response['error'] = true;
$response['errors']['notFound'] = ['User Not Found.'];
return response()
->json($response,400,[],JSON_PRETTY_PRINT);
}
if (!Hash::check($currentPass,$user->password)) {
return Redirect::back()
->withErrors(['Current Password','Please provide your current password properly.']);
}
$isChar = preg_match('/[a-zA-Z]+/',$newPass);
$isNum = preg_match('/\d+/',$newPass);
if (!($isChar && $isNum)) {
$response['error'] = 'Password must contain minimum 6 characters with at-least one letter and one number.';
return response()
->json($response,200,JSON_PRETTY_PRINT);
}
/** hash password */
$hashpass = Hash::make($newPass);
$user->password = $hashpass;
try {
$user->save();
} catch (QueryException $ex) {
return Redirect::back()
->withErrors(['query',$ex->getMessage()]);
}
Auth::logoutOtherDevices($currentPass);
return Redirect::back()
->with('success','Your password has been successfully updated.');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。