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.
INTERFACE
column_remaps
my $aref = $self->column_remaps;
create
my $instance = MojoX::Authentication::Model::Db->new( $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 hashy 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.
If the wmdb key is present, a new instance of the class is created and returned. Otherwise, the method returns undef.
Also accepts parameters for the following accessors: "name" (only from %args, see above), "table", "column_remaps", "crypt_passphrase" (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.
See "id_column".
load_user_by_name
my $user = $provider->load_user_by_name($ignored, $username);
Load the user by its username, according to "name_column".
name
my $name = $provider->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).
remaps
my $aref = $provider->remaps;
Accessor for the list of remaps, handled by MojoX::Authentication::Model::Role::Remap.
Make sure that the mapping contains a way to map the column containing the secret to check in correspondence of key secret, otherwise MojoX::Authentication::Model::Role::Local will fail to check secrets.
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 keys name (for the username/userid) and secret (for the secret). it <MAY> contain other key/value pairs, which will be copied.
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 accounts.
The names of the columns with interesting values are accessible through "id_column", "name_column" and "secret_column".
username_column
my $string = $provider->name_column;
Returns the name of the column where the username is kept. Defaults to name.
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).
ANYTHING ELSE (INCLUDING AUTHOR, COPYRIGHT AND LICENSE)
See documentation for MojoX::Authentication.