package Dojo::Controller::Users;
use Mojo::Base 'Mojolicious::Controller';
use Dojo::Support qw{ merge_hash load_module };


sub login {
  my $c = shift;
  $c->stash((load_module("users/login"))[0]);
  my $user = $c->param('uname') // '';
  my $pass = $c->param('pass') //'';
  $c->stash(layout=>"defaultContact");
  return $c->render unless my $pmid = $c->dbg->check($user, $pass);
  $c->session(user => $user, pmid=>$pmid, nick=> $c->param('nick'));
  $c->redirect_to('radio');
}

sub is_logged {
  my $self = shift;
  return 1 if $self->session('user');
  $self->redirect_to('login');
}

sub logout {
  my $self = shift;
  $self->session(expires => 1);
  $self->redirect_to('home');
}

1;
