Beispiel #1
0
 /**
  * Validación de datos de usuario.
  *
  * @param type array $errors               Errores devueltos pasados por referencia.
  * @param type array	$skip_validations  Crea el usuario aunque estos campos no sean correctos
  *                                         password, active
  * @return bool true|false
  */
 public function validate(&$errors = array(), $skip_validations = array())
 {
     // Nuevo usuario.
     if (empty($this->id)) {
         // Nombre de usuario (id)
         if (empty($this->userid)) {
             $errors['userid'] = Text::get('error-register-userid');
         } else {
             $id = self::idealiza($this->userid);
             $query = self::query('SELECT id FROM user WHERE id = ?', array($id));
             if ($query->fetchColumn()) {
                 $errors['userid'] = Text::get('error-register-user-exists');
             }
         }
         if (empty($this->name)) {
             $errors['username'] = Text::get('error-register-username');
         }
         // E-mail
         if (empty($this->email)) {
             $errors['email'] = Text::get('mandatory-register-field-email');
         } elseif (!Check::mail($this->email)) {
             $errors['email'] = Text::get('validate-register-value-email');
         } else {
             $query = self::query('SELECT email FROM user WHERE email = ?', array($this->email));
             if ($query->fetchObject()) {
                 $errors['email'] = Text::get('error-register-email-exists');
             }
         }
         // Contraseña
         if (!in_array('password', $skip_validations)) {
             if (!empty($this->password)) {
                 if (!Check::password($this->password)) {
                     $errors['password'] = Text::get('error-register-invalid-password');
                 }
             } else {
                 $errors['password'] = Text::get('error-register-pasword-empty');
             }
         }
         if (!empty($this->userid)) {
             if (!Check::userid($this->userid)) {
                 $errors['userid'] = Text::get('error-user-userid-invalid');
             }
         }
         return empty($errors);
     } else {
         if (!empty($this->email)) {
             if (count($tmp = explode('¬', $this->email)) > 1) {
                 if ($this->email !== $this->token) {
                     $errors['email'] = Text::get('error-user-email-token-invalid');
                 }
             } elseif (!Check::mail($this->email)) {
                 $errors['email'] = Text::get('error-user-email-invalid');
             } else {
                 $query = self::query('SELECT id FROM user WHERE email = ?', array($this->email));
                 if ($found = $query->fetchColumn()) {
                     if ($this->id !== $found) {
                         $errors['email'] = Text::get('error-user-email-exists');
                     }
                 }
             }
         }
         if (!empty($this->password)) {
             if (!Check::password($this->password)) {
                 $errors['password'] = Text::get('error-user-password-invalid');
             }
         }
         if (isset($this->name) && empty($this->name)) {
             $errors['username'] = Text::get('error-register-username');
         }
     }
     if (\str_replace(Text::get('regular-facebook-url'), '', $this->facebook) == '') {
         $this->facebook = '';
     }
     if (\str_replace(Text::get('regular-google-url'), '', $this->google) == '') {
         $this->google = '';
     }
     if (\str_replace(Text::get('regular-twitter-url'), '', $this->twitter) == '') {
         $this->twitter = '';
     }
     if (\str_replace(Text::get('regular-identica-url'), '', $this->identica) == '') {
         $this->identica = '';
     }
     if (\str_replace(Text::get('regular-linkedin-url'), '', $this->linkedin) == '') {
         $this->linkedin = '';
     }
     return empty($errors['email']) && empty($errors['password']);
 }