LasTres/lib/LasTres.pm

49 lines
1.3 KiB
Perl

package LasTres;
use Mojo::Base 'Mojolicious', -signatures;
# This method will run once at server start
sub startup ($self) {
# Load configuration from config file
my $config = $self->plugin('NotYAMLConfig');
# Configure the application
$self->secrets( $config->{secrets} );
# Router
my $r = $self->routes;
$self->helper(user => sub($self) {
require LasTres::DAO::Players;
my $result_set_players = LasTres::DAO::Players->ResultSet;
my $uuid = $self->session->{uuid};
if (!defined $uuid) {
return;
}
my @players = $result_set_players->search({
uuid => $uuid,
});
my $player = $players[0];
if (!defined $player) {
delete $self->session->{uuid};
return;
}
return $player;
});
my $sessions = Mojolicious::Sessions->new;
$sessions->cookie_name('LasTres');
$sessions->default_expiration(86400);
# Normal route to controller
$r->get('/')->to('Root#index');
$r->post('/player/register')->to('Player#register');
$r->post('/player/login')->to('Player#login');
$r->post('/player/check_login')->to('Player#check_login');
$r->post('/pj/create')->to('PJ#create');;
$r->websocket('/ws')->to('Websocket#ws');
}
1;