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


Myco-Core-User documentation  | view source Contained in the Myco-Core-User distribution.

Index


NAME

Top

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

VERSION

Top

1.0

SYNOPSIS

Top

  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

Top

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

Top

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

Top

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

ATTRIBUTES

Top

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&39;s login name.

-pass: string(32) = undef

The user&39;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&39;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&39;t use the hash to get at the roles, though. See below for the methods specific to Role access.

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

ADDED CLASS / INSTANCE METHODS

Top

chk_pass

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

Checks the user&39;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

Top

AUTHORS

Top

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

SEE ALSO

Top

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


Myco-Core-User documentation  | view source Contained in the Myco-Core-User distribution.