Skip to content

Instantly share code, notes, and snippets.

@edvaldoszy
Created January 28, 2016 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edvaldoszy/4efb8349e8d023c53022 to your computer and use it in GitHub Desktop.
Save edvaldoszy/4efb8349e8d023c53022 to your computer and use it in GitHub Desktop.
<?php
namespace Sys;
class Usuario
{
const ATIVO = 1;
const INVATIVO = 0;
/**
* @var Conexao
*/
private $con;
/**
* @param Conexao $con
*/
public function __construct($con) {
$this->con = $con;
}
/**
* @param string $login
* @param string $senha
* @return object
* @throws ValidacaoException
*/
public function validar($login, $senha) {
if (empty($login) || empty($senha))
throw new ValidacaoException('Preencha o login e senha');
$rs = $this->con->selecionar(
'SELECT * FROM usuarios WHERE login = ? AND senha = ? AND ativo = ? LIMIT 1',
array($login, $senha, self::ATIVO)
);
if (count($rs) < 1)
throw new ValidacaoException('Login ou senha inválida');
return $rs[0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment