Replaced the account.options loop in the displayAccount auth methods with new macros for displaying deactivate account and back to site links. Another macro which allows text to be displayed according to whether the value passed in is empty or not was added to allow functionality similar to that which currently exists.

This commit is contained in:
Frank Dillon 2008-11-18 07:05:23 +00:00
parent d91bc5754d
commit 32979d75e1
13 changed files with 175 additions and 82 deletions

View file

@ -33,76 +33,7 @@ readonly session => my %session;
readonly module => my %module;
public method => my %method;
public uid => my %uid;
public store => my %store; #This is an all purpose hash to store stuff in: $store{id $self}->{something} = "something"
#-------------------------------------------------------------------
=head2 appendAccountLinks ( session , var)
Class method which appends common links to preform various account tasks
=head3 session
WebGUI::Session object
=head3 var
hash ref to append template variables to
=cut
sub appendAccountLinks {
my $class = shift;
my $session = shift;
my $var = shift;
return unless $var;
my $i18n = WebGUI::International->new($session);
my $format = q{<a href="%s">%s</a>};
my @array = ();
#Turn Admin On
if ($session->user->isInGroup(12)) {
if ($session->var->isAdminOn) {
$var->{'admin_mode_url' } = $session->url->page('op=switchOffAdmin');
$var->{'admin_mode_text'} = $i18n->get(12);
}
else {
$var->{'admin_mode_url' } = $session->url->page('op=switchOnAdmin');
$var->{'admin_mode_text'} = $i18n->get(63);
}
push(@array,{
'options.display' => sprintf($format,$var->{'admin_mode_url'},$var->{'admin_mode_text'})
});
}
#Logout
$var->{'logout_url' } = $session->url->page('op=auth;method=logout');
$var->{'logout_text'} = $i18n->get(64);
push(@array,{
'options.display' => sprintf($format,$var->{'logout_url'},$var->{'logout_text'})
});
#Deactivate Account
if ($session->setting->get("selfDeactivation") && !$session->user->isAdmin){
$var->{'self_deactivation_url' } = $session->url->page('op=auth;method=deactivateAccount');
$var->{'self_deactivation_text'} = $i18n->get(65);
push(@array,{
'options.display' => sprintf($format,$var->{'self_deactivation_url' },$var->{'self_deactivation_text'})
});
}
#Return to site
$var->{'return_to_site_url' } = $session->url->getBackToSiteURL;
$var->{'return_to_site_link'} = $i18n->get(493);
push(@array,{
'options.display' => sprintf($format,$var->{'return_to_site_url'},$var->{'return_to_site_link'})
});
$var->{'account.options'} = \@array;
}
public store => my %store; #This is an all purpose hash to store stuff in: $self->store->{something} = "something"
#-------------------------------------------------------------------

View file

@ -482,9 +482,6 @@ sub displayAccount {
}
$vars->{'account.form.submit'} = WebGUI::Form::submit($self->session,{});
$vars->{'account.form.footer'} = WebGUI::Form::formFooter($self->session,);
#Appends 'account.options' loop along with some new links
WebGUI::Account->appendAccountLinks($self->session,$vars);
########### ACCOUNT SHUNT
#The following is a shunt which allows the displayAccount page to be displayed in the

View file

@ -355,8 +355,7 @@ sub displayAccount {
$vars->{'account.form.karma'} = $self->session->user->profileField("karma");
$vars->{'account.form.karma.label'} = $i18n->get(537);
}
WebGUI::Account->appendAccountLinks($self->session,$vars);
########### ACCOUNT SHUNT
#The following is a shunt which allows the displayAccount page to be displayed in the
#Account system. This shunt will be replaced in WebGUI 8 when the API can be broken

View file

@ -0,0 +1,37 @@
package WebGUI::Macro::BackToSite;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
=head1 NAME
Package WebGUI::Macro::BackToSite
=head1 DESCRIPTION
Tries to return a URL to take the user back to the last page they were at before
using an operation or other function. This will always include the gateway
url from the config file.
=head2 process
=cut
#-------------------------------------------------------------------
sub process {
my $session = shift;
return $session->url->getBackToSiteURL;
}
1;

View file

@ -0,0 +1,62 @@
package WebGUI::Macro::DeactivateAccount;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::International;
use WebGUI::Asset::Template;
=head1 NAME
Package WebGUI::Macro::DeactivateAccount
=head1 DESCRIPTION
Macro for displaying a url to the user for deactivating their account, if
the setting is turned on.
=head2 process ( [deactivateText, template ] )
process takes two optional parameters for customizing the content and layout
of the self deactivation link.
=head3 deactivateText
The text displayed to the user for this link. If this is blank an internationalized default is used.
=head3 template
The url for a template from the Macro/DeactivateAccount namespace to use for formatting the link.
=cut
#-------------------------------------------------------------------
sub process {
my $session = shift;
my ($deactivateText, $templateName) = @_;
return "" unless ($session->setting->get("selfDeactivation") && !$session->user->isAdmin);
my $i18n = WebGUI::International->new($session);
my $var = {};
$var->{'self_deactivation_url' } = $session->url->page('op=auth;method=deactivateAccount');
$var->{'self_deactivation_text'} = $deactivateText || $i18n->get(65);
my $template = $templateName ? WebGUI::Asset::Template->newByUrl($session, $templateName)
: WebGUI::Asset::Template->new($session, "CocyDcs-NqmKtPy0Bs_vUA")
;
return $template->process($var);
}
1;

View file

@ -0,0 +1,58 @@
package WebGUI::Macro::HasValueText;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
=head1 NAME
Package WebGUI::Macro::HasValueText
=head1 DESCRIPTION
Macro for displaying text based on whether or not the value entered it empty.
=head2 process ( value, textIfValue, textIfNotValule )
Either the textIfValue or textIfNotValue fields can be empty
=head3 value
The value to test to see if it's empty.
=head3 textIfValue
The text to be displayed if the value is not empty. Use %s to represent the value itself.
ex: ^HasValueText(test,<li>%s</li>,);
returns: <li>test</li>
=head3 textIfNoValue
Text to be displayed if the value is empty.
=cut
#-------------------------------------------------------------------
sub process {
my $session = shift;
my ($value, $valueText, $noValueText ) = @_;
$value =~ s/^\s//;
$value =~ s/\s$//;
if ($value eq "") {
return $noValueText;
}
return sprintf($valueText,$value);
}
1;

View file

@ -27,18 +27,14 @@ Shared routines for WebGUI Operations.
TODO: DOCUMENT ME
DEPRECATED - USE WebGUI::Account->appendAccountOptions
DEPRECATED - USE Macros to display account options
=cut
#-------------------------------------------------------------------
sub accountOptions {
my $session = shift;
my $vars = {};
WebGUI::Account->appendAccountLinks($session,$vars);
return $vars->{'account.options'};
return "";
}
=head2 secureEval ( $session, $code )