Para::Frame::User - Represents the user behind the request
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; }
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.
$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.
$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.
$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.
$u->logout
Logs out the user.
Removes the cookies.
$u->change_current_user( $new_user )
Sets the user for this request to the object $new_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 $@;
$u->revert_from_temporary_user
Reverts back from the temporary user to the user before /become_temporary_user.
The real name of the user. Default is 'Guest'.
Conflicts with RB Resource desig...
A unique handle for the user, following the rules of a unix username. Default is 'guest'.
A unique integer identifier for the user. Default is 0.
The access level for the user. A user can access everything with a level less than or equal to her level. Default is 0.
$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).