NAME

Mojolicious::Plugin::ContextAuth::DB::User - User object for the ContextAuth database

VERSION

version 0.01

SYNOPSIS

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

my $user = Mojolicious::Plugin::ContextAuth::DB::User->new(
    dbh => $db->dbh,
);

my $new_user = $user->add(
    username      => 'test',
    user_password => 'hallo', 
);

my $updated_user = $new_user->update(
    username      => 'ernie',
    user_password => 'bert',
);

# create user object with data for user id 1
my $found_user = $user->load( 1 );

# delete user
$new_user->delete;

# check if user is allowed to update the title of the project in "Project X"
my $can_update = $found_user->has_permission(
    context_id => 123,
    permission_id => 33,
);

# check if user has role Y in "Project X"
my $has_role = $found_user->has_role(
    context_id => 123,
    role_id    => 15,
);

ATTRIBUTES

  • dbh

  • username

  • user_password

  • user_id

  • error

METHODS

load

# create user object with data for user id 1
my $found_user = $user->load( 1 );

has_permission

# check if user is allowed to update the title of the project in "Project X"
my $can_update = $found_user->has_permission(
    context_id => 123,
    permission_id => 33,
);

has_role

# check if user has role Y in "Project X"
my $has_role = $found_user->has_role(
    context_id => 123,
    role_id    => 15,
);

add

my $new_user = $user->add(
    username      => 'test',
    user_password => 'hallo', 
);

update

my $updated_user = $new_user->update(
    username      => 'ernie',
    user_password => 'bert',
);

delete

$user->delete;

add_session

# add new session for the user
my $success = $found_user->add_session(
    $session_id
);

set_context_roles

# set roles the user has in the given context
my $success = $found_user->set_context_roles(
    context_id => 123,
    roles      => [    # list of role_ids
        15,
        22,
        33,
    ],
);

context_roles

my @roles = $user->context_roles(
    context_id => 123,
);

Returns a list of role ids.

contexts

my @context_ids = $user->context_roles();

Returns a list of context ids.

has_permission

my $has_permission = $user->has_permission(
    context_id => 123,
    role_id    => 456, # or role => 'role_name'
);

has_role

my @roles = $user->has_role(
    context_id => 123,
    role_id    => 456, # or role => 'role_name'
);

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)