<?php
/**
 * Description of LoginRepository
 *
 * @author carlos
 */
class LoginRepository extends DataBase {
    public function isLoginCorrect($user,$password){
        $select = "SELECT * FROM users WHERE usuario = '$user' AND contrasena = MD5('$password') LIMIT 1";
        $result = $this->getInstance()->execute($select);
        
        if($result->num_rows > 0){
           $result = $result->fetch_assoc();
           
           if($result['status']=='2'){
               $flashmessenger = new FlashMessenger();
               $flashmessenger->addMessage(array('danger'=>'Usuario inactivo para ingreso a sistema.'));
               return null;
           }           
                      
           if($result['status']=='3'){
               $flashmessenger = new FlashMessenger();
               $flashmessenger->addMessage(array('danger'=>'Servicio suspendido. Favor de comunicarse al area de pagos.'));
               return null;
           }
           
           return $result;
        }else{
            $flashmessenger = new FlashMessenger();
            $flashmessenger->addMessage(array('danger'=>'Usuario o contraseña incorrecta.'));
            return null;
        }
    }
}
