Skip to content

Commit

Permalink
Add ability to allow automatic self-created guest logins
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemhall committed Sep 26, 2023
1 parent 87a6c79 commit ed904de
Show file tree
Hide file tree
Showing 11 changed files with 485 additions and 223 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
docker exec -t libki-test-server prove /app/t/stdout.t
docker exec -t -e TEST_POD=1 libki-test-server prove /app/t/02pod.t
docker exec -t -e TEST_POD=1 libki-test-server prove /app/t/03podcoverage.t
docker exec -t prove t/controller_API-Client-v1_0.t
publish-docker-io-debian:
name: Push Debian image (docker.io)
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.9.0]
### Added
- Add passwordless mode support to Print Manager authentication api

## [4.7.9]
### Added
- Add passwordless mode support to Print Manager authentication api
Expand Down
2 changes: 1 addition & 1 deletion lib/Libki.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use DateTime::Format::MySQL;
use DateTime;
use File::Slurp;

our $VERSION = '4.7.9';
our $VERSION = '4.9.0';

# Set flags and add plugins for the application.
#
Expand Down
88 changes: 59 additions & 29 deletions lib/Libki/Controller/API/Client/v1_0.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Libki::SIP qw( authenticate_via_sip );
use Libki::LDAP qw( authenticate_via_ldap );
use Libki::Hours qw( minutes_until_closing );
use Libki::Utils::Printing qw( create_print_job_and_file );
use Libki::Utils::User qw( create_guest );

use DateTime::Format::MySQL;
use DateTime;
Expand Down Expand Up @@ -84,18 +85,19 @@ sub index : Path : Args(0) {
}

$client->get_from_storage;
my $client_status = $client->status // q{};

if ($client->status eq "unlock") {
if ($client_status eq "unlock") {
$c->stash(
unlock => 1,
minutes => $client->session->minutes,
username => $client->session->user->username,
);
} elsif ($client->status eq "shutdown" || $client->status eq "suspend" || $client->status eq "restart") {
} elsif ($client_status eq "shutdown" || $client_status eq "suspend" || $client_status eq "restart") {
$c->stash(
$client->status => 1,
$client_status => 1,
);
} elsif ($client->status eq "wakeup") {
} elsif ($client_status eq "wakeup") {
my $host = $c->setting('WOLHost') || '255.255.255.255';
my $port = $c->setting('WOLPort') || 9;
my @mac_addresses = split(/[\r\n]+/, $c->setting('ClientMACAddresses'));
Expand Down Expand Up @@ -139,6 +141,8 @@ sub index : Path : Args(0) {
ClientBehavior => $c->stash->{Settings}->{ClientBehavior},
ReservationShowUsername => $c->stash->{Settings}->{ReservationShowUsername},

EnableGuestSelfRegistration => $c->stash->{Settings}->{EnableGuestSelfRegistration},

EnableClientSessionLocking => $c->stash->{Settings}->{EnableClientSessionLocking},
EnableClientPasswordlessMode => $c->stash->{Settings}->{EnableClientPasswordlessMode},

Expand Down Expand Up @@ -199,10 +203,32 @@ sub index : Path : Args(0) {
my $client_type = $c->request->params->{'type'};

my $units;
my $user = $c->model('DB::User')
->single( { instance => $instance, username => $username } );
my $user
= $username
? $c->model('DB::User')->single( { instance => $instance, username => $username } )
: undef;

if ( $action eq 'login' ) {
my $create_guest = $c->request->params->{'createGuest'};
if ($create_guest) {
if ( $c->setting('EnableGuestSelfRegistration') ) {
( $user, $password ) = Libki::Utils::User::create_guest($c);
$username = $user->username;

$c->stash(
username => $username,
password => $password,
);
}
else {
delete( $c->stash->{Settings} );
$c->stash( authenticated => 0, error => "GUEST_SELF_REG_NOT_ENABLED" );
$c->res->status(501);
$c->forward( $c->view('JSON') );
return;
}
}

$log->debug( __PACKAGE__
. " - username: $username, client_name: $client_name" );

Expand Down Expand Up @@ -488,31 +514,35 @@ sub index : Path : Args(0) {
}
elsif ( $action eq 'logout' ) {
my $session = $user->session;
my $session_id = $session->session_id;
my $location = $session->client->location;
my $type = $session->client->type;

my $success = $user->session->delete();
$success &&= 1;
$c->stash( logged_out => $success );
if ($session) {
my $session_id = $session->session_id;
my $location = $session->client->location;
my $type = $session->client->type;

$c->model('DB::Statistic')->create(
{
instance => $instance,
username => $username,
client_name => $client_name,
client_location => $client_location,
client_type => $client_type,
action => 'LOGOUT',
created_on => $now,
session_id => $session_id,
info => to_json(
{
client_version => $version
}
),
}
);
my $success = $session->delete() ? 1 : 0;
$c->stash( logged_out => $success );

$c->model('DB::Statistic')->create(
{
instance => $instance,
username => $username,
client_name => $client_name,
client_location => $client_location,
client_type => $client_type,
action => 'LOGOUT',
created_on => $now,
session_id => $session_id,
info => to_json(
{
client_version => $version
}
),
}
);
} else {
$c->stash( logged_out => 0 );
}
}
}

Expand Down
Loading

0 comments on commit ed904de

Please sign in to comment.