Pluggable Account system added to WebGUI with new Profile, Inbox, Friends, User, and Shop interfaces.
This commit is contained in:
commit
4ff722bd5d
56 changed files with 6954 additions and 1090 deletions
|
|
@ -11,11 +11,7 @@ package WebGUI::Operation::Friends;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::Friends;
|
||||
use WebGUI::User;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Operation::Shared;
|
||||
use WebGUI::Content::Account;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -25,372 +21,53 @@ Package WebGUI::Operation::Friends
|
|||
|
||||
Operation handler for handling the friends network.
|
||||
|
||||
DEPRECATED - Do not use this package in new code.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_addFriend ( )
|
||||
|
||||
Form for inviting a user to become your friend.
|
||||
DEPRECATED - See WebGUI::Account::Friends::sendFriendsRequest
|
||||
|
||||
=cut
|
||||
|
||||
sub www_addFriend {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
my $friendId = $session->form->get('userId');
|
||||
my $protoFriend = WebGUI::User->new($session, $friendId);
|
||||
|
||||
my $i18n = WebGUI::International->new($session, 'Friends');
|
||||
|
||||
my $friends = WebGUI::Friends->new($session);
|
||||
if($friends->isFriend($friendId)) {
|
||||
my $returnToProfile = sprintf($i18n->get('add to friends profile'),$protoFriend->getFirstName);
|
||||
my $backUrl = $session->url->append($session->url->getRequestedUrl, 'op=viewProfile;uid='.$friendId);
|
||||
return $session->style->userStyle(
|
||||
sprintf($i18n->get("error user is already friend"),$backUrl,$returnToProfile)
|
||||
);
|
||||
}
|
||||
elsif($friends->isInvited($friendId)) {
|
||||
my $returnToProfile = sprintf($i18n->get('add to friends profile'),$protoFriend->getFirstName);
|
||||
my $backUrl = $session->url->append($session->url->getRequestedUrl, 'op=viewProfile;uid='.$friendId);
|
||||
return $session->style->userStyle(
|
||||
sprintf($i18n->get("error user is already invited"),$backUrl,$returnToProfile)
|
||||
);
|
||||
}
|
||||
|
||||
# Check for non-existant user id.
|
||||
if ((!$protoFriend->username) || (!$protoFriend->profileField('ableToBeFriend'))) {
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('add to friends'),
|
||||
$i18n->get('does not want to be a friend'),
|
||||
$session->url->getBackToSiteURL(),
|
||||
$i18n->get('493', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
my $output = join '',
|
||||
sprintf("<h1>%s</h1>\n", $i18n->get('add to friends')),
|
||||
'<p>',
|
||||
sprintf($i18n->get('add to friends description'),
|
||||
$protoFriend->getWholeName),
|
||||
'</p>',
|
||||
WebGUI::Form::formHeader($session),
|
||||
WebGUI::Form::hidden($session,
|
||||
{
|
||||
name => 'op',
|
||||
value => 'addFriendSave',
|
||||
}
|
||||
),
|
||||
WebGUI::Form::hidden($session,
|
||||
{
|
||||
name => 'userId',
|
||||
value => $friendId,
|
||||
}
|
||||
),
|
||||
WebGUI::Form::textarea($session,
|
||||
{
|
||||
name => 'comments',
|
||||
value => sprintf($i18n->get('default friend comments'), $protoFriend->getFirstName, $session->user->getFirstName),
|
||||
}
|
||||
),
|
||||
WebGUI::Form::Submit($session,
|
||||
{
|
||||
value => $i18n->get('add')
|
||||
}
|
||||
),
|
||||
WebGUI::Form::Button($session,
|
||||
{
|
||||
value => $i18n->get('cancel', 'WebGUI'),
|
||||
extras => q|onclick="history.go(-1);" class="backwardButton"|,
|
||||
}
|
||||
),
|
||||
WebGUI::Form::formFooter($session),
|
||||
;
|
||||
return $session->style->userStyle($output);
|
||||
my $uid = $session->form->process("userId");
|
||||
my $instance = WebGUI::Content::Account->createInstance($session,"friends");
|
||||
return $instance->displayContent($instance->callMethod("sendFriendsRequest",[],$uid));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_addFriendSave ( )
|
||||
|
||||
Post process the form, check for required fields, handle inviting users who are already
|
||||
members (determined by email address) and send the email.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_addFriendSave {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
|
||||
my $friendId = $session->form->get('userId');
|
||||
my $protoFriend = WebGUI::User->new($session, $friendId);
|
||||
my $i18n = WebGUI::International->new($session, 'Friends');
|
||||
|
||||
my $friends = WebGUI::Friends->new($session);
|
||||
if($friends->isFriend($friendId) || $friends->isInvited($friendId)) {
|
||||
return www_addFriend($session);
|
||||
}
|
||||
|
||||
# Check for non-existant user id.
|
||||
if ((!$protoFriend->username) || (!$protoFriend->profileField('ableToBeFriend'))) {
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('add to friends'),
|
||||
$i18n->get('does not want to be a friend'),
|
||||
$session->url->getBackToSiteURL(),
|
||||
$i18n->get('493', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
$friends->sendAddRequest($friendId, $session->form->get('comments'));
|
||||
|
||||
# display result
|
||||
my $output = sprintf(
|
||||
q!<h1>%s</h1><p>%s</p><p><a href="%s">%s</a></p><p><a href="%s">%s</a></p>!,
|
||||
$i18n->get('add to friends'),
|
||||
sprintf($i18n->get('add to friends confirmation'), $protoFriend->getWholeName),
|
||||
$session->url->append($session->url->getRequestedUrl, 'op=viewProfile;uid='.$friendId),
|
||||
sprintf($i18n->get('add to friends profile'), $protoFriend->getFirstName),
|
||||
$session->url->getBackToSiteURL(),
|
||||
$i18n->get('493', 'WebGUI'),
|
||||
);
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_friendRequest ( )
|
||||
|
||||
Form for the friend to accept or deny the request.
|
||||
DEPRECATED - See WebGUI::Account::Inbox::viewInvitation
|
||||
|
||||
=cut
|
||||
|
||||
sub www_friendRequest {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
|
||||
my $i18n = WebGUI::International->new($session, 'Friends');
|
||||
|
||||
my $inviteId = $session->form->get('inviteId');
|
||||
my $friends = WebGUI::Friends->new($session);
|
||||
|
||||
my $invitation = $friends->getAddRequest($inviteId);
|
||||
|
||||
##Invalid invite ID
|
||||
unless (exists $invitation->{friendId}) { ##No userId corresponds to the inviteId
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('invalid invite code'),
|
||||
$i18n->get('invalid invite code message'),
|
||||
$session->url->page("op=viewInbox"),
|
||||
$i18n->get('354', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
##Already a friend (check friendId already in the group)
|
||||
if ($friends->isFriend($invitation->{inviterId})) {
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('invalid invite code'),
|
||||
$i18n->get('already a friend'),
|
||||
$session->url->page("op=viewInbox"),
|
||||
$i18n->get('354', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
##Someone else's invite (check friendId vs current userId).
|
||||
if ($session->user->userId ne $invitation->{friendId}) { ##This isn't your invitation, dude.
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('invalid invite code'),
|
||||
$i18n->get('not the right user'),
|
||||
$session->url->page("op=viewInbox"),
|
||||
$i18n->get('354', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
##Everything looks good. Make the form!
|
||||
my $inviter = WebGUI::User->new($session, $invitation->{inviterId});
|
||||
my $output = join '',
|
||||
sprintf("<h1>%s</h1>\n", $i18n->get('friend request')),
|
||||
'<p>',
|
||||
sprintf($i18n->get('friend request description'),
|
||||
$inviter->getWholeName),
|
||||
'</p>',
|
||||
WebGUI::Form::formHeader($session),
|
||||
WebGUI::Form::hidden($session,
|
||||
{
|
||||
name => 'op',
|
||||
value => 'friendRequestSave',
|
||||
}
|
||||
),
|
||||
WebGUI::Form::hidden($session,
|
||||
{
|
||||
name => 'inviteId',
|
||||
value => $inviteId,
|
||||
}
|
||||
),
|
||||
WebGUI::Form::textarea($session,
|
||||
{
|
||||
name => 'comments',
|
||||
value => $invitation->{comments},
|
||||
extras => 'disabled=disabled',
|
||||
}
|
||||
),
|
||||
WebGUI::Form::Submit($session, ##Approve
|
||||
{
|
||||
name => 'doWhat',
|
||||
value => $i18n->get('572', 'WebGUI'),
|
||||
}
|
||||
),
|
||||
WebGUI::Form::Submit($session, ##Deny
|
||||
{
|
||||
name => 'doWhat',
|
||||
value => $i18n->get('574', 'WebGUI'),
|
||||
}
|
||||
),
|
||||
WebGUI::Form::formFooter($session),
|
||||
;
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_friendRequestSave ( )
|
||||
|
||||
Handle form data from the friend's response to the invitation
|
||||
|
||||
=cut
|
||||
|
||||
sub www_friendRequestSave {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
|
||||
my $i18n = WebGUI::International->new($session, 'Friends');
|
||||
my $doWhat = $session->form->get('doWhat');
|
||||
my $inviteId = $session->form->get('inviteId');
|
||||
my $friends = WebGUI::Friends->new($session);
|
||||
my $invite = $friends->getAddRequest($inviteId);
|
||||
my $inviter = WebGUI::User->new($session, $invite->{inviterId});
|
||||
##Invalid invite ID
|
||||
if (!$invite->{inviterId}) { ##No userId corresponds to the inviteId
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('invalid invite code'),
|
||||
$i18n->get('invalid invite code message'),
|
||||
$session->url->page("op=viewInbox"),
|
||||
$i18n->get('354', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
##If deny, change the status of the request to denied.
|
||||
if ($doWhat ne $i18n->get('572', 'WebGUI')) { ##request denied
|
||||
$friends->rejectAddRequest($inviteId);
|
||||
##Return screen that says they denied the request.
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('friend request'),
|
||||
sprintf($i18n->get('you have not been added'), $inviter->getWholeName),
|
||||
$session->url->page("op=viewInbox"),
|
||||
$i18n->get('354', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
}
|
||||
|
||||
##If accepted,
|
||||
# set the status to accepted.
|
||||
$friends->approveAddRequest($inviteId);
|
||||
|
||||
# Return screen that says they accepted the request.
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('friend request'),
|
||||
sprintf($i18n->get('you have been added'), $inviter->getWholeName),
|
||||
$session->url->page("op=viewInbox"),
|
||||
$i18n->get('354', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
my $instance = WebGUI::Content::Account->createInstance($session,"inbox");
|
||||
return $instance->displayContent($instance->callMethod("viewInvitation"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_manageFriends ( )
|
||||
|
||||
Display the list of friends and allow the user to remove friends or
|
||||
send private messages to a subset of them.
|
||||
|
||||
DEPRECATED - See WebGUI::Account::Friends::view
|
||||
|
||||
=cut
|
||||
|
||||
sub www_manageFriends {
|
||||
my $session = shift;
|
||||
my ($user, $url, $style) = $session->quick(qw(user url style));
|
||||
return $session->privilege->insufficient() unless ($user->isRegistered);
|
||||
my $i18n = WebGUI::International->new($session, 'Friends');
|
||||
|
||||
##You have no friends!
|
||||
my $friends = $user->friends->getUsers;
|
||||
unless (scalar(@{$friends})) {
|
||||
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('my friends'),
|
||||
$i18n->get('no friends'),
|
||||
$url->getBackToSiteURL(),
|
||||
$i18n->get('493', 'WebGUI');
|
||||
return $style->userStyle($output);
|
||||
}
|
||||
|
||||
# show the friend manager
|
||||
my %var = (
|
||||
"account.options" => WebGUI::Operation::Shared::accountOptions($session),
|
||||
formHeader => WebGUI::Form::formHeader($session)
|
||||
. WebGUI::Form::hidden($session, { name => 'op', value => 'sendMessageToFriends', }),
|
||||
removeFriendButton => WebGUI::Form::button($session, { value => $i18n->get('remove'), extras => q|onclick="confirmRemovalOfFriends(form);"|, }),
|
||||
subjectForm => WebGUI::Form::text($session, { name=>"subject" }),
|
||||
sendMessageButton => WebGUI::Form::Submit($session, { value => $i18n->get('send message'), }),
|
||||
messageForm => WebGUI::Form::textarea($session, { name=>"message" }),
|
||||
formFooter => WebGUI::Form::formFooter($session),
|
||||
);
|
||||
foreach my $userId (@{ $friends}) {
|
||||
my $friend = WebGUI::User->new($session, $userId);
|
||||
push(@{$var{friends}}, {
|
||||
name => $friend->getWholeName,
|
||||
profileUrl => $url->append($url->getRequestedUrl, 'op=viewProfile;uid='.$userId),
|
||||
status => ($friend->isOnline ? $i18n->get('online') : $i18n->get('offline')),
|
||||
checkboxForm => WebGUI::Form::checkbox($session, { name => 'userId', value => $userId, }),
|
||||
});
|
||||
}
|
||||
my $template = WebGUI::Asset->new(
|
||||
$session,
|
||||
$session->setting->get("manageFriendsTemplateId"),
|
||||
"WebGUI::Asset::Template",
|
||||
);
|
||||
return $style->userStyle($template->process(\%var));
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_removeFriends ()
|
||||
|
||||
Removes friends from the current user's friends list.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_removeFriends {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
my @users = $session->form->param("userId");
|
||||
WebGUI::Friends->new($session)->delete(\@users);
|
||||
return www_manageFriends($session);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_sendMessageToFriends ()
|
||||
|
||||
Sends a message to selected friends.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_sendMessageToFriends {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
my @users = $session->form->param("userId");
|
||||
my $friends = WebGUI::Friends->new($session);
|
||||
$friends->sendMessage($session->form->process("subject", "text"), $session->form->process("message","textarea"), \@users);
|
||||
return www_manageFriends($session);
|
||||
my $instance = WebGUI::Content::Account->createInstance($session,"friends");
|
||||
return $instance->displayContent($instance->callMethod("view"));
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -11,15 +11,11 @@ package WebGUI::Operation::Inbox;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict qw(vars subs);
|
||||
use URI;
|
||||
use WebGUI::Inbox;
|
||||
use WebGUI::Content::Account;
|
||||
use WebGUI::Inbox::Message;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Paginator;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::User;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Operation::Shared;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -37,6 +33,9 @@ Operations for viewing message logs and individual messages.
|
|||
|
||||
appends the form variables for the private message form
|
||||
|
||||
DEPRECATED: Do not use this method in new code. It is here for API
|
||||
compatibility only
|
||||
|
||||
=cut
|
||||
|
||||
sub _appendPrivateMessageForm {
|
||||
|
|
@ -55,10 +54,6 @@ sub _appendPrivateMessageForm {
|
|||
|
||||
$vars->{ message_to_label } = $i18n->get("private message to label");
|
||||
$vars->{ message_to } = $userTo->username;
|
||||
$vars->{ message_to } .= WebGUI::Form::hidden($session, {
|
||||
name=>"uid",
|
||||
value=>$userTo->userId
|
||||
});
|
||||
|
||||
my $subject = $form->get("subject") || "";
|
||||
if($subject eq "" && defined $message) {
|
||||
|
|
@ -80,22 +75,23 @@ sub _appendPrivateMessageForm {
|
|||
name=>"message",
|
||||
value=>$form->get("message") || "",
|
||||
});
|
||||
|
||||
$vars->{ form_header } = WebGUI::Form::formHeader($session);
|
||||
$vars->{ form_header } .= WebGUI::Form::hidden($session, {
|
||||
name => "op",
|
||||
value => "sendPrivateMessageSave"
|
||||
});
|
||||
$vars->{ form_header } .= WebGUI::Form::hidden($session, {
|
||||
name => "messageId",
|
||||
value => $form->get("messageId") || "",
|
||||
|
||||
my $messageId = "";
|
||||
if($form->get("messageId")) {
|
||||
$messageId = $form->get("messageId");
|
||||
}
|
||||
elsif(defined $message) {
|
||||
$messageId = $message->getId;
|
||||
}
|
||||
|
||||
$vars->{'form_header' } = WebGUI::Form::formHeader($session,{
|
||||
action => $session->url->page("op=account;module=inbox;do=sendMessageSave;messageId=$messageId;userId=".$userTo->userId),
|
||||
extras => q{name="messageForm"}
|
||||
});
|
||||
|
||||
$vars->{ submit_button } = WebGUI::Form::submit($session,{});
|
||||
$vars->{ submit_label } = $i18n->get("private message submit label");
|
||||
$vars->{ form_footer } = WebGUI::Form::formFooter($session, {});
|
||||
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -104,326 +100,58 @@ sub _appendPrivateMessageForm {
|
|||
|
||||
returns a hashref with internationalized values for message status.
|
||||
|
||||
DEPRECATED: Do not use this method in new code. Use WebGUI::Inbox::Message->statusCodes
|
||||
|
||||
=cut
|
||||
|
||||
sub _status {
|
||||
my $session = shift;
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
return {
|
||||
"pending" =>$i18n->get(552),
|
||||
"completed" =>$i18n->get(350),
|
||||
"unread" =>$i18n->get("private message status unread"),
|
||||
"read" =>$i18n->get("private message status read"),
|
||||
"replied" =>$i18n->get("private message status replied"),
|
||||
};
|
||||
return WebGUI::Inbox::Message->statusCodes($session);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_sendPrivateMessage ( )
|
||||
|
||||
Form for sending private messages
|
||||
DEPRECATED: See WebGUI::Account::Inbox::sendMessage
|
||||
|
||||
=cut
|
||||
|
||||
sub www_sendPrivateMessage {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $form = $session->form;
|
||||
my $user = $session->user;
|
||||
my $style = $session->style;
|
||||
my $settings = $session->setting;
|
||||
|
||||
my $templateId = $settings->get("sendPrivateMessageTemplateId");
|
||||
my $uid = $form->get("uid");
|
||||
my $userTo = WebGUI::User->new($session,$uid);
|
||||
|
||||
my $vars = {};
|
||||
$vars->{title} = $i18n->get('private message title');
|
||||
|
||||
if($uid eq "") {
|
||||
$vars->{'error_msg'} = $i18n->get('private message no user');
|
||||
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
|
||||
|
||||
}
|
||||
elsif($uid eq $user->userId) {
|
||||
$vars->{'error_msg'} = $i18n->get('private message no self error');
|
||||
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
|
||||
}
|
||||
|
||||
unless($userTo->acceptsPrivateMessages($user->userId)) {
|
||||
$vars->{'error_msg'} = $i18n->get('private message blocked error');
|
||||
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
|
||||
}
|
||||
|
||||
_appendPrivateMessageForm($session,$vars,$userTo);
|
||||
|
||||
$vars->{ accountOptions } = WebGUI::Operation::Shared::accountOptions($session);
|
||||
|
||||
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
|
||||
my $session = shift;
|
||||
my $uid = $session->form->get("uid");
|
||||
my $instance = WebGUI::Content::Account->createInstance($session,"inbox");
|
||||
return $instance->displayContent($instance->callMethod("sendMessage",[],$uid));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_sendPrivateMessageSave ( )
|
||||
|
||||
Post process the form, check for required fields, handle inviting users who are already
|
||||
members (determined by email address) and send the email.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_sendPrivateMessageSave {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $form = $session->form;
|
||||
my $user = $session->user;
|
||||
my $style = $session->style;
|
||||
|
||||
my $uid = $form->get("uid");
|
||||
my $userTo = WebGUI::User->new($session,$uid);
|
||||
|
||||
if($uid eq "") {
|
||||
my $output = sprintf qq|<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>|,
|
||||
$i18n->get('private message error'),
|
||||
$i18n->get('private message no user'),
|
||||
$session->url->getBackToSiteURL(),
|
||||
$i18n->get('493', 'WebGUI');
|
||||
return $style->userStyle($output);
|
||||
} elsif($uid eq $user->userId) {
|
||||
my $output = sprintf qq|<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>|,
|
||||
$i18n->get('private message error'),
|
||||
$i18n->get('private message no self error'),
|
||||
$session->url->getBackToSiteURL(),
|
||||
$i18n->get('493', 'WebGUI');
|
||||
return $style->userStyle($output);
|
||||
}
|
||||
|
||||
my $isReply = 0;
|
||||
if($form->get("messageId")) {
|
||||
my $message = WebGUI::Inbox->new($session)->getMessage($form->get("messageId"));
|
||||
# Ensure that the user sending the message was sent by the user being replied to
|
||||
# and that the user reponding is the user the message was sent to
|
||||
if($message->get("sentBy") eq $uid && $message->get("userId") eq $user->userId) {
|
||||
$isReply = 1;
|
||||
$message->setStatus("replied");
|
||||
}
|
||||
}
|
||||
|
||||
my $message = WebGUI::Inbox->new($session)->addPrivateMessage({
|
||||
message => $form->get("message"),
|
||||
subject => $form->get("subject"),
|
||||
userId => $uid,
|
||||
status => 'unread',
|
||||
sentBy => $user->userId
|
||||
},$isReply);
|
||||
|
||||
unless(defined $message) {
|
||||
my $output = sprintf qq|<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>|,
|
||||
$i18n->get('private message error'),
|
||||
$i18n->get('private message blocked error'),
|
||||
$session->url->getBackToSiteURL(),
|
||||
$i18n->get('493', 'WebGUI');
|
||||
return $style->userStyle($output);
|
||||
}
|
||||
|
||||
|
||||
my $output = sprintf qq!<p>%s</p><a href="%s">%s</a>!,
|
||||
$i18n->get('private message sent'),
|
||||
$session->url->getBackToSiteURL(),
|
||||
$i18n->get('493', 'WebGUI');
|
||||
return $session->style->userStyle($output);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_viewInbox ( )
|
||||
|
||||
Templated display all messages for the current user.
|
||||
DEPRECATED: See WebGUI::Account::Inbox::view
|
||||
|
||||
=cut
|
||||
|
||||
sub www_viewInbox {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $vars = {};
|
||||
my @msg = ();
|
||||
my $rpp = 50;
|
||||
|
||||
#Deal with page number
|
||||
my $pn = $session->form->get("pn") || 1;
|
||||
my $pn_url = "";
|
||||
$pn_url = ";pn=$pn";
|
||||
|
||||
#Deal with sort order
|
||||
my $sortBy = $session->form->get("sortBy");
|
||||
my $sort_url = "";
|
||||
$sort_url = ";sortBy=$sortBy" if($sortBy);
|
||||
|
||||
#Cache the base url
|
||||
my $inboxUrl = $session->url->page('op=viewInbox');
|
||||
|
||||
$vars->{ title } = $i18n->get(159);
|
||||
$vars->{'subject_label' } = $i18n->get(351);
|
||||
$vars->{'subject_url' } = $inboxUrl.$pn_url.";sortBy=subject";
|
||||
|
||||
$vars->{'status_label' } = $i18n->get(553);
|
||||
$vars->{'status_url' } = $inboxUrl.$pn_url.";sortBy=status";
|
||||
|
||||
$vars->{'from_label' } = $i18n->get("private message from label");
|
||||
$vars->{'from_url' } = $inboxUrl.$pn_url.";sortBy=sentBy";
|
||||
|
||||
$vars->{'dateStamp_label'} = $i18n->get(352);
|
||||
$vars->{'dateStamp_url' } = $inboxUrl.$pn_url.";sortBy=dateStamp";
|
||||
|
||||
my $adminUser = WebGUI::User->new($session,3)->username;
|
||||
my $messages = WebGUI::Inbox->new($session)->getMessagesForUser($session->user,$rpp,$pn,$sortBy);
|
||||
foreach my $message (@$messages) {
|
||||
next if($message->get('status') eq 'deleted');
|
||||
|
||||
my $hash = {};
|
||||
$hash->{ message_url } = $session->url->page('op=viewInboxMessage;messageId='.$message->getId);
|
||||
$hash->{ subject } = $message->get("subject");
|
||||
$hash->{ status_class } = $message->get("status");
|
||||
$hash->{ status } = _status($session)->{$hash->{ status_class }};
|
||||
|
||||
#Get the username of the person who sent the message
|
||||
my $sentBy = $message->get("sentBy");
|
||||
#Assume it's the admin user for speed purposes - admin user is cached above the loop
|
||||
my $from = $adminUser;
|
||||
#If it wasn't the admin user, get the username of the person who sent it
|
||||
if($sentBy ne "3") {
|
||||
my $u = WebGUI::User->new($session,$sentBy);
|
||||
#If the user that sent the message is valid, get the username
|
||||
#This case would happen if the user was deleted after sending a private message
|
||||
if($u->isRegistered) {
|
||||
$from = $u->username;
|
||||
}
|
||||
}
|
||||
|
||||
$hash->{ from } = $from;
|
||||
$hash->{ dateStamp } = $session->datetime->epochToHuman($message->get("dateStamp"));
|
||||
push(@msg,$hash);
|
||||
}
|
||||
my $msgCount = scalar(@{$messages});
|
||||
|
||||
#Pagination has to exist on every page regardless if there are more messages or not.
|
||||
if($pn > 1 ) {
|
||||
$vars->{'prev_url' } = $inboxUrl.';pn='.($pn-1).$sort_url;
|
||||
$vars->{'prev_label' } = $i18n->get("private message prev label");
|
||||
}
|
||||
if (scalar(@msg) >= $rpp) {
|
||||
$vars->{'next_url' } = $inboxUrl.';pn='.($pn+1).$sort_url;
|
||||
$vars->{'next_label' } = $i18n->get("private message next label");
|
||||
}
|
||||
|
||||
$vars->{'messages' } = \@msg;
|
||||
$vars->{'noresults' } = $i18n->get(353) unless ($msgCount > 0);
|
||||
$vars->{'accountOptions'} = WebGUI::Operation::Shared::accountOptions($session);
|
||||
my $templateId = $session->setting->get("viewInboxTemplateId");
|
||||
return $session->style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_deletePrivateMessage ( )
|
||||
|
||||
Mark a private message in the inbox as deleted.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_deletePrivateMessage {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
|
||||
#Get the message
|
||||
my $message = WebGUI::Inbox->new($session)->getMessage($session->form->param("messageId"));
|
||||
if(defined $message) {
|
||||
# set the message status to 'deleted'
|
||||
$message->setStatus("deleted");
|
||||
}
|
||||
return www_viewInbox($session);
|
||||
my $instance = WebGUI::Content::Account->createInstance($session,"inbox");
|
||||
return $instance->displayContent($instance->callMethod("view"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_viewInboxMessage ( )
|
||||
|
||||
DEPRECATED: Use WebGUI::Account::Inbox
|
||||
|
||||
Templated display of a single message for the user.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_viewInboxMessage {
|
||||
my $session = shift;
|
||||
return $session->privilege->insufficient() unless ($session->user->isRegistered);
|
||||
|
||||
#Get the message
|
||||
my $message = WebGUI::Inbox->new($session)->getMessage($session->form->param("messageId"));
|
||||
|
||||
#Make sure users can only read their own messages
|
||||
my $userId = $message->get("userId");
|
||||
my $groupId = $message->get("groupId");
|
||||
return $session->privilege->insufficient() unless (
|
||||
$session->user->userId eq $userId
|
||||
|| (defined $groupId && $session->user->isInGroup($groupId))
|
||||
);
|
||||
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $vars = {};
|
||||
$vars->{ title } = $i18n->get("private message reply title");
|
||||
$vars->{ from_label } = $i18n->get("private message from label");
|
||||
$vars->{ date_label } = $i18n->get("private message date label");
|
||||
|
||||
|
||||
if (defined $message) {
|
||||
my $origStatus = $message->get("status");
|
||||
$message->setStatus("read") if($origStatus eq "unread");
|
||||
$vars->{'message_subject' } = $message->get("subject");
|
||||
$vars->{'dateStamp'} =$session->datetime->epochToHuman($message->get("dateStamp"));
|
||||
$vars->{'status' } = _status($session)->{$message->get("status")};
|
||||
$vars->{ message } = $message->get("message");
|
||||
$vars->{ delete_text } = $i18n->get("private message delete text");
|
||||
$vars->{ delete_url } = '?op=deletePrivateMessage;messageId=' . $message->getId;
|
||||
unless ($vars->{message} =~ /\<a/ig) {
|
||||
$vars->{message} =~ s/(http\S*)/\<a href=\"$1\"\>$1\<\/a\>/g;
|
||||
}
|
||||
unless ($vars->{message} =~ /\<div/ig || $vars->{message} =~ /\<br/ig || $vars->{message} =~ /\<p/ig) {
|
||||
$vars->{message} =~ s/\n/\<br \/\>\n/g;
|
||||
}
|
||||
|
||||
#Get the username of the person who sent the message
|
||||
my $sentBy = $message->get("sentBy");
|
||||
#Assume it's the admin user who sent the message
|
||||
my $from = WebGUI::User->new($session,3)->username;
|
||||
#If the user actually exists, get the username
|
||||
if($sentBy ne "1" && $sentBy ne "3") {
|
||||
$from = WebGUI::User->new($session,$sentBy)->username;
|
||||
}
|
||||
|
||||
$vars->{ from } = $from;
|
||||
|
||||
|
||||
#If the person didn't send the message to themselves (for admin only) and the user still exsists (check visitor case)
|
||||
if($sentBy ne $session->user->userId &&
|
||||
$sentBy ne "1" &&
|
||||
$origStatus ne "pending" &&
|
||||
$origStatus ne "completed") {
|
||||
my $u = WebGUI::User->new($session,$sentBy);
|
||||
$vars->{'canReply'} = "true";
|
||||
_appendPrivateMessageForm($session,$vars,$u,$message);
|
||||
}
|
||||
|
||||
}
|
||||
$vars->{'accountOptions'} = WebGUI::Operation::Shared::accountOptions($session);
|
||||
my $templateId = $session->setting->get("viewInboxMessageTemplateId");
|
||||
return $session->style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
|
||||
my $instance = WebGUI::Content::Account->createInstance($session,"inbox");
|
||||
return $instance->displayContent($instance->callMethod("viewMessage"));
|
||||
}
|
||||
|
||||
1;
|
||||
1;
|
||||
|
|
@ -11,19 +11,11 @@ package WebGUI::Operation::Profile;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict qw(vars subs);
|
||||
use URI;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Operation::Auth;
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Content::Account;
|
||||
use WebGUI::International;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::ProfileField;
|
||||
use WebGUI::User;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::ProfileField;
|
||||
use WebGUI::ProfileCategory;
|
||||
use WebGUI::Operation::Shared;
|
||||
use WebGUI::Operation::Friends;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -46,7 +38,7 @@ These methods are available from this package:
|
|||
Returns an array of hashes for required profile fields. This array is ready
|
||||
to be used as template variables in the WebGUI template system.
|
||||
|
||||
This method is deprecated, and should not be used in new code. Use
|
||||
DEPRECATED - This method is deprecated, and should not be used in new code. Use
|
||||
the getRequiredFields method from WebGUI::ProfileField and specify the
|
||||
translation to template variables directly instead.
|
||||
|
||||
|
|
@ -80,6 +72,9 @@ duplicated in the system. Returns true of false. Will return false
|
|||
if the email address passed in is same as the email address of the
|
||||
current user.
|
||||
|
||||
DEPRECATED - This method is deprecated, and should not be used in new code. Use
|
||||
the isDuplicate method from WebGUI::ProfileField instead
|
||||
|
||||
=head3 email
|
||||
|
||||
email address to check for duplication
|
||||
|
|
@ -89,12 +84,9 @@ email address to check for duplication
|
|||
sub isDuplicateEmail {
|
||||
my $session = shift;
|
||||
my $email = shift;
|
||||
my ($otherEmail)
|
||||
= $session->db->quickArray(
|
||||
'select count(*) from userProfileData where email = ? and userId <> ?',
|
||||
[$email, $session->user->userId]
|
||||
);
|
||||
return ($otherEmail > 0);
|
||||
|
||||
my $field = WebGUI::ProfileField->new($session,'email');
|
||||
return $field->isDuplicate($email);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -103,6 +95,9 @@ sub isDuplicateEmail {
|
|||
|
||||
Saves profile data to a user's profile. Does not validate any of the data.
|
||||
|
||||
DEPRECATED - This method is deprecated, and should not be used in new code. Use
|
||||
the updateProfileFields method in WebGUI::User
|
||||
|
||||
=head3 session
|
||||
|
||||
WebGUI session object
|
||||
|
|
@ -119,12 +114,9 @@ Hash ref of profile data to save.
|
|||
|
||||
sub saveProfileFields {
|
||||
my $session = shift;
|
||||
my $u = shift;
|
||||
my $u = shift;
|
||||
my $profile = shift;
|
||||
|
||||
foreach my $fieldName (keys %{$profile}) {
|
||||
$u->profileField($fieldName,${$profile}{$fieldName});
|
||||
}
|
||||
$u->updateProfileFields($profile);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -134,6 +126,9 @@ sub saveProfileFields {
|
|||
Validates profile data from the session form variables. Returns processed data, warnings
|
||||
and errors.
|
||||
|
||||
DEPRECATED - This method is deprecated, and should not be used in new code. Use
|
||||
the validateProfileDataFromForm method from WebGUI::User instead
|
||||
|
||||
There are two levels of validation:
|
||||
|
||||
=over 4
|
||||
|
|
@ -152,46 +147,35 @@ warning if it is a duplicate.
|
|||
=cut
|
||||
|
||||
sub validateProfileData {
|
||||
my $session = shift;
|
||||
my $opts = shift || {};
|
||||
my $regOnly = $opts->{regOnly};
|
||||
my %data = ();
|
||||
my $error = "";
|
||||
my $warning = "";
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $fields = $regOnly ? WebGUI::ProfileField->getRegistrationFields($session)
|
||||
my $session = shift;
|
||||
my $opts = shift || {};
|
||||
my $regOnly = $opts->{regOnly};
|
||||
|
||||
my $error = "";
|
||||
my $warning = "";
|
||||
my $fields = $regOnly ? WebGUI::ProfileField->getRegistrationFields($session)
|
||||
: WebGUI::ProfileField->getEditableFields($session);
|
||||
foreach my $field (@$fields) {
|
||||
my $fieldValue = $field->formProcess;
|
||||
if (ref $fieldValue eq "ARRAY") {
|
||||
$data{$field->getId} = $$fieldValue[0];
|
||||
} else {
|
||||
$data{$field->getId} = $fieldValue;
|
||||
}
|
||||
if ($field->isRequired && $data{$field->getId} eq "") {
|
||||
$error .= '<li>'.$field->getLabel.' '.$i18n->get(451).'</li>';
|
||||
} elsif ($field->getId eq "email" && isDuplicateEmail($session,$data{$field->getId}) && WebGUI::ProfileField->new($session, "email")->isRequired() ) {
|
||||
$warning .= '<li>'.$i18n->get(1072).'</li>';
|
||||
}
|
||||
if ($field->getId eq "language" && $fieldValue ne "") {
|
||||
unless (exists $i18n->getLanguages()->{$fieldValue}) {
|
||||
$error .= '<li>'.$field->getLabel.' '.$i18n->get(451).'</li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
return (\%data, $error, $warning);
|
||||
|
||||
my $retHash = $session->user->validateProfileDataFromForm($fields);
|
||||
|
||||
my $warnings = $retHash->{warnings};
|
||||
my $errors = $retHash->{errors};
|
||||
|
||||
my $format = "<li>%s</li>";
|
||||
my $warning = "";
|
||||
my $error = "";
|
||||
map { $warning .= sprintf($format,$_) }@{$warnings};
|
||||
map { $error .= sprintf($format,$_) }@{$errors};
|
||||
|
||||
return ($retHash->{profile},$error,$warning);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_editProfile ( session )
|
||||
|
||||
Provide a form where user profile data can be entered or edited. The subroutine
|
||||
makes a large set of template variables which are passed to a template for presentation
|
||||
and styling. The default template is PBtmpl0000000000000051 and is not user
|
||||
selectable.
|
||||
|
||||
Calls www_editProfileSave on submission.
|
||||
DEPRECATED - This method is deprecated, and should not be used in new code.
|
||||
Use WebGUI::Account::Profile::www_edit
|
||||
|
||||
=head3 session
|
||||
|
||||
|
|
@ -200,86 +184,18 @@ A reference to the current session.
|
|||
=cut
|
||||
|
||||
sub www_editProfile {
|
||||
my $session = shift;
|
||||
return WebGUI::Operation::Auth::www_auth($session,"init") if($session->user->isVisitor);
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $vars = {};
|
||||
$vars->{displayTitle} .= $i18n->get(338);
|
||||
$vars->{'profile.message'} = $_[0] if($_[0]);
|
||||
$vars->{'profile.form.header'} = "\n\n".WebGUI::Form::formHeader($session,{});
|
||||
$vars->{'profile.form.footer'} = WebGUI::Form::formFooter($session,);
|
||||
|
||||
$vars->{'profile.form.hidden'} = WebGUI::Form::hidden($session,{"name"=>"op","value"=>"editProfileSave"});
|
||||
$vars->{'profile.form.hidden'} .= WebGUI::Form::hidden($session,{"name"=>"uid","value"=>$session->user->userId});
|
||||
my @array = ();
|
||||
foreach my $category (@{WebGUI::ProfileCategory->getCategories($session)}) {
|
||||
next unless $category->isEditable;
|
||||
my @temp = ();
|
||||
foreach my $field (@{$category->getFields}) {
|
||||
next unless ($field->isEditable);
|
||||
next if $field->getId =~ /contentPositions/;
|
||||
push(@temp, {
|
||||
'profile.form.element' => $field->formField,
|
||||
'profile.form.element.label' => $field->getLabel,
|
||||
'profile.form.element.subtext' => $field->isRequired ? "*" : undef,
|
||||
'profile.form.element.extras' => $field->getExtras,
|
||||
});
|
||||
}
|
||||
push(@array, {
|
||||
'profile.form.category' => $category->getLabel,
|
||||
'profile.form.category.loop' => \@temp
|
||||
});
|
||||
}
|
||||
$vars->{'profile.form.elements'} = \@array;
|
||||
$vars->{'profile.form.submit'} = WebGUI::Form::submit($session,{});
|
||||
$vars->{'profile.form.cancel'} = WebGUI::Form::button($session,{
|
||||
value => $i18n->get('cancel'),
|
||||
extras=>q|onclick="history.go(-1);" class="backwardButton"|,
|
||||
});
|
||||
$vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions($session);
|
||||
return $session->style->userStyle(WebGUI::Asset::Template->new($session, $session->setting->get('editUserProfileTemplate'))->process($vars));
|
||||
my $session = shift;
|
||||
my $instance = WebGUI::Content::Account->createInstance($session,"profile");
|
||||
return $instance->displayContent($instance->callMethod("edit"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_editProfileSave ( session )
|
||||
|
||||
Validates all data submitted by www_editProfile. If errors or warnings are present,
|
||||
they are concatenated and sent back to www_editProfile for display and to let the user
|
||||
correct their mistakes.
|
||||
|
||||
If no mistakes are present, saves the data to the user's profile, updates the session user
|
||||
object.
|
||||
|
||||
Returns the user to WebGUI::Operation::Auth::www_auth when done.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editProfileSave {
|
||||
my $session = shift;
|
||||
my ($profile, $error, $warning);
|
||||
return WebGUI::Operation::Auth::www_auth($session, "init") if ($session->user->isVisitor);
|
||||
($profile, $error, $warning) = validateProfileData($session);
|
||||
$error .= $warning;
|
||||
return www_editProfile($session, '<ul>'.$error.'</ul>') if($error ne "");
|
||||
foreach my $fieldName (keys %{$profile}) {
|
||||
$session->user->profileField($fieldName,$profile->{$fieldName});
|
||||
}
|
||||
return WebGUI::Operation::Auth::www_auth($session);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_viewProfile ( session )
|
||||
|
||||
View the profile data for a user by the userId specified by the form variable C<uid>.
|
||||
Validates that the user requesting the profile data is allowed to see it.
|
||||
Similarly to www_editProfile, this method is templated. The default template
|
||||
is PBtmpl0000000000000052. The template is not user selectable.
|
||||
DEPRECATED: This method is deprecated, and should not be used in new code.
|
||||
Use WebGUI::Account::Profile::www_view
|
||||
|
||||
=head3 session
|
||||
|
||||
|
|
@ -288,47 +204,11 @@ A reference to the current session.
|
|||
=cut
|
||||
|
||||
sub www_viewProfile {
|
||||
my $session = shift;
|
||||
my $u = WebGUI::User->new($session,$session->form->process("uid"));
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $vars = {};
|
||||
$vars->{displayTitle} = $i18n->get(347).' '.$u->username;
|
||||
|
||||
return $session->privilege->notMember() if($u->username eq "");
|
||||
|
||||
return $session->style->userStyle($vars->{displayTitle}.'. '.$i18n->get(862)) if($u->profileField("publicProfile") < 1 && ($session->user->userId ne $session->form->process("uid") || $session->user->isAdmin));
|
||||
return $session->privilege->insufficient() if(!$session->user->isRegistered);
|
||||
|
||||
my @array = ();
|
||||
foreach my $category (@{WebGUI::ProfileCategory->getCategories($session)}) {
|
||||
next unless ($category->get("visible"));
|
||||
push(@array, {'profile.category' => $category->getLabel});
|
||||
foreach my $field (@{$category->getFields}) {
|
||||
next unless ($field->get("visible"));
|
||||
next if ($field->get("fieldName") eq "email" && !$u->profileField("publicEmail"));
|
||||
push @array, {
|
||||
'profile.label' => $field->getLabel,
|
||||
'profile.value' => $field->formField(undef,2,$u),
|
||||
'profile.extras' => $field->getExtras,
|
||||
};
|
||||
}
|
||||
}
|
||||
$vars->{'profile.elements'} = \@array;
|
||||
|
||||
if ($session->user->userId eq $session->form->process("uid")) {
|
||||
$vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions($session);
|
||||
}
|
||||
else {
|
||||
## TODO: Make this more legible code, maybe refactor into a method
|
||||
push @{$vars->{'profile.accountOptions'}}, {
|
||||
'options.display' => '<a href="'.$session->url->page("op=addFriend;userId=".$u->userId).'">'.$i18n->get('add to friends list', 'Friends').'</a>',
|
||||
}, {
|
||||
'options.display' => '<a href="'.$session->url->page('op=sendPrivateMessage;uid='.$session->form->process("uid")).'">'.$i18n->get('send private message').'</a>',
|
||||
};
|
||||
}
|
||||
|
||||
return $session->style->userStyle(WebGUI::Asset::Template->new($session, $session->setting->get('viewUserProfileTemplate'))->process($vars));
|
||||
my $session = shift;
|
||||
my $uid = $session->form->process("uid");
|
||||
my $instance = WebGUI::Content::Account->createInstance($session,"profile");
|
||||
return $instance->displayContent($instance->callMethod("view",[],$uid));
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
1;
|
||||
|
|
@ -169,6 +169,12 @@ sub www_editProfileCategory {
|
|||
-hoverHelp => $i18n->get('470 description'),
|
||||
-value => $data->{label},
|
||||
);
|
||||
$f->text(
|
||||
-name => "shortLabel",
|
||||
-label => $i18n->get('category short name'),
|
||||
-hoverHelp => $i18n->get('category short name description'),
|
||||
-value => $data->{shortLabel},
|
||||
);
|
||||
$f->yesNo(
|
||||
-name=>"visible",
|
||||
-label=>$i18n->get(473),
|
||||
|
|
@ -198,10 +204,11 @@ sub www_editProfileCategorySave {
|
|||
my $session = shift;
|
||||
return $session->privilege->adminOnly() unless canView($session);
|
||||
my %data = (
|
||||
label=>$session->form->text("label"),
|
||||
visible=>$session->form->yesNo("visible"),
|
||||
editable=>$session->form->yesNo("editable"),
|
||||
);
|
||||
label => $session->form->text("label"),
|
||||
shortLabel => $session->form->text("shortLabel"),
|
||||
visible => $session->form->yesNo("visible"),
|
||||
editable => $session->form->yesNo("editable"),
|
||||
);
|
||||
if ($session->form->process("cid") eq "new") {
|
||||
my $category = WebGUI::ProfileCategory->create($session,\%data);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -241,33 +241,6 @@ sub definition {
|
|||
defaultValue=>$setting->get("AdminConsoleTemplate")
|
||||
});
|
||||
# messaging settings
|
||||
push(@fields, {
|
||||
tab=>"messaging",
|
||||
fieldType=>"template",
|
||||
name=>"viewInboxTemplateId",
|
||||
label=>$i18n->get('view inbox template'),
|
||||
hoverHelp=>$i18n->get('view inbox template description'),
|
||||
namespace=>"Inbox",
|
||||
defaultValue=>$setting->get("viewInboxTemplateId"),
|
||||
});
|
||||
push(@fields, {
|
||||
tab=>"messaging",
|
||||
fieldType=>"template",
|
||||
name=>"viewInboxMessageTemplateId",
|
||||
label=>$i18n->get('view inbox message template'),
|
||||
hoverHelp=>$i18n->get('view inbox message template description'),
|
||||
namespace=>"Inbox/Message",
|
||||
defaultValue=>$setting->get("viewInboxMessageTemplateId"),
|
||||
});
|
||||
push(@fields, {
|
||||
tab=>"messaging",
|
||||
fieldType=>"template",
|
||||
name=>"sendPrivateMessageTemplateId",
|
||||
label=>$i18n->get('send private message template'),
|
||||
hoverHelp=>$i18n->get('send private message template description'),
|
||||
namespace=>"Inbox/SendPrivateMessage",
|
||||
defaultValue=>$setting->get("sendPrivateMessageTemplateId"),
|
||||
});
|
||||
push(@fields, {
|
||||
tab=>"messaging",
|
||||
fieldType=>"text",
|
||||
|
|
@ -458,15 +431,6 @@ sub definition {
|
|||
namespace=>"userInvite/Email",
|
||||
defaultValue=>$setting->get("userInvitationsEmailTemplateId"),
|
||||
});
|
||||
push(@fields, {
|
||||
tab => "user",
|
||||
fieldType => "template",
|
||||
defaultValue => "managefriends_________",
|
||||
namespace => "friends/manage",
|
||||
name => "manageFriendsTemplateId",
|
||||
label => $i18n->get("manage friends template", "Friends"),
|
||||
hoverHelp => $i18n->get("manage friends template help", "Friends"),
|
||||
});
|
||||
push @fields, {
|
||||
tab => "user",
|
||||
name => "showMessageOnLogin",
|
||||
|
|
@ -498,24 +462,6 @@ sub definition {
|
|||
label => $i18n->get( 'showMessageOnLoginBody label' ),
|
||||
hoverHelp => $i18n->get( 'showMessageOnLoginBody description' ),
|
||||
defaultValue => $setting->get('showMessageOnLoginBody'),
|
||||
};
|
||||
push @fields, {
|
||||
tab => "user",
|
||||
name => 'viewUserProfileTemplate',
|
||||
fieldType => 'template',
|
||||
namespace => 'Operation/Profile/View',
|
||||
label => $i18n->get( 'user profile view template' ),
|
||||
hoverHelp => $i18n->get( 'user profile view template description' ),
|
||||
defaultValue => $setting->get('viewUserProfileTemplate'),
|
||||
};
|
||||
push @fields, {
|
||||
tab => "user",
|
||||
name => 'editUserProfileTemplate',
|
||||
fieldType => 'template',
|
||||
namespace => 'Operation/Profile/Edit',
|
||||
label => $i18n->get( 'user profile edit template' ),
|
||||
hoverHelp => $i18n->get( 'user profile edit template description' ),
|
||||
defaultValue => $setting->get('editUserProfileTemplate'),
|
||||
};
|
||||
# auth settings
|
||||
my $options;
|
||||
|
|
@ -618,6 +564,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") },
|
||||
|
|
@ -643,6 +590,38 @@ sub www_editSettings {
|
|||
$tabform->getTab("auth")->fieldSetEnd;
|
||||
}
|
||||
|
||||
# Get fieldsets for avaiable account methods
|
||||
my $accountConfigs = $session->config->get("account");
|
||||
|
||||
foreach my $account (@{$accountConfigs}) {
|
||||
#Create the instance
|
||||
my $className = $account->{className};
|
||||
my $instance = eval { WebGUI::Pluggable::instanciate($className,"new",[ $session ]) };
|
||||
if ( $@ ) {
|
||||
$session->log->warn("Could not instantiate account pluggin $className...skipping");
|
||||
next;
|
||||
}
|
||||
|
||||
#Get the content of the settings form from the instance
|
||||
my $settingsForm = eval { $instance->editSettingsForm };
|
||||
if( $@ ) {
|
||||
$session->log->warn("Error calling editSettingsForm in $className...skipping : ".$@);
|
||||
next;
|
||||
}
|
||||
|
||||
#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;
|
||||
|
||||
|
|
@ -682,6 +661,26 @@ sub www_saveSettings {
|
|||
}
|
||||
}
|
||||
|
||||
# Save account pluggin settings
|
||||
my $accountConfigs = $session->config->get("account");
|
||||
foreach my $account (@{$accountConfigs}) {
|
||||
#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;
|
||||
}
|
||||
#Save the settings
|
||||
eval { $instance->editSettingsFormSave };
|
||||
|
||||
if( my $e = WebGUI::Error->caught ) {
|
||||
$session->log->warn("Error calling editSettingsFormSave in $className...skipping : ".$e->error);
|
||||
next;
|
||||
}
|
||||
}
|
||||
|
||||
### Handle special settings
|
||||
# Reset login message seen numbers
|
||||
if ( $session->form->get( 'showMessageOnLoginReset' ) ) {
|
||||
|
|
|
|||
|
|
@ -27,73 +27,19 @@ Shared routines for WebGUI Operations.
|
|||
|
||||
TODO: DOCUMENT ME
|
||||
|
||||
DEPRECATED - USE WebGUI::Account->appendAccountOptions
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub accountOptions {
|
||||
my $session = shift;
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my @array;
|
||||
my $op = $session->form->process("op");
|
||||
|
||||
if ($session->user->isInGroup(12)) {
|
||||
my %hash;
|
||||
if ($session->var->isAdminOn) {
|
||||
$hash{'options.display'} .= '<a href="'.$session->url->page('op=switchOffAdmin').'">'.$i18n->get(12).'</a>';
|
||||
} else {
|
||||
$hash{'options.display'} .= '<a href="'.$session->url->page('op=switchOnAdmin').'">'.$i18n->get(63).'</a>';
|
||||
}
|
||||
push(@array,\%hash);
|
||||
}
|
||||
unless ($op eq "displayAccount"){
|
||||
my %hash;
|
||||
$hash{'options.display'} = '<a href="'.$session->url->page('op=auth;method=init').'">'.$i18n->get(342).'</a>';
|
||||
push(@array,\%hash);
|
||||
}
|
||||
unless ($op eq "editProfile"){
|
||||
my %hash;
|
||||
$hash{'options.display'} = '<a href="'.$session->url->page('op=editProfile').'">'.$i18n->get(341).'</a>';
|
||||
push(@array,\%hash);
|
||||
}
|
||||
unless ($op eq "viewProfile"){
|
||||
my %hash;
|
||||
$hash{'options.display'} = '<a href="'.$session->url->page('op=viewProfile;uid='.$session->user->userId).'">'.$i18n->get(343).'</a>';
|
||||
push(@array,\%hash);
|
||||
}
|
||||
unless ($op eq "viewInbox"){
|
||||
my %hash;
|
||||
$hash{'options.display'} = '<a href="'.$session->url->page('op=viewInbox').'">'.$i18n->get(354).'</a>';
|
||||
push(@array,\%hash);
|
||||
}
|
||||
push(@array, {'options.display' => '<a href="'.$session->url->page('shop=transaction;method=manageMy').'">'.$i18n->get('my purchases', 'Shop').'</a>'});
|
||||
|
||||
if ($session->setting->get('userInvitationsEnabled')) {
|
||||
push @array, {
|
||||
'options.display' => sprintf('<a href=%s>%s</a>', $session->url->page('op=inviteUser'), $i18n->get('invite a friend')),
|
||||
};
|
||||
}
|
||||
unless ($op eq "manageFriends") {
|
||||
push @array, {
|
||||
'options.display' => sprintf('<a href=%s>%s</a>', $session->url->page('op=manageFriends'), $i18n->get('see my friends', 'Friends')),
|
||||
};
|
||||
}
|
||||
my %logout;
|
||||
$logout{'options.display'} = '<a href="'.$session->url->page('op=auth;method=logout').'">'.$i18n->get(64).'</a>';
|
||||
push(@array,\%logout);
|
||||
if ($session->setting->get("selfDeactivation") && !$session->user->isAdmin){
|
||||
my %hash;
|
||||
$hash{'options.display'} = '<a href="'.$session->url->page('op=auth;method=deactivateAccount').'">'.$i18n->get(65).'</a>';
|
||||
push(@array,\%hash);
|
||||
}
|
||||
{ ##Return to site link
|
||||
my %hash;
|
||||
$hash{'options.display'} = '<a href="'.$session->url->getBackToSiteURL.'">'.$i18n->get(493).'</a>';
|
||||
push(@array,\%hash);
|
||||
}
|
||||
|
||||
return \@array;
|
||||
}
|
||||
my $vars = {};
|
||||
WebGUI::Account->appendAccountLinks($session,$vars);
|
||||
|
||||
return $vars->{'account.options'};
|
||||
}
|
||||
|
||||
=head2 secureEval ( $session, $code )
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue