NAME
MojoX::Authentication::Model::Db
SYNOPSIS
use MojoX::Authentication::Model::Db;
DESCRIPTION
This class is not supposed to be used directly but through MojoX::Authentication::Model instead.
This class composes role MojoX::Authentication::Model::Role::Local and inherits its methods.
This class needs MojoX::MojoDbWrap version 0.100 or later.
INTERFACE
create
my $instance = MojoX::Authentication::Model::Db->create($config, %args);
Constructor.
Can receive the configuration either from a more "generic" $config hash as well as direct named arguments.
First a name is determined, either from $args{name} or dby by default. Then $config is looked at for a corresponding value, which is either expected to be missing/undef or be a hash reference. In case a hash reference is found, its pairs override those on %args, with the only exception of the key name which is preserved if already present or set to the default otherwise.
Argument wmdb is mandatory (an exception is thrown otherwise), see "wmdb".
Also accepts parameters for the following accessors: "name" (only from %args, see above), "table", crypt_passphrase, key_for_secret and protected_keys (inherited from role MojoX::Authentication::Model::Role::Local), "remaps", and "username_column".
load_user
my $user = $provider->load_user($ignored, $uid);
Load the user by its userid, compatibly with Mojolicious::Plugin::Authentication's interface for loading users. The first parameter (which is supposed to be a controller instance) is ignored.
This class has no distinction between user identifiers and usernames: the record is looked for in "table", using column "username_column". The record is then passed through "remaps". Returns nothing if the record is not present.
load_user_by_username
my $user = $provider->load_user_by_username($ignored, $username);
Alias for "load_user", as this class has no distinction between user identifiers and usernames.
name
my $name = $provider->name;
$provider->name($new_name);
Name assigned to the provider (e.g. if you want to use different databases at the same time and hence want to instantiate this class multiple times). It is read-write: MojoX::Authentication::Model sets it to the name it registers the provider under (see "Provider names" in MojoX::Authentication::Model).
remaps
my $aref = $provider->remaps;
Accessor for the list of remaps, handled by MojoX::Authentication::Model::Role::Remap.
Remaps never see the column holding the secret, nor the other protected keys (see MojoX::Authentication::Model::Role::Remap): if the hash is not in a column named secret, set key_for_secret to the column's name (e.g. key_for_secret => 'userpass') instead of remapping it.
save_user
$provider->save_user($user); # OR
$provider->save_user($user, $is_secret_cleartext);
Save a user.
The input $user is supposed to be a hash reference with at least key username (for the username/userid) and, for an account that logs in with a password, the key for the secret (secret by default, see key_for_secret), after "remaps" are applied backwards. It MAY contain other key/value pairs, which will be copied.
The record is inserted, or updated if a record with the same value in column "username_column" is already present; for this reason, the column MUST have a UNIQUE constraint (or be the primary key).
The secret is supposed to be already hashed. It is possible to set the optional additional parameter $is_secret_cleartext to a true value to indicate that the hashing should be done by the function before saving the user.
table
my $string = $provider->table;
Returns the name of the table where user accounts are kept. Defaults to account.
See also "username_column" and "remaps".
username_column
my $string = $provider->username_column;
Returns the name of the column where the username is kept. Defaults to username.
See also "table".
wmdb
my $wmdb = $provider->wmdb;
Accessor to the MojoX::MojoDbWrap object wrapping the relevant database access object (most probably an object of either Mojo::SQLite or Mojo::Pg class).
At construction it can be a MojoX::MojoDbWrap object, an object with a wmdb method returning one, a sub reference returning one, or the arguments for creating one (e.g. { db_url => 'sqlite:accounts.db' }).
ANYTHING ELSE (INCLUDING AUTHOR, COPYRIGHT AND LICENSE)
See documentation for MojoX::Authentication.