Solstice::UserService - Provides access to the logged-in user.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::UserService - Provides access to the logged-in user.

SYNOPSIS

Top

  use Solstice::UserService;

  my $service = Solstice::UserService->new();

  my $user = $service->getUser();

DESCRIPTION

Top

You can get the currently logged-in user at any time using this service.

Superclass

Solstice::Service

Export

No symbols exported..

Methods

getUser()

Returns a Person object. If there is no Session, or no user in Session, $person is created using Solstice::Service::LoginRealm.

hasUser()

Returns TRUE if a user can be created. This means the session has a user, or $ENV{'REMOTE_USER'} is defined.

getOriginalUser()

Returns the original Person object, ignoring administrative overrides.

Modules Used

Solstice::Service, Solstice::Factory::Person (Solstice::Factory::Person), Solstice::Service::LoginRealm, Solstice::Session.

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 3382 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::UserService;

# $Id: UserService.pm 3382 2006-05-15 21:25:18Z pmichaud $

use 5.006_000;
use strict;
use warnings;

use base qw(Solstice::Service);

use Solstice::Service::LoginRealm;
use Solstice::Factory::Person;
use Solstice::Session;

use constant TRUE  => 1;
use constant FALSE => 0;

our ($VERSION) = ('$Revision: 3382 $' =~ /^\$Revision:\s*([\d.]*)/);

sub getUser {
    my $self = shift;
    
    my $session = Solstice::Session->new();
    
    unless (defined $session) {
        die "Session not defined in UserService::getUser, called from ". join(' ', caller)."\n";
    }
    
    my $person;
    if ($person = $session->getUser()) {
        $self->loadModule(ref $person->getLoginRealm());
        return $person;
    }

    if (my $login = Solstice::Service::LoginRealm->new()->getLogin()) {
        $person = Solstice::Factory::Person->new()->createByLogin($login);
        $person->updateLoginDate();
        $session->setUser($person);
        return $person;
    }

    return;
}

sub hasUser {
    my $self = shift;
    return (defined Solstice::Session->new()->getUser()) ? TRUE : FALSE;
}

sub getOriginalUser {
    my $self = shift;

    my $session = Solstice::Session->new();

    my $person = $session->getOriginalUser();
    return $person if defined $person;

    $self->getUser(); #init the original user, then
    $session = Solstice::Session->new();
    return $session->getOriginalUser();
}


1;
__END__