initial commit

This commit is contained in:
Frank Dillon 2008-11-03 17:03:00 +00:00
parent d754931286
commit 7b260de791
14 changed files with 1046 additions and 0 deletions

163
lib/WebGUI/Account.pm Normal file
View file

@ -0,0 +1,163 @@
package WebGUI::Account;
use strict;
use Class::InsideOut qw{ :std };
use WebGUI::Exception;
use WebGUI::International;
use WebGUI::Pluggable;
use WebGUI::Utility;
=head1 NAME
Package WebGUI::Account::Profile
=head1 DESCRIPTION
This is the class which is used to display a users's profile information
=head1 SYNOPSIS
use WebGUI::Account::Profile;
=head1 METHODS
These subroutines are available from this package:
=cut
readonly session => my %session;
#-------------------------------------------------------------------
=head2 editSettingsForm ( )
Override this method to create settings for your Account Pluggin
=cut
sub editUserSettingsForm {
my $self = shift;
return "";
}
#-------------------------------------------------------------------
=head2 editSettingsFormSave ( )
Override this method to create settings for your Account Pluggin
=cut
sub editUserSettingsFormSave {
my $self = shift;
return "";
}
#-------------------------------------------------------------------
=head2 getLayoutTemplateId ( )
Override this method to return the template Id for the account layout.
=cut
sub getLayoutTemplateId {
my $self = shift;
return "FJbUTvZ2nUTn65LpW6gjsA";
}
#-------------------------------------------------------------------
=head2 getStyleTemplate ( )
Override this method to return the template for the main style.
=cut
sub getStyleTemplateId {
my $self = shift;
return $self->session->setting->get("userFunctionStyleId");
}
#-------------------------------------------------------------------
=head2 new ( $session )
Constructor.
=head3 $session
A WebGUI::Session object.
=cut
sub new {
my $class = shift;
my $session = shift;
unless (ref $session eq 'WebGUI::Session') {
WebGUI::Error::InvalidObject->throw(
expected =>"WebGUI::Session",
got =>(ref $session),
error => q{Must provide a session variable}
);
}
my $self = register $class;
my $id = id $self;
$session { $id } = $session;
return $self;
}
#-------------------------------------------------------------------
=head2 processTemplate ( vars, templateId, template )
Returns the content generated from this template. It adds the Asset control
bar to the template variables, as well as all Asset properties and metadata.
=head3 vars
A hash reference containing variables and loops to pass to the template engine.
=head3 templateId
An id referring to a particular template in the templates table.
=head3 template
Instead of passing in a templateId, you may pass in a template object.
=cut
sub processTemplate {
my $self = shift;
my $session = $self->session;
my $var = shift;
my $templateId = shift;
my $template = shift;
my $className = ref $self;
# Sanity checks
if (ref $var ne "HASH") {
$session->log->error("First argument to processTemplate() should be a hash reference.");
my $i18n = WebGUI::International->new($self->session, 'Account');
return sprintf($i18n->get('Error: Cannot instantiate template'),$templateId,$className);
}
$template = WebGUI::Asset->new($session, $templateId,"WebGUI::Asset::Template") unless (defined $template);
unless (defined $template) {
$session->log->error("Can't instantiate template $templateId for class ".$className);
my $i18n = WebGUI::International->new($self->session, 'Account');
return sprintf($i18n->get('Error: Cannot instantiate template'),$templateId,$className);
}
return $template->process($var);
}
1;

View file

