работающий logout

This commit is contained in:
Vladislav Ostapov 2024-11-05 10:44:36 +03:00
parent 0eacd76810
commit 3714207983
3 changed files with 17 additions and 1 deletions

View File

@ -6,6 +6,8 @@
namespace http::auth::jwt { namespace http::auth::jwt {
extern std::string secretKey; extern std::string secretKey;
constexpr const char* EMPTY_AUTH_COOKIE = "auth=;Path=/; Max-Age=86400; HttpOnly; SameSite=Lax";;
void generateSecretKey(); void generateSecretKey();
/** /**

View File

@ -128,7 +128,12 @@ public:
s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/login", [this](const auto& req, auto& rep) { s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/login", [this](const auto& req, auto& rep) {
if (req.method == "GET") { if (req.method == "GET") {
auto user = auth.getSession(req);
if (user == nullptr) {
sf->serve(LOGIN_HTML, rep); sf->serve(LOGIN_HTML, rep);
} else {
http::server::httpRedirect(rep, "/");
}
} else if (req.method == "POST") { } else if (req.method == "POST") {
rep.status = http::server::ok; rep.status = http::server::ok;
rep.headers.clear(); rep.headers.clear();
@ -153,6 +158,14 @@ public:
http::server::stockReply(http::server::bad_request, rep); http::server::stockReply(http::server::bad_request, rep);
} }
})); }));
s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/logout", [this](const auto& req, auto& rep) {
if (req.method == "GET") {
http::server::httpRedirect(rep, "/");
rep.headers.push_back({.name = "Set-Cookie", .value = http::auth::jwt::EMPTY_AUTH_COOKIE});
} else {
http::server::stockReply(http::server::bad_request, rep);
}
}));
s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/favicon.ico", [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(FAVICON_ICO, rep); })); s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/favicon.ico", [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(FAVICON_ICO, rep); }));
s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/images/krokodil_vzryvaetsya_hd.gif", [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(KROKODIL_GIF, rep); })); s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/images/krokodil_vzryvaetsya_hd.gif", [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(KROKODIL_GIF, rep); }));

View File

@ -22,6 +22,7 @@
<a href="#monitoring" class="tabs-btn" @click="activeTab = 'monitoring'" :class="{ active: activeTab === 'monitoring' }">Мониторинг</a> <a href="#monitoring" class="tabs-btn" @click="activeTab = 'monitoring'" :class="{ active: activeTab === 'monitoring' }">Мониторинг</a>
<a href="#setup" class="tabs-btn" @click="activeTab = 'setup'" :class="{ active: activeTab === 'setup' }">Настройки</a> <a href="#setup" class="tabs-btn" @click="activeTab = 'setup'" :class="{ active: activeTab === 'setup' }">Настройки</a>
<a href="#admin" class="tabs-btn" @click="activeTab = 'admin'" :class="{ active: activeTab === 'admin' }">Администрирование</a> <a href="#admin" class="tabs-btn" @click="activeTab = 'admin'" :class="{ active: activeTab === 'admin' }">Администрирование</a>
<a href="/logout" class="tabs-btn">Выход</a>
</div> </div>
<div class="tabs-body"> <div class="tabs-body">
<div class="tabs-body-item tabs-item-flex-container" v-show="activeTab === 'monitoring'"> <div class="tabs-body-item tabs-item-flex-container" v-show="activeTab === 'monitoring'">