NAME

Mojolicious::Plugin::ContextAuth::DB - Main class to do the database stuff

VERSION

version 0.01

SYNOPSIS

use Mojolicious::Plugin::ContextAuth::DB;

use Mojo::File qw(path);

my $file = path(__FILE__)->sibling($$ . '.db')->to_string;

my $db = Mojolicious::Plugin::ContextAuth::DB->new(
    dsn => 'sqlite:' . $file,
);

my $session_id = $db->login( 'user', 'password' );

# later

my $user = $db->user_from_session( $session_id );

ATTRIBUTES

  • dsn

  • error

  • dbh

  • token

  • session_expires

METHODS

login

my $session_id = $db->login( 'user', 'password' );

Returns the session id if user and password was correct.

user_from_session

my $user = $db->user_from_session( $session_id );

Returns a Mojolicious::Plugin::ContextAuth::DB::User object, if a user exists that is tied to the session id. It returns undef if no user was found.

add

my $user = $db->add(
    'user',
    user_id       => '1234',
    username      => 'username',
    user_password => '123',
);

warn $db->error if !$user;

This is a proxy for the add methods of the Mojolicious::Plugin::ContextAuth::DB::* modules.

get

my $user = $db->get(
    'user' => '1234',
);

warn $db->error if !$user;

This is a proxy for the load methods of the Mojolicious::Plugin::ContextAuth::DB::* modules.

update

my $updated_user = $db->update(
    'user'        => '1234',
    username      => 'username',
    user_password => '123',
);

warn $db->error if !$updated_user;

Returns the object that reflects the updated object. If the object could not be updated

This is a proxy for the update methods of the Mojolicious::Plugin::ContextAuth::DB::* modules.

delete

my $success = $db->delete(
    'user' => '1234',
);

warn $db->error if !$success;

It returns 1 on success, undef otherwise.

This is a proxy for the add methods of the Mojolicious::Plugin::ContextAuth::DB::* modules.

clear_sessions

$db->clear_sessions();

Removes all sessions from the corbac_user_sessions table that are expired.

object

my $obj = $db->object('user');

Returns an instance of the Mojolicious::Plugin::ContextAuth::DB::*

AUTHOR

Renee Baecker <reneeb@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2020 by Renee Baecker.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)