Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
RegistrationForm.php
1 <?php
2 /**
3  * RegistrationForm class.
4  * RegistrationForm is the data structure for keeping
5  * user registration form data. It is used by the 'registration' action of 'UserController'.
6  */
7 class RegistrationForm extends User
8 {
9  public $verifyPassword;
10  public $verifyCode;
11 
12  /**
13  * set verivication rules
14  *
15  * @return array
16  */
17  public function rules()
18  {
19  $rules = array(
20  array('username, email', 'common.components.NotContainsTagsValidator'),
21  array('password, verifyPassword, email', 'required'),
22  array('username', 'length', 'max' => 20, 'min' => Yii::app()->getModule('user')->usernameMin, 'message' => UserModule::t("Incorrect username (length between 3 and 20 characters).")),
23  array('password', 'length', 'max' => 128, 'min' => Yii::app()->getModule('user')->passwordMin, 'message' => UserModule::t("Incorrect password (minimal length 4 symbols).")),
24  array('email', 'email'),
25  array('email', 'unique', 'message' => UserModule::t("This user's email address already exists.")),
26  array('verifyPassword', 'compare', 'compareAttribute' => 'password', 'message' => UserModule::t("Retype Password is incorrect.")),
27  array('username', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u', 'message' => UserModule::t("Incorrect symbols (A-z0-9).")),
28  );
29  if (@$_POST['ajax'] !== 'registration-form') {
30  array_push($rules, array('verifyCode', 'captcha', 'allowEmpty' => !UserModule::doCaptcha('registration')));
31  }
32 
33  if (Yii::app()->getModule('user')->usernameUnique && Yii::app()->getModule('user')->usernameRequired) {
34  array_unshift($rules, array('username', 'unique', 'message' => UserModule::t("This user's name already exists.")));
35  }
36 
37  if (Yii::app()->getModule('user')->usernameRequired) {
38  array_unshift($rules, array('username', 'required'));
39  }
40 
41  return $rules;
42  }
43 }