@ -0,0 +1,153 @@
package WebGUI::Account::Friends;
use strict;
use WebGUI::Exception;
use WebGUI::International;
use WebGUI::Pluggable;
use WebGUI::Utility;
use base qw/WebGUI::Account/;
=head1 NAME
Package WebGUI::Account::Friends
=head1 DESCRIPTION
This is the class which is used to display a users's friends
=head1 SYNOPSIS
use WebGUI::Account::Friends;
=head1 METHODS
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 editSettingsForm ( )
Creates form elements for user settings page custom to this account module
=cut
sub editUserSettingsForm {
my $self = shift;
my $session = $self->session;
my $setting = $session->setting;
my $i18n = WebGUI::International->new($session,'Account_Friends');
my $f = WebGUI::HTMLForm->new($session);
# $f->template(
# name => "profileStyleTemplateId",
# value => $self->getStyleTemplateId,
# namespace => "style",
# label => $i18n->get("profile style template label"),
# hoverHelp => $i18n->get("profile style template hoverHelp")
# );
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
=head2 editSettingsFormSave ( )
Creates form elements for user settings page custom to this account module
=cut
sub editUserSettingsFormSave {
}
#-------------------------------------------------------------------
=head2 getDisplayTemplateId ( )
This method returns the template ID for the account layout.
=cut
sub getDisplayTemplateId {
my $self = shift;
return $self->session->setting->get("friendsDisplayTempalteId") || "defaultAssetId";
}
#-------------------------------------------------------------------
=head2 getLayoutTemplateId ( )
This method returns the template ID for the account layout.
=cut
sub getLayoutTemplateId {
my $self = shift;
return $self->session->setting->get("friendsLayoutTempalteId") || $self->SUPER::getLayoutTemplateId;
}
#-------------------------------------------------------------------
=head2 getStyleTemplateId ( )
This method returns the template ID for the main style.
=cut
sub getStyleTemplateId {
my $self = shift;
return $self->session->setting->get("friendsStyleTemplateId") || $self->SUPER::getStyleTemplateId;
}
#-------------------------------------------------------------------
=head2 getViewTemplateId ( )
This method returns the template ID for the main view.
=cut
sub getViewTemplateId {
my $self = shift;
return $self->session->setting->get("friendsViewTemplateId") || "defaultAssetId";
}
#-------------------------------------------------------------------
=head2 www_display ( )
The main view page for displaying the user's profile.
=cut
sub www_display {
my $self = shift;
my $session = $self->session;
my $var = {};
return $self->processTemplate($var,$self->getDisplayTemplateId);
}
#-------------------------------------------------------------------
=head2 www_view ( )
The main view page for editing the user's profile.
=cut
sub www_view {
my $self = shift;
my $session = $self->session;
my $var = {};
return $self->processTemplate($var,$self->getViewTemplateId);
}
1;

124
lib/WebGUI/Account/Inbox.pm Normal file
View file

@ -0,0 +1,124 @@
package WebGUI::Account::Inbox;
use strict;
use WebGUI::Exception;
use WebGUI::International;
use WebGUI::Pluggable;
use WebGUI::Utility;
use base qw/WebGUI::Account/;
=head1 NAME
Package WebGUI::Account::Inbox
=head1 DESCRIPTION
This is the class which is used to display a users's inbox
=head1 SYNOPSIS
use WebGUI::Account::Inbox;
=head1 METHODS
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 editSettingsForm ( )
Creates form elements for user settings page custom to this account module
=cut
sub editUserSettingsForm {
my $self = shift;
my $session = $self->session;
my $setting = $session->setting;
my $i18n = WebGUI::International->new($session,'Account_Inbox');
my $f = WebGUI::HTMLForm->new($session);
# $f->template(
# name => "profileStyleTemplateId",
# value => $self->getStyleTemplateId,
# namespace => "style",
# label => $i18n->get("profile style template label"),
# hoverHelp => $i18n->get("profile style template hoverHelp")
# );
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
=head2 editSettingsFormSave ( )
Creates form elements for user settings page custom to this account module
=cut
sub editUserSettingsFormSave {
}
#-------------------------------------------------------------------
=head2 getLayoutTemplateId ( )
This method returns the template ID for the account layout.
=cut
sub getLayoutTemplateId {
my $self = shift;
return $self->session->setting->get("inboxLayoutTempalteId") || $self->SUPER::getLayoutTemplateId;
}
#-------------------------------------------------------------------
=head2 getStyleTemplateId ( )
This method returns the template ID for the main style.
=cut
sub getStyleTemplateId {
my $self = shift;
return $self->session->setting->get("inboxStyleTemplateId") || $self->SUPER::getStyleTemplateId;
}
#-------------------------------------------------------------------
=head2 getViewTemplateId ( )
This method returns the template ID for the main view.
=cut
sub getViewTemplateId {
my $self = shift;
return $self->session->setting->get("inboxViewTemplateId") || "defaultAssetId";
}
#-------------------------------------------------------------------
=head2 www_view ( )
The main view page for editing the user's profile.
=cut
sub www_view {
my $self = shift;
my $session = $self->session;
my $var = {};
return $self->processTemplate($var,$self->getViewTemplateId);
}
1;

View file

@ -0,0 +1,146 @@
package WebGUI::Account::Profile;
use strict;
use WebGUI::Exception;
use WebGUI::International;
use WebGUI::Pluggable;
use WebGUI::Utility;
use base qw/WebGUI::Account/;
=head1 NAME
Package WebGUI::Account::Profile
=head1 DESCRIPTION
This is the class which is used to display a users's profile information
=head1 SYNOPSIS
use WebGUI::Account::Profile;
=head1 METHODS
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 editSettingsForm ( )
Creates form elements for user settings page custom to this account module
=cut
sub editUserSettingsForm {
my $self = shift;
my $session = $self->session;
my $setting = $session->setting;
my $i18n = WebGUI::International->new($session,'Account_Profile');
my $f = WebGUI::HTMLForm->new($session);
$f->template(
name => "profileStyleTemplateId",
value => $self->getStyleTemplateId,
namespace => "style",
label => $i18n->get("profile style template label"),
hoverHelp => $i18n->get("profile style template hoverHelp")
);
$f->template(
name => "profileLayoutTempalteId",
value => $self->getLayoutTemplateId,
namespace => "Account/Layout",
label => $i18n->get("profile layout template label"),
hoverHelp => $i18n->get("profile layout template hoverHelp")
);
$f->template(
name => "profileViewTemplateId",
value => $self->getViewTemplateId,
namespace => "Account/Profile/View",
label => $i18n->get("profile view template label"),
hoverHelp => $i18n->get("profile view template hoverHelp")
);
$f->template(
name => "profileEditTemplateId",
value => $setting->get("profileEditTemplateId"),
namespace => "Account/Profile/Edit",
label => $i18n->get("profile edit template label"),
hoverHelp => $i18n->get("profile edit template hoverHelp")
);
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
=head2 getDisplayTemplateId ( )
This method returns the template ID for the account layout.
=cut
sub getDisplayTemplateId {
my $self = shift;
return $self->session->setting->get("profileDisplayTempalteId") || "defaultAssetId";
}
#-------------------------------------------------------------------
=head2 getLayoutTemplateId ( )
This method returns the template ID for the account layout.
=cut
sub getLayoutTemplateId {
my $self = shift;
return $self->session->setting->get("profileLayoutTempalteId") || $self->SUPER::getLayoutTemplateId;
}
#-------------------------------------------------------------------
=head2 getStyleTemplateId ( )
This method returns the template ID for the main style.
=cut
sub getStyleTemplateId {
my $self = shift;
return $self->session->setting->get("profileStyleTemplateId") || $self->SUPER::getStyleTemplateId;
}
#-------------------------------------------------------------------
=head2 getViewTemplateId ( )
This method returns the template ID for the main view.
=cut
sub getViewTemplateId {
my $self = shift;
return $self->session->setting->get("profileViewTemplateId") || "75CmQgpcCSkdsL-oawdn3Q";
}
#-------------------------------------------------------------------
=head2 www_view ( )
The main view page for the user's profile.
=cut
sub www_view {
my $self = shift;
my $session = $self->session;
my $var = {};
return $self->processTemplate($var,$session->setting->get("profileViewTemplateId"));
}
1;

124
lib/WebGUI/Account/User.pm Normal file
View file

@ -0,0 +1,124 @@
package WebGUI::Account::User;
use strict;
use WebGUI::Exception;
use WebGUI::International;
use WebGUI::Pluggable;
use WebGUI::Utility;
use base qw/WebGUI::Account/;
=head1 NAME
Package WebGUI::Account::User
=head1 DESCRIPTION
This is the class which is used to display a users's account details
=head1 SYNOPSIS
use WebGUI::Account::User;
=head1 METHODS
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 editSettingsForm ( )
Creates form elements for user settings page custom to this account module
=cut
sub editUserSettingsForm {
my $self = shift;
my $session = $self->session;
my $setting = $session->setting;
my $i18n = WebGUI::International->new($session,'Account_User');
my $f = WebGUI::HTMLForm->new($session);
# $f->template(
# name => "profileStyleTemplateId",
# value => $self->getStyleTemplateId,
# namespace => "style",
# label => $i18n->get("profile style template label"),
# hoverHelp => $i18n->get("profile style template hoverHelp")
# );
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
=head2 editSettingsFormSave ( )
Creates form elements for user settings page custom to this account module
=cut
sub editUserSettingsFormSave {
}
#-------------------------------------------------------------------
=head2 getLayoutTemplateId ( )
This method returns the template ID for the account layout.
=cut
sub getLayoutTemplateId {
my $self = shift;
return $self->session->setting->get("userLayoutTempalteId") || $self->SUPER::getLayoutTemplateId;
}
#-------------------------------------------------------------------
=head2 getStyleTemplateId ( )
This method returns the template ID for the main style.
=cut
sub getStyleTemplateId {
my $self = shift;
return $self->session->setting->get("userStyleTemplateId") || $self->SUPER::getStyleTemplateId;
}
#-------------------------------------------------------------------
=head2 getViewTemplateId ( )
This method returns the template ID for the main view.
=cut
sub getViewTemplateId {
my $self = shift;
return $self->session->setting->get("userViewTemplateId") || "defaultAssetId";
}
#-------------------------------------------------------------------
=head2 www_view ( )
The main view page for editing the user's profile.
=cut
sub www_view {
my $self = shift;
my $session = $self->session;
my $var = {};
return $self->processTemplate($var,$self->getViewTemplateId);
}
1;

View file

@ -0,0 +1,124 @@
package WebGUI::Content::Account;
=head1 LEGAL
-------------------------------------------------------------------
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
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::Session;
use WebGUI::Exception::Account;
use Carp qw(croak);
=head1 NAME
Package WebGUI::Content::Account
=head1 DESCRIPTION
A content handler that opens up all the account functionality. Account modules are accessed via the url like this:
/pagename?op=module;do=www_method
For example:
/home?op=profile;do=edit
In the above we're accessing the www_edit method in the WebGUI::Account::Profile module.
Module op relationships are stored in the config file as such
account : {
"profile" : "WebGUI::Account::Profile",
"inbox" : "WebGUI::Account::Inbox",
"network" : "WebGUI::Account::Network",
"user" : "WebGUI::Account::User",
"custom" : "WebGUI::Account::Custom"
}
=head1 SYNOPSIS
use WebGUI::Content::Account;
my $output = WebGUI::Content::Account::handler($session);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( session )
The content handler for this package.
=cut
sub handler {
my $session = shift;
my $form = $session->form;
my $output = undef;
my $op = $session->form->get("op");
my $configs = $session->config->get("account");
if ($configs->{$op}) {
return $session->privilege->insufficient if($session->user->isVisitor);
#$session->errorHandler->warn("Loading module : ".$configs->{$op}->{className});
#Create Pluggin Object
#Don't eval this as pluggable will croak and we want WebGUI::URL::Content to handle the exception
my $pluggin = WebGUI::Pluggable::instanciate($configs->{$op}->{className}, "new", [ $session ] );
#Check to make sure pluggin is a subclass of WebGUI::Account
unless($pluggin->isa('WebGUI::Account')) {
my $plugginType = ref $pluggin;
WebGUI::Error::InvalidObject->throw(
expected => 'WebGUI::Account',
got => $plugginType,
error => '$plugginType is not a subclass of WebGUI::Accout'
);
}
#Process the method call
my $method = $session->form->get("do") || "view";
$method = "www_".$method;
if($pluggin->can($method)) {
$output = eval { $pluggin->$method($session) };
}
else {
WebGUI::Error::MethodNotFound->throw(
error => "Couldn't call non-existant method $method",
method => $method
);
}
#Wrap content returned from method call into the layout
my $var = {};
$var->{content} = $output;
my $layoutId = $pluggin->getLayoutTemplateId;
$output = $pluggin->processTemplate($var,$layoutId);
#Wrap the layout in the user style
$session->http->setCacheControl("none");
$output = $session->style->process($output,$session->setting->get("userFunctionStyleId"));
}
return $output;
}
1;

View file

@ -0,0 +1,63 @@
package WebGUI::Exception::Account;
=head1 LEGAL
-------------------------------------------------------------------
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
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::Exception;
use Exception::Class (
'WebGUI::Error::Account::NoAccountInfo' => {
description => "Some items restrict how many you can put into your cart.",
},
);
=head1 NAME
Package WebGUI::Exception::Account
=head1 DESCRIPTION
Exceptions which apply only to the WebGUI account system.
=head1 SYNOPSIS
use WebGUI::Exception::Account;
# throw
WebGUI::Error::Account::MaxOfItemInCartReached->throw(error=>"Too many in cart.");
# try
eval { $cart->addItem($ku) };
# catch
if (my $e = WebGUI::Error->caught("WebGUI::Error::Shop::MaxOfItemInCartReached")) {
# do something
}
=head1 EXCEPTION TYPES
These exception classes are defined in this class:
=head2 WebGUI::Error::Shop::MaxOfItemInCartReached
Throw this when there are too many items of a given type added to the cart so that the user can be notified. ISA WebGUI::Error.
=cut
1;

View file

@ -15,6 +15,7 @@ use Tie::IxHash;
use WebGUI::AdminConsole;
use WebGUI::TabForm;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::SQL;
=head1 NAME
@ -603,6 +604,7 @@ sub www_editSettings {
ui => { label => $i18n->get("ui") },
messaging => { label => $i18n->get("messaging") },
misc => { label => $i18n->get("misc") },
account => { label => $i18n->get("account settings tab")},
user => { label => $i18n->get("user") },
auth => { label => $i18n->get("authentication") },
perms => { label => $i18n->get("permissions") },
@ -628,6 +630,35 @@ sub www_editSettings {
$tabform->getTab("auth")->fieldSetEnd;
}
# Get fieldsets for avaiable account methods
my $accountConfigs = $session->config->get("account");
foreach my $accountKey (keys %{$accountConfigs}) {
my $account = $accountConfigs->{$accountKey};
#Create the instance
my $className = $account->{className};
my $instance = eval { WebGUI::Pluggable::instanciate($className,"new",[ $session ]) };
if ( my $e = WebGUI::Error->caught ) {
$session->log->warn("Could not instantiate account pluggin $className...skipping");
next;
}
#Get the content of the settings form from the instance
my $settingsForm = $instance->editUserSettingsForm;
#If editUserSettingsForm is empty, skip it
next if $settingsForm eq "";
#Set the title of the fieldset
my $title = $account->{title};
WebGUI::Macro::process($title);
#Print the settings form for this account pluggin
$tabform->getTab("account")->fieldSetStart($title);
$tabform->getTab("account")->raw($settingsForm);
$tabform->getTab("account")->fieldSetEnd;
}
$tabform->submit();
$output .= $tabform->print;

View file

@ -0,0 +1,14 @@
package WebGUI::i18n::English::Account_Profile;
use strict;
our $I18N = {
'Error: Cannot instantiate template' => {
message => q{Error: Cannot instantiate template %s for class %s},
lastUpdated => 1225724810,
context => q{Error message in Account.pm},
},
};
1;

View file

@ -0,0 +1,15 @@
package WebGUI::i18n::English::Account_Friends;
use strict;
our $I18N = {
'title' => {
message => q{Friends},
lastUpdated => 1225724810,
context => q{Tab label for Friends Account pluggin},
},
};
1;

View file

@ -0,0 +1,15 @@
package WebGUI::i18n::English::Account_Inbox;
use strict;
our $I18N = {
'title' => {
message => q{Inbox},
lastUpdated => 1225724810,
context => q{Tab label for Inbox Account pluggin},
},
};
1;

View file

@ -0,0 +1,53 @@
package WebGUI::i18n::English::Account_Profile;
use strict;
our $I18N = {
'title' => {
message => q{Profile},
lastUpdated => 1225724810,
context => q{Tab label for Profile Account pluggin},
},
'profile style template label' => {
message => q|Style Template|,
lastUpdated => 1119068809
},
'profile style template hoverHelp' => {
message => q|Select a style template from the list to enclose your Wobject if it is viewed directly. If the Wobject is displayed as part of a Layout Asset, the Layout Asset's <b>Style Template</b> is used instead.|,
lastUpdated => 1119068809
},
'profile layout template label' => {
message => q|Layout Template|,
lastUpdated => 1119068809
},
'profile layout template hoverHelp' => {
message => q|Choose a layout from the list to display the various account pluggins and the contents of the one currently chosen|,
lastUpdated => 1119068809
},
'profile view template label' => {
message => q|View Template|,
lastUpdated => 1119068809
},
'profile view template hoverHelp' => {
message => q|Choose the main template for viewing a profile|,
lastUpdated => 1119068809
},
'profile edit template label' => {
message => q|Edit Template|,
lastUpdated => 1119068809
},
'profile edit template hoverHelp' => {
message => q|Choose the main template for editing a profile|,
lastUpdated => 1119068809
},
};
1;

View file

@ -0,0 +1,15 @@
package WebGUI::i18n::English::Account_User;
use strict;
our $I18N = {
'title' => {
message => q{User},
lastUpdated => 1225724810,
context => q{Tab label for User Account pluggin},
},
};
1;

View file

@ -3229,6 +3229,12 @@ a user.|,
lastUpdated => 1118941685,
},
'account settings tab' => {
message => q|Account|,
lastUpdated => 1098327046,
context => q|Tab label for the account settings in WebGUI Settings.|
},
'account' => {
message => q|Account|,
lastUpdated => 1098327046,