KumbiaPHP beta2-dev
Framework PHP en español
|
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 KumbiaException("Debe especificar el parámetro '$param' en los parámetros"); 00069 } 00070 } 00071 unset($extra_args[0]); 00072 unset($extra_args['class']); 00073 $this->compare_attributes = $extra_args; 00074 } 00079 public function get_identity () 00080 { 00081 return $this->identity; 00082 } 00088 public function authenticate () 00089 { 00090 $where_condition = array(); 00091 foreach ($this->compare_attributes as $field => $value) { 00092 $value = addslashes($value); 00093 $where_condition[] = "$field = '$value'"; 00094 } 00095 $result = Load::model($this->class)->count(join(" AND ", $where_condition)); 00096 if ($result) { 00097 $model = ActiveRecord::get($this->class)->find_first(join(" AND ", $where_condition)); 00098 $identity = array(); 00099 foreach ($model->fields as $field) { 00103 if (! in_array($field, array('password' , 'clave' , 'contrasena' , 'passwd' , 'pass'))) { 00104 $identity[$field] = $model->$field; 00105 } 00106 } 00107 $this->identity = $identity; 00108 } 00109 return $result; 00110 } 00116 public function set_params ($extra_args) 00117 { 00118 foreach (array('server' , 'secret' , 'principal' , 'password' , 'port' , 'max_retries') as $param) { 00119 if (isset($extra_args[$param])) { 00120 $this->$param = $extra_args[$param]; 00121 } 00122 } 00123 } 00124 }