<?php

/**
 * FormularioRegistroUsuario class.
 * FormularioRegistroUsuario is the data structure for keeping
 * user registration form data. It is used by the 'registration' action of 'UsuarioController'.
 */
class FormularioRegistroUsuario extends Usuario {

    public $confirmacion_password;
    public $codigo_verificacion;

    public function rules() {
        $rules = array(
            array('username, password, confirmacion_password, email', 'required'),
            array('username', 'length', 'max' => 20, 'min' => 3, 'message' => UsuarioModule::t("Incorrect username (length between 3 and 20 characters).")),
            array('password', 'length', 'max' => 128, 'min' => 4, 'message' => UsuarioModule::t("Incorrect password (minimal length 4 symbols).")),
            array('email', 'email'),
            array('username', 'unique', 'message' => UsuarioModule::t("This user's name already exists.")),
            array('email', 'unique', 'message' => UsuarioModule::t("This user's email address already exists.")),
            array('username', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u', 'message' => UsuarioModule::t("Incorrect symbols (A-z0-9).")),
        );
        if (!(isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form')) {
            array_push($rules, array('codigo_verificacion', 'captcha', 'allowEmpty' => !UsuarioModule::doCaptcha('registration')));
        }

        array_push($rules, array('confirmacion_password', 'compare', 'compareAttribute' => 'password', 'message' => UsuarioModule::t("Retype Password is incorrect.")));
        return $rules;
    }
}
