Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class RegisterForm extends Model{
- public $login;
- public $password;
- public $password_repeat;
- public $email;
- public $captcha ;
- public function rules(){
- return [
- [['login','email','password','password_repeat','captcha'],'required'],
- ['password','string','length'=>[5,40]],
- ['password_repeat','compare','compareAttribute'=>'password','message'=>"Passwords must be the same"],
- ['login','string','length' => [4,25]],
- ['login','unique','targetClass' => 'app\models\activeRecord\Users','targetAttribute' => 'username'],
- [['captcha'],'captcha', 'captchaAction' => 'site/captcha', 'caseSensitive' => false],
- ['email','unique','targetClass' => 'app\models\activeRecord\Users','targetAttribute' => 'email'],
- ['email','email']
- ];
- }
- public function register()
- {
- $password_hash = new Security();
- $user = new Users();
- $user->email = $this->email;
- $user->username = $this->login;
- //HASHING PASSWORD WITH SALT
- $user->password = $password_hash->generatePasswordHash($this->password);
- $user->save();
- return $user;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement