添加 sudo 模式

This commit is contained in:
iVampireSP.com 2023-02-02 19:18:16 +08:00
parent 96feebe605
commit a1c4c23d3e
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
3 changed files with 39 additions and 1 deletions

View File

@ -102,6 +102,13 @@ public function logout(): RedirectResponse
return redirect()->route('index');
}
public function exitSudo(): RedirectResponse
{
session()->forget('auth.password_confirmed_at');
return back()->with('success', '已退出 Sudo 模式。');
}
public function showAuthRequest($token): View|RedirectResponse
{
$data = Cache::get('auth_request:'.$token);

View File

@ -24,7 +24,7 @@
<body>
<div id="app">
<nav class="navbar navbar-expand-lg bd-navbar sticky-top bg-body">
<nav class="navbar navbar-expand-lg bd-navbar sticky-top bg-body" id="nav">
<div class="container">
<a class="navbar-brand" href="{{ route('index') }}">
{{ config('app.display_name') }}
@ -92,11 +92,30 @@
{{ Auth::user()->name }}
</a>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('password.request') }}">
{{ __('Reset Password') }}
</a>
@if (!session('auth.password_confirmed_at'))
<a class="dropdown-item" href="{{ route('password.confirm') }}">
进入 Sudo 模式
</a>
@else
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="document.getElementById('exit-sudo-form').submit();return false;">
退出 Sudo 模式
</a>
<form id="exit-sudo-form" action="{{ route('sudo.exit') }}" method="POST"
class="d-none">
@csrf
</form>
@endif
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="document.getElementById('logout-form').submit();return false;">
{{ __('Logout') }}
@ -139,6 +158,17 @@ class="d-none">
</div>
</main>
</div>
<script>
const nav = document.getElementById('nav');
@if (session('auth.password_confirmed_at'))
nav.style.backgroundColor = 'rgb(234 234 234 / 9%)';
nav.classList.remove('bg-body');
@endif
</script>
</body>
</html>

View File

@ -54,6 +54,7 @@ function () {
Route::delete('deleteAll', [AuthController::class, 'deleteAll'])->name('token.delete_all');
Route::patch('update', [AuthController::class, 'update'])->name('users.update');
Route::post('sudo/exit', [AuthController::class, 'exitSudo'])->name('sudo.exit');
/* End 账户区域 */
/* Start 财务 */