NAME

Para::Frame::User - Represents the user behind the request

SYNOPSIS

  package My::User;
  use Para::Frame::Utils qw( throw passwd_crypt );
  use base qw(Para::Frame::User);

  sub verify_password
  {
    my( $u, $password_encrypted ) = @_;

    $password_encrypted ||= '';

    if( $password_encrypted eq passwd_crypt($u->{'passwd'}) )
    {
	return 1;
    }
    else
    {
	return 0;
    }
  }

  sub get
  {
      my( $class, $username ) = @_;

      my $rec;

      if( $username eq 'egon' )
      {
        $rec =
        {
          name => 'Egon Duktig',
          username => 'egon',
          uid      => 123,
          level    => 1,
          passwd   => 'hemlis',
        };
      elsif( $username eq 'guest' )
      {
        $rec =
        {
          name => 'The guest',
          username => 'guest',
          uid      => 0,
          level    => 0,
        };
      }
      else
      {
        return undef;
      }

      return bless $rec, $class;
  }

DESCRIPTION

This is the base class for the application User class. The user object can be accessed as $req->u from Perl and user from templates.

Methods

identify_user

  $class->identify_user()

  $class->identify_user( $username )

  $class->identify_user( $username, \%args )

%args may include:

  password_encrypted

This will only identify who the client is claiming to be. Authentication is done by /authenticate_user.

$username will default to cookie username. $args->{password_encrypted} will default to cookie password.

Password is used for cases when where may be more than one user with the same username.

Subclass /get to actually looking up and returning the user.

/identify_user and /authenticate_user is called at the beginning of each request that does not have a sotred result.

user_not_found_msg

authenticate_user

get

  $this->get( $username )

Returns the user object, or undef if no such user exist.

This method should be reimplemented in a User class that inherits from this class.

See the example above.

The special user guest should always be recognized and the user object must always contain the hash fields given in the example.

Do not throw any exceptions in this code.

verify_password

  $u->verify_password( $encrypted_password )

Returns true or false.

Compare the password as in the example above, using Para::Frame::User/passwd_crypt. See this function for the restrictions.

cas_session

cas_verified

logout

  $u->logout

Logs out the user.

Removes the cookies.

clear_cookies

change_current_user

  $u->change_current_user( $new_user )

Sets the user for this request to the object $new_user.

become_temporary_user

  $u->become_temporary_user( $new_user )

Temporarily change the user for this request to the object $new_user, for some special operation. Remember who the real user is. Make sure to switch back then done, and use eval{} to catch errors and switch back before any exception.

Switch back to the real user with /revert_from_temporary_user.

Example: $Para::Frame::U->become_temporary_user($root); eval { # do your stuff... }; $Para::Frame::U->revert_from_temporary_user; die $@ if $@;

revert_from_temporary_user

  $u->revert_from_temporary_user

Reverts back from the temporary user to the user before /become_temporary_user.

name

The real name of the user. Default is 'Guest'.

desig

Conflicts with RB Resource desig...

username

A unique handle for the user, following the rules of a unix username. Default is 'guest'.

uid

A unique integer identifier for the user. Default is 0.

level

The access level for the user. A user can access everything with a level less than or equal to her level. Default is 0.

style

has_root_access

has_page_update_access

  $u->has_page_update_access()

  $u->has_page_update_access( $file )

Reimplement this to give update access for a specific page or the default access for the given user.

$file must be a Para::Frame::File object.

Returns: true or false

The default is false (0).

SEE ALSO

Para::Frame