added logout button.

This commit is contained in:
ivancheahhh
2024-01-04 16:51:45 -07:00
parent 83470a9a6c
commit e856e9d6ba
3 changed files with 25 additions and 1 deletions

View File

@@ -121,6 +121,13 @@ namespace CarCareTracker.Controllers
}
return Json(false);
}
[Authorize]
[HttpPost]
public IActionResult LogOut()
{
Response.Cookies.Delete("ACCESS_TOKEN");
return Json(true);
}
private static string Sha256_hash(string value)
{
StringBuilder Sb = new StringBuilder();

View File

@@ -1,4 +1,8 @@
@model string
@inject IConfiguration Configuration
@{
var enableAuth = bool.Parse(Configuration[nameof(UserConfig.EnableAuth)]);
}
@model string
@{
ViewData["Title"] = "LubeLogger";
}
@@ -19,6 +23,12 @@
<li class="nav-item ms-auto" role="presentation">
<button class="nav-link @(Model == "settings" ? "active" : "")" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings-tab-pane" type="button" role="tab"><i class="bi bi-gear me-2"></i>Settings</button>
</li>
@if (enableAuth)
{
<li class="nav-item">
<button class="nav-link" onclick="performLogOut()">Logout</button>
</li>
}
</ul>
<div class="tab-content" id="homeTab">
<div class="tab-pane fade @(Model == "garage" ? "show active" : "")" id="garage-tab-pane" role="tabpanel" tabindex="0">

View File

@@ -20,4 +20,11 @@ function loadSettings() {
$.get('/Home/Settings', function (data) {
$("#settings-tab-pane").html(data);
});
}
function performLogOut() {
$.post('/Login/LogOut', function (data) {
if (data) {
window.location.href = '/Login';
}
})
}