package Dojo::Model::Users;


use strict;
use warnings;
use DBI;
use Mojo::Util 'secure_compare';
use Dojo::Conf;


sub new { bless {}, shift }

sub check {
  my ($self, $user, $pass) = @_;
  my $q="select permiso_id as pid from usuario where nombre = ? and pass=? ";
# |  0 | bloqueado |
# |  1 | invitado  |
# |  2 | usuario   |
# |  3 | pago      |
# |  4 | master    |
  my $r= _read($q,$user,$pass)->[0];
  return $r->{pid} // 0;
}

sub _read{
  my ($q,@bind)=@_;
  my (@empty,$arr);
  my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::GRULLADB.":".Dojo::Conf::GRULLADB_H,Dojo::Conf::GRULLADB_UR,Dojo::Conf::GRULLADB_URP);
  return \@empty unless($dbh);
  #$dbh->do(qq{SET NAMES 'utf8'}); 
  my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind);
  #((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
  $dbh->disconnect();
  return $h; 
}



1;
