<?php

class UserIdentity extends CUserIdentity
{
	private $_id;
	public function authenticate()
	{
		$user = Funcionario::model()->findByAttributes(array('fun_login'=>$this->username));
		$pefil = FuncionarioPerfil::model()->findByAttributes(array('fun_rut'=>$user->fun_rut));
		$rol = Perfil::model()->findByAttributes(array('prf_codigo'=>$pefil->prf_codigo));
       // $connection = ldap_connect('172.18.1.7');
		
		if($user===null)
			$this->errorCode=self::ERROR_USERNAME_INVALID;
		elseif($this->password!==$user->fun_clave)
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
		else
		{			
			$this->_id=$user->fun_rut;
			$this->setState('nombre', $user->fun_nombre.' '.$user->fun_ap_paterno);
			$this->setState('foto', $user->fun_foto);
			$this->setState('rol', $rol->prf_descripcion);
			$this->errorCode=self::ERROR_NONE;
			
		}
		return !$this->errorCode;
	}
	public function getId()
    {
        return $this->_id;
    }
}

