Add log out button
This commit is contained in:
1 parent
39f7dd6285
commit
ed4e749901
2 files changed
+39
No files matched your search
@@ -50,10 +50,23 @@ def create_session
|
||||
token
|
||||
end
|
||||
|
||||
def remove_session(token)
|
||||
return if token.nil? || token.empty?
|
||||
sessions = load_sessions.reject { |t, _| t == token }
|
||||
File.write(SESSIONS_FILE, sessions.map { |t, ts| "#{t}:#{ts}" }.join("\n") + "\n")
|
||||
end
|
||||
|
||||
session_token = (cgi.cookies["MALP"] || []).first
|
||||
authenticated = valid_session?(session_token)
|
||||
cookie = nil
|
||||
|
||||
if cgi.request_method == "POST" && authenticated && cgi.params["action"]&.first == "logout"
|
||||
remove_session(session_token)
|
||||
cookie = CGI::Cookie.new("name" => "MALP", "value" => "", "path" => "/", "expires" => Time.at(0))
|
||||
print cgi.header("Status" => "303 See Other", "Location" => ENV["REQUEST_URI"], "cookie" => cookie)
|
||||
exit
|
||||
end
|
||||
|
||||
if cgi.request_method == "POST" && !authenticated
|
||||
username = cgi.params["username"]&.first.to_s
|
||||
password = cgi.params["password"]&.first.to_s
|
||||
|
||||
Reference in new issue
Block a user