The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Myco::Core::User - Interface to Myco User Objects

VERSION

1.0

SYNOPSIS

  use Myco::Core::User;

  # Constructors.
  my $user = Myco::Core::User->new;
  # See Myco::Entity for more.

  # Class Methods.

  # Instance Methods.
  my $person = $user->get_person;
  $user->set_person($person);
  my $login = $user->login;
  $login->set_login($login);
  $user->set_pass($pass);
  if ($user->chk_pass($pass)) {
      # Allow access.
  }

  $user->save;
  $user->destroy;

DESCRIPTION

This Class provides the basic interface to all Myco user objects. It offers the ability to set and get the login name, and to set and check the password. The password is double-MD5 hash encrypted for security.

QUERIES

Myco::Query::Meta::Query objects defining generic and reusable queries for finding Myco::Core::User objects.

default query

  my $metadata = Myco::Core::User->introspect->get_queries;
  my $default_query = $metadata->{default};
  my @results = $default_query->run_query(login => 'doej');

Find a user object with a given unique login attribute.

by_person query

  my $metadata = Myco::Core::User->introspect->get_queries;
  my $default_query = $metadata->{by_person};
  my @results = $default_query->run_query(person => $p);

Find a user object with a person attribute set to a given Myco::Core::Person object, $p.

COMMON ENTITY INTERFACE

Constructor, accessors, and other methods -- as inherited from Myco::Entity.

ATTRIBUTES

Attributes may be initially set during object construction (with new()) but otherwise are accessed solely through accessor methods. Typical usage:

  • Set attribute value

     $user->set_attribute($value);

    Check functions (see Class::Tangram) perform data validation. If there is any concern that the set method might be called with invalid data then the call should be wrapped in an eval block to catch exceptions that would result.

  • Get attribute value

     $value = $user->get_attribute;

Available attributes are listed below, using syntax borrowed from UML class diagrams; for each showing the name, type, default initial value (if any), and, following that, a description.

-person: ref(Myco::Core::Person) = Myco::Core::Person

The person object to which this user belongs. Access this object to output name information about a user.

-login: string(128) = undef

The user's login name.

-pass: string(32) = undef

The user's login password. Internally, it will be encrypted in a double-MD5 hash before being stored in the system.

-roles: hash (string(64} => int) = {}

The user's roles. These are stored in a hash, where the keys are the role names and the values are an integer, usually "1". Mostly, you shouldn't use the hash to get at the roles, though. See below for the methods specific to Role access.

############################################################################## # Methods ##############################################################################

ADDED CLASS / INSTANCE METHODS

chk_pass

  if ($user->chk_pass($pass)) {
      # Allow access.
  }

Checks the user's pass word or phrase. Returns true if the pass word or phrase is correct, and false if it is not.

get_roles

  my @roles = $user->get_roles;
  my $roles_aref = $user->get_roles;

Returns a list (in an array context) or an anonymous array (in a scalar context) of all the roles assigned to the user.

add_roles

  $user->add_roles(@roles);

Adds the listed roles to the user. If any role in @roles does not actually exist as a role, then add_roles() will throw an exception.

del_roles

  $user->del_roles(@roles);

Deletes the listed roles from the user.

get_roles_hash

  $user->get_roles_hash;

Returns an anonymous hash of all of the roles assigned to the user. The hash keys are the role names, and the values are a simple integer (usually one). This is the internal representation of the roles in the User object, and normally this method will only be used internally.

get_displayname

  $user->get_displayname;

Returns the displayname of the person (first and last name) associated with a user.

find_user

  my $u = Myco::Core::User->find_user($person);

Finds a user, given a Myco::Core::Person. This is a simple wrapper around the 'by_person' query contained in the Myco::Core::User query.

LICENSE AND COPYRIGHT

Copyright (c) 2006 the myco project. All rights reserved. This software is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS

Charles Owens <charles@mycohq.com>, David Wheeler <david@wheeler.net>, and Ben Sommer <ben@mycohq.com>

SEE ALSO

Myco, Myco::Entity, Myco::Core::Person, Tangram, Class::Tangram,