NAME

Krang::User - a means to access information on users


SYNOPSIS

  use Krang::ClassLoader 'User';
  # construct object
  my $user = Krang::User->new(email => 'a@b.com',               #optional
                              first_name => 'fname',            #optional
                              group_ids => [1, 2, 3],           #optional
                              last_name => 'lname',             #optional
                              login => 'login',                 #required
                              mobile_phone => '112-358-1321'    #optional
                              password => 'passwd',             #required
                              phone => '123-456-8901');         #optional
  # saves object to the DB
  $user->save();
  # getters
  ##########
  my $email     = $user->email();
  my $first_name= $user->first_name();
  my @group_ids = $user->group_ids();   # returns arrayref or array
  my $last_name = $user->last_name();
  my $login     = $user->login();
  my $password  = $user->password();
  my $phone     = $user->phone();
  my $id        = $user->user_id();     # undef until save()
  # setters
  ##########
  $user->first_name( 'first_name' );
  $user->group_ids( @ids );
  $user->last_name('last_name');
  $user->login( 'loginX' );
  $user->mobile_phone( $phone_number );
  $user->password( $password );         # stores MD5 of $self->SALT, $password
  $user->phone( $phone_number );
  # delete the user from the database
  $user->delete();
  # a hash of search parameters
  my %params =
  ( order_desc => 1,            # result ascend unless this flag is set
    limit => 5,                 # return 5 or less user objects
    offset => 1,                # start counting result from the
                                # second row
    order_by => 'user_id'       # sort on the 'user_id' field
    login_like => '%fred%',     # match rows with 'login's LIKE '%fred'
    phone_like => '718%' );     # match rows with phone#'s LIKE '718%'
  # any valid object field can be appended with '_like' to perform a
  # case-insensitive sub-string match on that field in the database
  # returns an array of user objects matching criteria in %params
  my @users = pkg('User')->find( %params );


DESCRIPTION

Each user object corresponds to an authorized user of the system. The degree of access a user is determined by the groups with which he is associated.

N.B. - Passwords are MD5 digests of $self->SALT and the password string; the original password string in not retrievable once it is passed but can only be calculated and compared i.e.:

  my $valid_password =
    $user->{password} eq md5_hex($self->SALT, $password_string) ? 1 : 0;


INTERFACE

FIELDS

Access to fields for this object is provided my Krang::MethodMaker. The value of fields can be obtained and set in the following fashion:

 $value = $user->field_name();
 $user->field_name( $some_value );

The available fields for a user object are:

METHODS


TO DO


SEE ALSO

Krang, Krang::DB