NAME

A class for TABLE users in schema main

SYNOPSIS

#In a controller use the helper.
#Find a user by login_name and change the current user
my $user       = Ado::Model::Users->by_login_name($login_name);
$c->user($user);

#in a template
<h1>Hello, <%=user->name%>!</h1>

#Create a new user.
my $user = Ado::Model::Users->add(login_name=>'petko'...);
#Add the user to a group
$user->add_to_group('cool');

DESCRIPTION

This class maps to rows in table users.

ATTRIBUTES

Ado::Model::Users inherits all attributes from Ado::Model and provides the following.

name

Readonly. Returns concatenated "first_name" and "last_name" of the user or the username (in case the first two are not available).

# Hello, Guest
<h1>Hello, <%=user->name%>!</h1>

COLUMNS

Each column from table users has an accessor method in this class.

id

group_id

login_name

login_password

first_name

last_name

email

description

created_by

changed_by

tstamp

reg_date

disabled

start_date

stop_date

ALIASES

none

METHODS

Ado::Model::Users inherits all methods from Ado::Model and provides the following additional methods:

add

Given enough parameters creates a new user object and inserts it into the table users. Creates a primary group for the user with the same group name. Throws an exception if any of the above fails. Returns (the eventually newly created) user object.

my $user = Ado::Model::Users->add(
    login_name     => $login_name,
    login_password => Mojo::Util::sha1_hex($login_name.$login_password)
);

add_to_group

Adds a user with login_name to a group. Creates the group if it does not already exists. Returns the group.

$ingroup = $user->add_to_group(ingroup=>'admin');

by_email

Selects a user by email column.

my $user = Ado::Model::Users->by_email('user@example.com');
say $user->email if $user->id;

by_group_name

Selects active users (WHERE (disabled=0 AND (stop_date$now OR stop_date=0) AND start_date<$now )>) belonging to a given group only and within a given range, ordered by first_name, last_name alphabetically. $limit defaults to 500 and $offset to 0. Only the following fields are retrieved: id, login_name, first_name, last_name, email.

Returns an array of hashes. The "name" method is executed for each row in the resultset and the evaluation is available via key 'name'.

#get contacts of the user 'berov'
my @users = Ado::Model::Users->by_group_name('vest_contacts_for_berov', $limit, $offset);

by_login_name

Selects a user by login_name column.

my $user = Ado::Model::Users->by_login_name('guest');
say $user->login_name if $user->id;

ingroup

Given a group name returns true if a user is member of the group. Returns false otherwise. Returns a list of all group names a user belongs to if no group name passed.

say $user->name . ' is admin!' if $user->ingroup('admin');
say $user->name .' is member of the following groups:'
. join(', ', $user->ingroup);

GENERATOR

DBIx::Simple::Class::Schema

This class contains also custom code.

SEE ALSO

Ado::Command::adduser, Email::Address, Ado::Model, DBIx::Simple::Class, DBIx::Simple::Class::Schema