ModelsAuth.php 1.71 KB
<?php

class ModelsAuth {

    private $dados;
    private $result;
    private $msg;
    private $rowCount;

    const ENTITY = "users";

    public function autenticar(array $dados) {
        $this->dados = $dados;
        $this->validar();
        if ($this->result){
            $visulizar = new ModelsRead();
            $visulizar->exeRead(self::ENTITY, 'WHERE email =:email AND password =:password LIMIT :limit',
                "email={$this->dados['email']}&password={$this->dados['password']}&limit=1");
            if ($visulizar->getRowCount() == 1) {
                //var_dump($Visulizar->getResultado());
                $this->result = $visulizar->getResult();
            }else {
                $this->result = false;
                $this->msg = "
                        <div class='alert alert-danger' role='alert'>
                          Login e/ou senhas incorretos!
                        </div>
                        ";
            }
        }
    }

    public function validar()
    {
        $this->dados = array_map('strip_tags', $this->dados);
        $this->dados = array_map('trim', $this->dados);
        if (in_array('', $this->dados)){
            $this->result = false;
            $this->msg = "
                        <div class='alert alert-danger' role='alert'>
                          Login e/ou senhas incorretos!
                        </div>
                        ";
        }else{
            $this->dados['password'] = md5($this->dados['password']);
            $this->result = true;
        }
    }

    function getResult() {
        return $this->result;
    }

    function getMsg() {
        return $this->msg;
    }

    function getRowCount() {
        return $this->rowCount;
    }

}