46 lines
993 B
PHP
46 lines
993 B
PHP
<?php
|
|
|
|
/**
|
|
* LoginForm class.
|
|
* LoginForm is the data structure for keeping
|
|
* user login form data. It is used by the 'login' action of 'SiteController'.
|
|
*/
|
|
class RegisterForm extends CFormModel
|
|
{
|
|
public $username;
|
|
public $password;
|
|
public $email;
|
|
|
|
/**
|
|
* Declares the validation rules.
|
|
* The rules state that username and password are required,
|
|
* and password needs to be authenticated.
|
|
*/
|
|
public function rules()
|
|
{
|
|
return array(
|
|
array('username, password, email', 'required'),
|
|
array('email', 'email'),
|
|
array('username', 'unique'),
|
|
);
|
|
}
|
|
|
|
public function unique($attribute,$params)
|
|
{
|
|
|
|
if(!$this->hasErrors())
|
|
{
|
|
$count = user::model()->count('username=:username', array('username'=>$this->username));
|
|
if ($count != 0)
|
|
$this->addError('username','Username already exists');
|
|
|
|
$count = user::model()->count('email=:email', array('email'=>$this->email));
|
|
if ($count != 0)
|
|
$this->addError('email','Email already exists');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|