00001 <?php
00022 class ModelAuth implements AuthInterface
00023 {
00029 private $filename;
00035 private $server;
00041 private $username;
00047 private $password;
00051 private $compare_attributes = array();
00055 private $identity = array();
00062 public function __construct ($auth, $extra_args)
00063 {
00064 foreach (array('class') as $param) {
00065 if (isset($extra_args[$param])) {
00066 $this->$param = $extra_args[$param];
00067 } else {
00068 throw new AuthException("Debe especificar el parametro '$param' en los parámetros");
00069 }
00070 }
00071
00072 Load::models($extra_args['class']);
00073 unset($extra_args[0]);
00074 unset($extra_args['class']);
00075 $this->compare_attributes = $extra_args;
00076 }
00081 public function get_identity ()
00082 {
00083 return $this->identity;
00084 }
00090 public function authenticate ()
00091 {
00092 $where_condition = array();
00093 foreach ($this->compare_attributes as $field => $value) {
00094 $value = addslashes($value);
00095 $where_condition[] = "$field = '$value'";
00096 }
00097 $result = ActiveRecord::get($this->class)->count(join(" AND ", $where_condition));
00098 if ($result) {
00099 $model = ActiveRecord::get($this->class)->find_first(join(" AND ", $where_condition));
00100 $identity = array();
00101 foreach ($model->fields as $field) {
00105 if (! in_array($field, array('password' , 'clave' , 'contrasena' , 'passwd' , 'pass'))) {
00106 $identity[$field] = $model->$field;
00107 }
00108 }
00109 $this->identity = $identity;
00110 }
00111 return $result;
00112 }
00118 public function set_params ($extra_args)
00119 {
00120 foreach (array('server' , 'secret' , 'principal' , 'password' , 'port' , 'max_retries') as $param) {
00121 if (isset($extra_args[$param])) {
00122 $this->$param = $extra_args[$param];
00123 }
00124 }
00125 }
00126 }