#! /usr/bin/perl -w # Emily Wu's Website # logout.cgi: The log-out script. # Copyright (c) 2004-2021 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Author: imacat # First written: 2004-10-16 use 5.008; use strict; use warnings; use lib $ENV{"DOCUMENT_ROOT"} . qw(/magicat/lib/perl5); use Selima::emily; local $SIG{"__DIE__"} = \&http_500; my $d = new Selima::Destroy; # Prototype declaration sub main(); sub check_get(); sub check_post(); sub html_page($); sub html_logoutform(); sub html_relogin(); initenv(-dbi => DBI_NONE, -lastmod => 1, -page_param => {"keywords" => N_("log out")}); main; exit 0; sub main() { local ($_, %_); my ($error, $success, $processor); # If the request is a GET query if ($ENV{"REQUEST_METHOD"} ne "POST") { $error = check_get; # If an error occurs if (defined $error) { html_page $error; # Display the page } else { html_page retrieve_status; } # If a form was POSTed from the client } else { $error = check_post; # If an error occurs if (defined $error) { error_redirect $error; # Else, save the data } else { $processor = new Selima::Processor::LogOut($POST); $success = $processor->process; success_redirect $success; } } return; } # check_get: Check the GET arguments sub check_get() { local ($_, %_); my $status; # There is a result to display $status = retrieve_status; # Successfully logged out if ( defined $status && exists $$status{"status"} && $$status{"status"} eq "success") { # Nothing to check return; } # Check if this user has logged in unauth unless defined get_login_sn; # OK return; } # check_post: Check the POSTed form sub check_post() { local ($_, %_); # Check if this user has logged in unauth unless defined get_login_sn; # OK return; } # html_page: Display the page sub html_page($) { local ($_, %_); my $status; $status = $_[0]; # Not logged out yet if (defined get_login_sn) { html_header __("Log Out"); html_errmsg $status; html_logoutform; html_footer; # Logged out } else { html_header __("Log Out"); html_errmsg $status; html_relogin; html_footer; } return; } ################################## # Subroutines to manage the data # ################################## # html_logoutform: Display a form to log out sub html_logoutform() { local ($_, %_); my ($msg, $submit); $msg = h(__("Are you sure you want to log out?")); $submit = h(__("Log out")); print << "EOT";

$msg

EOT return; } # html_relogin: Display links to log in again sub html_relogin() { local ($_, %_); $_ = h(__("Log in again.")); print << "EOT";

$_

EOT return; }