Added isVisitor, isAdmin, and isRegistered methods to User object instead
of hard coding checks everywhere with group ids. And updated the code base to match.
This commit is contained in:
parent
586164d8d0
commit
ef120fb06b
52 changed files with 201 additions and 118 deletions
|
|
@ -420,6 +420,19 @@ sub identifier {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isAdmin ()
|
||||
|
||||
Returns 1 if the user is in the admins group.
|
||||
|
||||
=cut
|
||||
|
||||
sub isAdmin {
|
||||
my $self = shift;
|
||||
return $self->isInGroup(3);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isInGroup ( [ groupId ] )
|
||||
|
|
@ -481,6 +494,32 @@ sub isOnline {
|
|||
return $flag;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isRegistered ()
|
||||
|
||||
Returns 1 if the user is not a visitor.
|
||||
|
||||
=cut
|
||||
|
||||
sub isRegistered {
|
||||
my $self = shift;
|
||||
return $self->userId ne '1';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isVisitor ()
|
||||
|
||||
Returns 1 if the user is a visitor.
|
||||
|
||||
=cut
|
||||
|
||||
sub isVisitor {
|
||||
my $self = shift;
|
||||
return $self->userId eq '1';
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -611,7 +650,7 @@ sub newByEmail {
|
|||
my $email = shift;
|
||||
my ($id) = $session->dbSlave->quickArray("select userId from userProfileData where email=?",[$email]);
|
||||
my $user = $class->new($session, $id);
|
||||
return undef if ($user->userId eq "1"); # visitor is never valid for this method
|
||||
return undef if ($user->isVisitor); # visitor is never valid for this method
|
||||
return undef unless $user->username;
|
||||
return $user;
|
||||
}
|
||||
|
|
@ -640,7 +679,7 @@ sub newByUsername {
|
|||
my $username = shift;
|
||||
my ($id) = $session->dbSlave->quickArray("select userId from users where username=?",[$username]);
|
||||
my $user = $class->new($session, $id);
|
||||
return undef if ($user->userId eq "1"); # visitor is never valid for this method
|
||||
return undef if ($user->isVisitor); # visitor is never valid for this method
|
||||
return undef unless $user->username;
|
||||
return $user;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue