Account release candidate - final changes before merge

This commit is contained in:
Frank Dillon 2008-11-15 02:39:23 +00:00
parent aec93573f0
commit 11d18075fa
45 changed files with 3379 additions and 1325 deletions

View file

@ -24,6 +24,7 @@ use WebGUI::ProfileField;
use WebGUI::ProfileCategory;
use WebGUI::Operation::Shared;
use WebGUI::Operation::Friends;
use WebGUI::Account::Profile;
=head1 NAME
@ -92,12 +93,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);
}
#-------------------------------------------------------------------
@ -107,7 +105,7 @@ 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 saveProfileFields method from WebGUI::Account::Profile instead
the updateProfileFields method in WebGUI::User
=head3 session
@ -127,8 +125,7 @@ sub saveProfileFields {
my $session = shift;
my $u = shift;
my $profile = shift;
WebGUI::Account::Profile->saveProfileFields($session,$u,$profile);
$u->updateProfileFields($profile);
}
#-------------------------------------------------------------------
@ -139,7 +136,7 @@ Validates profile data from the session form variables. Returns processed data,
and errors.
DEPRECATED - This method is deprecated, and should not be used in new code. Use
the validateProfileData method from WebGUI::Account::Profile instead
the validateProfileDataFromForm method from WebGUI::User instead
There are two levels of validation:
@ -159,48 +156,38 @@ 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);
use Data::Dumper;
print Dumper($retHash)."\n\n\n";
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.
DEPRECATED - Use WebGUI::Account::Profile::www_edit
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
@ -209,91 +196,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.
DEPRECATED: Use WebGUI::Account::Profile::www_editSave
=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: Use WebGUI::Account::Profile::www_view
DEPRECATED: This method is deprecated, and should not be used in new code.
Use WebGUI::Account::Profile::www_view
=head3 session
@ -302,46 +216,10 @@ 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));
}