From 4065042cd5d4e57afab40cfcf2074a6b4c7fd9c7 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 30 Dec 2010 15:49:52 +0100 Subject: [PATCH] =?utf8?q?flash=5Flater():=20In=20Session=20gespeicherter?= =?utf8?q?=20Flash=20f=C3=BCr=20n=C3=A4chsten=20Request=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Dispatcher.pm | 1 + SL/Helper/Flash.pm | 56 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 35284db4b..013dfe607 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -170,6 +170,7 @@ sub handle_request { $::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password}); $::auth->create_or_refresh_session; + $::auth->delete_session_value('FLASH')->save_session(); delete $::form->{password}; if ($action) { diff --git a/SL/Helper/Flash.pm b/SL/Helper/Flash.pm index a4ad69177..e599f6e6e 100644 --- a/SL/Helper/Flash.pm +++ b/SL/Helper/Flash.pm @@ -3,22 +3,42 @@ package SL::Helper::Flash; use strict; require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw(flash render_flash); +our @ISA = qw(Exporter); +our @EXPORT = qw(flash flash_later); +our @EXPORT_OK = qw(render_flash); + +# +# public functions +# sub flash { - my $category = shift; - $category = 'info' if $category eq 'information'; + $::form->{FLASH} = _store_flash($::form->{FLASH}, @_); +} - $::form->{FLASH} ||= { }; - $::form->{FLASH}->{ $category } ||= [ ]; - push @{ $::form->{FLASH}->{ $category } }, @_; +sub flash_later { + $::auth->set_session_value(FLASH => _store_flash($::auth->get_session_value('FLASH'), @_))->save_session(); } sub render_flash { return $::form->parse_html_template('common/flash'); } +# +# private functions +# + +sub _store_flash { + my $store = shift || { }; + my $category = shift; + $category = 'info' if $category eq 'information'; + + $store ||= { }; + $store->{ $category } ||= [ ]; + push @{ $store->{ $category } }, @_; + + return $store; +} + 1; __END__ @@ -42,21 +62,39 @@ following code: [%- INCLUDE 'common/flash.html' %] +=head1 EXPORTS + +The functions L and L are always exported. + +The function L is only exported upon request. + =head1 FUNCTIONS =over 4 -=item C +=item C -Stores a message for the given category. The category can be either +Stores messages for the given category. The category can be either C, C or C. C can also be used as an alias for C. +=item C + +Stores messages for the given category for the next request. The +category can be either C, C or C. C +can also be used as an alias for C. + +The messages are stored in the user's session and restored upon the +next request. Can be used for transmitting information over HTTP +redirects. + =item C Outputs the flash message by parsing the C template file. +This function is not exported by default. + =back =head1 AUTHOR -- 2.20.1