KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
model_auth.php
Ir a la documentación de este archivo.
1 <?php
27 class ModelAuth implements AuthInterface
28 {
29 
35  private $filename;
41  private $server;
47  private $username;
53  private $password;
57  private $compare_attributes = array();
61  private $identity = array();
62 
69  public function __construct($auth, $extra_args)
70  {
71  foreach (array('class') as $param) {
72  if (isset($extra_args[$param])) {
73  $this->$param = $extra_args[$param];
74  } else {
75  throw new KumbiaException("Debe especificar el parámetro '$param' en los parámetros");
76  }
77  }
78  unset($extra_args[0]);
79  unset($extra_args['class']);
80  $this->compare_attributes = $extra_args;
81  }
82 
87  public function get_identity()
88  {
89  return $this->identity;
90  }
91 
97  public function authenticate()
98  {
99  $where_condition = array();
100  foreach ($this->compare_attributes as $field => $value) {
101  $value = addslashes($value);
102  $where_condition[] = "$field = '$value'";
103  }
104  $result = Load::model($this->class)->count(join(" AND ", $where_condition));
105  if ($result) {
106  $model = KumbiaActiveRecord::get($this->class)->find_first(join(" AND ", $where_condition));
107  $identity = array();
108  foreach ($model->fields as $field) {
112  if (!in_array($field, array('password', 'clave', 'contrasena', 'passwd', 'pass'))) {
113  $identity[$field] = $model->$field;
114  }
115  }
116  $this->identity = $identity;
117  }
118  return $result;
119  }
120 
126  public function set_params($extra_args)
127  {
128  foreach (array('server', 'secret', 'principal', 'password', 'port', 'max_retries') as $param) {
129  if (isset($extra_args[$param])) {
130  $this->$param = $extra_args[$param];
131  }
132  }
133  }
134 
135 }