A class for TABLE users in schema main
#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');
This class maps to rows in table users.
users
Ado::Model::Users inherits all attributes from Ado::Model and provides the following.
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>
Each column from table users has an accessor method in this class.
none
Ado::Model::Users inherits all methods from Ado::Model and provides the following additional methods:
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.
name
my $user = Ado::Model::Users->add( login_name => $login_name, login_password => Mojo::Util::sha1_hex($login_name.$login_password) );
Adds a user with login_name to a group. Creates the group if it does not already exists. Returns the group.
login_name
$ingroup = $user->add_to_group(ingroup=>'admin');
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.
WHERE (disabled=0 AND (stop_date
first_name, last_name
$limit
$offset
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);
Selects a user by login_name column.
my $user = Ado::Model::Users->by_login_name('guest'); say $user->login_name if $user->id;
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);
DBIx::Simple::Class::Schema
This class contains also custom code.
Ado::Command::adduser, Email::Address, Ado::Model, DBIx::Simple::Class, DBIx::Simple::Class::Schema
To install Ado, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ado
CPAN shell
perl -MCPAN -e shell install Ado
For more information on module installation, please visit the detailed CPAN module installation guide.