Implement logout.

This commit is contained in:
Relintai 2021-08-20 19:29:39 +02:00
parent f8ba0b26c5
commit 127563e6ca
2 changed files with 15 additions and 2 deletions

View File

@ -47,9 +47,15 @@ void SessionManager::delete_session(const std::string &session_id) {
_sessions.erase(session_id); _sessions.erase(session_id);
for (int i = 0; i < _sessions_vec.size(); ++i) { for (int i = 0; i < _sessions_vec.size(); ++i) {
if (_sessions_vec[i]->session_id == session_id) { HTTPSession *sess = _sessions_vec[i];
if (sess->session_id == session_id) {
_sessions_vec[i] = _sessions_vec[_sessions_vec.size() - 1]; _sessions_vec[i] = _sessions_vec[_sessions_vec.size() - 1];
_sessions_vec.pop_back(); _sessions_vec.pop_back();
delete sess;
return; return;
} }
} }

View File

@ -397,7 +397,14 @@ void User::handle_password_reset_request(Request *request) {
request->compile_and_send_body(); request->compile_and_send_body();
} }
void User::handle_logout_request(Request *request) { void User::handle_logout_request(Request *request) {
request->body += "handle_logout_request"; request->remove_cookie("session_id");
SessionManager::get_singleton()->delete_session(request->session->session_id);
request->session = nullptr;
HTMLBuilder b;
b.w("Logout successful!");
request->body += b.result;
request->compile_and_send_body(); request->compile_and_send_body();
} }