работающий logout
This commit is contained in:
parent
0eacd76810
commit
3714207983
@ -6,6 +6,8 @@
|
||||
namespace http::auth::jwt {
|
||||
extern std::string secretKey;
|
||||
|
||||
constexpr const char* EMPTY_AUTH_COOKIE = "auth=;Path=/; Max-Age=86400; HttpOnly; SameSite=Lax";;
|
||||
|
||||
void generateSecretKey();
|
||||
|
||||
/**
|
||||
|
15
src/main.cpp
15
src/main.cpp
@ -128,7 +128,12 @@ public:
|
||||
|
||||
s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/login", [this](const auto& req, auto& rep) {
|
||||
if (req.method == "GET") {
|
||||
sf->serve(LOGIN_HTML, rep);
|
||||
auto user = auth.getSession(req);
|
||||
if (user == nullptr) {
|
||||
sf->serve(LOGIN_HTML, rep);
|
||||
} else {
|
||||
http::server::httpRedirect(rep, "/");
|
||||
}
|
||||
} else if (req.method == "POST") {
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.clear();
|
||||
@ -153,6 +158,14 @@ public:
|
||||
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>("/images/krokodil_vzryvaetsya_hd.gif", [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(KROKODIL_GIF, rep); }));
|
||||
|
@ -22,6 +22,7 @@
|
||||
<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="#admin" class="tabs-btn" @click="activeTab = 'admin'" :class="{ active: activeTab === 'admin' }">Администрирование</a>
|
||||
<a href="/logout" class="tabs-btn">Выход</a>
|
||||
</div>
|
||||
<div class="tabs-body">
|
||||
<div class="tabs-body-item tabs-item-flex-container" v-show="activeTab === 'monitoring'">
|
||||
|
Loading…
x
Reference in New Issue
Block a user