Problema com Autenticação em PRADO
Autor: Leandro Peçanha Scardua | Publicado: 2012-11-09T23:22:00-02:00

Hoje resolvi um problema que já vinha me ocupando durante dois dias! Estou desenvolvendo uma aplicação usando o framework Prado, em php, que se inspira no modelo de eventos do asp .net da microsoft.
O problema que eu tinha era o seguinte:
configurei dois modulos no arquivo aplication.xml
----------------
&lt;module class="System.Security.TAuthManager" id="auth" loginpage="Home" usermanager="users" /&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;module class="System.Security.TDbUserManager" connectionid="db" id="users" userclass="UsuarioDAO"/&gt;

---------------- 

e criei uma classe para fazer a autenticação :
----------------
class UsuarioDAO extends TDbUser&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function validateUser($login, $senha)&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return Usuario::finder()-&gt;findBy_login_AND_senha($login,$senha) !== null;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function createUser($login) {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return new Usuario();
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
-----------------

e uma classe Usuario que apenas recuperava os dados do banco de dados. Igual ao exemplo de Blog que o site do framework fornece. O problemas que eu tinha era o seguinte: o código de autenticação sempre retornava false, mesmo quando o método validateUser retornava true!
-------------------
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $authManager = $this-&gt;Application-&gt;getModule('auth');

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(!$authManager-&gt;login($this-&gt;txtUsuario-&gt;Text, $this-&gt;txtSenha-&gt;Text)) {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $param-&gt;IsValid = false;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
-------------------
Após muito pesquisar, principalmente no fórum do site, descobri que a classe Usuario, que fazia apenas a recuperação do banco de dados, deveria implementar a interface IUser. Assim o codigo que era:
----------------
class Usuario extends TActiveRecord&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; const TABLE = 'tbl_usuario';
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public $id;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public $login;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public $senha;

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public static function finder($className = __CLASS__)&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return parent::finder($className);
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
---------------
passou a ser:
---------------
class Usuario extends TActiveRecord implements IUser&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; const TABLE = 'tbl_usuario';
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public $id;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public $login;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public $senha;

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public static function finder($className = __CLASS__)&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return parent::finder($className);
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function getIsGuest(){}
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function getName() {}
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function setName($value) {}
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function getRoles() {}
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function isInRole($role) {}
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function loadFromString($string) {}
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function saveToString(){}
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function setIsGuest($value) {}
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public function setRoles( $value) {}
&nbsp;&nbsp;&nbsp; }
------------------
E a validação funcionou como deveria funcionar! Sem precisar reimplementar nenhuma classe (TDbUserManager), como foi a melhor solução que encontrei.