Pluggable Account system added to WebGUI with new Profile, Inbox, Friends, User, and Shop interfaces.

This commit is contained in:
Frank Dillon 2008-11-15 11:39:23 +00:00
commit 4ff722bd5d
56 changed files with 6954 additions and 1090 deletions

View file

@ -118,6 +118,9 @@ sub acceptsPrivateMessages {
my $self = shift;
my $userId = shift;
return 0 if ($self->isVisitor); #Visitor can't get private messages
return 0 if ($self->userId eq $userId); #Can't send private messages to yourself
my $pmSetting = $self->profileField('allowPrivateMessages');
return 0 if ($pmSetting eq "none");
@ -130,7 +133,37 @@ sub acceptsPrivateMessages {
return $sentBy->isInGroup($friendsGroup->getId);
}
return 1;
return 0;
}
#-------------------------------------------------------------------
=head2 acceptsFriendsRequests ( user )
Returns whether or this user will accept friends requests from the user passed in
=head3 user
WebGUI::User object to check to see if user will accept requests from.
=cut
sub acceptsFriendsRequests {
my $self = shift;
my $session = $self->session;
my $user = shift;
return 0 unless ($user && ref $user eq "WebGUI::User"); #Sanity checks
return 0 if($self->isVisitor); #Visitors can't have friends
return 0 if($self->userId eq $user->userId); #Can't be your own friend (why would you want to be?)
my $me = WebGUI::Friends->new($session,$self);
my $friend = WebGUI::Friends->new($session,$user);
return 0 if ($me->isFriend($user->userId)); #Already a friend
return 0 if ($me->isInvited($user->userId) || $friend->isInvited($self->userId)); #Invitation sent by one or the other
return $self->profileField('ableToBeFriend'); #Return profile setting
}
#-------------------------------------------------------------------
@ -317,13 +350,12 @@ Returns the WebGUI::Group for this user's Friend's Group.
sub friends {
my $self = shift;
if ($self->{_user}{"friendsGroup"} eq "") {
my $myFriends = WebGUI::Group->new($self->session, "new");
my $myFriends = WebGUI::Group->new($self->session, "new",0,1);
$myFriends->name($self->username." Friends");
$myFriends->description("Friends of user ".$self->userId);
$myFriends->expireOffset(60*60*24*365*60);
$myFriends->showInForms(0);
$myFriends->isEditable(0);
$myFriends->deleteUsers(['3']);
$self->uncache;
$self->{_user}{"friendsGroup"} = $myFriends->getId;
$self->{_user}{"lastUpdated"} = $self->session->datetime->time();
@ -418,6 +450,30 @@ sub getGroupIdsRecursive {
#-------------------------------------------------------------------
=head2 getProfileUrl ( [page] )
Returns a link to the user's profile
=head3 page
If page is passed in, the profile ops will be appended to the page, otherwise
the method will return the ops appended to the current page.
=cut
sub getProfileUrl {
my $self = shift;
my $session = $self->session;
my $page = shift || $session->url->page;
my $identifier = $session->config->get("profileModuleIdentifier");
return qq{$page?op=account;module=$identifier;do=view;uid=}.$self->userId;
}
#-------------------------------------------------------------------
=head2 getWholeName ( )
Attempts to build the user's whole name from profile fields, and ultimately their alias and username if all else
@ -433,6 +489,20 @@ sub getWholeName {
return $self->profileField("alias") || $self->username;
}
#-------------------------------------------------------------------
=head2 hasFriends ( )
Returns whether or not the user has any friends on the site.
=cut
sub hasFriends {
my $self = shift;
my $users = $self->friends->getUsers(1);
return scalar(@{$users}) > 0;
}
#-------------------------------------------------------------------
# This method is depricated and is provided only for reverse compatibility. See WebGUI::Auth instead.
sub identifier {
@ -764,6 +834,36 @@ sub profileField {
#-------------------------------------------------------------------
=head2 profileIsViewable ( user )
Returns whether or not the user's profile is viewable by the user passed in
=head3 user
The user to test to see if the profile is viewable for. If no user is passed in,
the current user in session will be tested
=cut
sub profileIsViewable {
my $self = shift;
my $user = shift || $self->session->user;
my $userId = $user->userId;
return 0 if ($self->isVisitor); #Can't view visitor's profile
return 1 if ($self->userId eq $userId); #Users can always view their own profile
my $profileSetting = $self->profileField('publicProfile');
return 0 if ($profileSetting eq "none");
return 1 if ($profileSetting eq "all");
my $friendsGroup = $self->friends;
return $user->isInGroup($friendsGroup->getId);
}
#-------------------------------------------------------------------
=head2 referringAffiliate ( [ value ] )
Returns the unique identifier of the affiliate that referred this user to the site.
@ -852,6 +952,27 @@ sub uncache {
#-------------------------------------------------------------------
=head2 updateProfileFields ( profile )
Saves profile data to a user's profile. Does not validate any of the data.
=head3 profile
Hash ref of key/value pairs of data in the users's profile to update.
=cut
sub updateProfileFields {
my $self = shift;
my $profile = shift;
foreach my $fieldName (keys %{$profile}) {
$self->profileField($fieldName,$profile->{$fieldName});
}
}
#-------------------------------------------------------------------
=head2 username ( [ value ] )
Returns the username.
@ -889,6 +1010,78 @@ sub userId {
#-------------------------------------------------------------------
=head2 validateProfileDataFromForm ( fields )
Validates profile data from the session form variables. Returns an data structure which contains the following
{
profile => Hash reference containing all of the profile fields and their values
errors => Array reference of error messages to be displayed
errorCategory => Category in which the first error was thrown
warnings => Array reference of warnings to be displayed
errorFields => Array reference of the fieldIds that threw an error
warningFields => Array reference of the fieldIds that threw a warning
}
=head3 fields
An array reference of profile field Ids to validate.
=cut
sub validateProfileDataFromForm {
my $self = shift;
my $session = $self->session;
my $fields = shift;
my $i18n = my $i18n = WebGUI::International->new($session);
my $data = {};
my $errors = [];
my $warnings = [];
my $errorCat = undef;
my $errorFields = [];
my $warnFields = [];
foreach my $field (@{$fields}) {
my $fieldId = $field->getId;
my $fieldLabel = $field->getLabel;
my $fieldValue = $field->formProcess;
my $isValid = $field->isValid($fieldValue);
$data->{$fieldId} = (ref $fieldValue eq "ARRAY") ? $fieldValue->[0] : $fieldValue;
if(!$isValid) {
$errorCat = $field->get("profileCategoryId") unless (defined $errorCat);
push (@{$errors}, sprintf($i18n->get("required error"),$fieldLabel));
push(@{$errorFields},$fieldId);
}
#The language field is special and must be always be valid or WebGUI will croak
elsif($fieldId eq "language" && !(exists $i18n->getLanguages()->{$data->{$fieldId}})) {
$errorCat = $field->get("profileCategoryId") unless (defined $errorCat);
push (@{$errors}, sprintf($i18n->get("language not available error"),$data->{$fieldId}));
push(@{$errorFields},$fieldId);
}
#Duplicate emails throw warnings
elsif($fieldId eq "email" && $field->isDuplicate($fieldValue)) {
$errorCat = $field->get("profileCategoryId") unless (defined $errorCat);
push (@{$warnings},$i18n->get(1072));
push(@{$warnFields},$fieldId);
}
}
return {
profile => $data,
errors => $errors,
warnings => $warnings,
errorCategory => $errorCat,
errorFields => $errorFields,
warningFields => $warnFields,
};
}
#-------------------------------------------------------------------
=head2 validUserId ( userId )
Returns true if the userId exists in the users table.