How to create a user with a password confirmation using the create_user () function - where you need to transfer the contents of the 'password_confirm' form field:

ORM::factory('user') ->create_user($_POST, array('username', 'email','password','confirm' )) ->add('roles', ORM::factory('role', array('name' => 'login'))); 

and in general - how to use this function - can it be redefined?

    1 answer 1

    Controller

     public function action_register() { if (!empty($_POST)){ $data = Arr::extract($_POST, array('username', 'password', 'password_confirm', 'email')); if(Captcha::valid($_POST['captcha']) == true) { $validation = Validation::factory($_POST); $validation -> rule('email', 'email'); if($validation->check()) { $users = ORM::factory('user'); try { $users->create_user($_POST, array( 'username', 'password', 'email', )); $role = ORM::factory('role')->where('name', '=', 'login')->find(); $users->add('roles', $role); $this->action_login(); $this->request->redirect(URL::site('/auth/successfully')); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('auth'); } } else { $errors = $validation->errors('validation'); } } else { $errors = array(Kohana::message('captcha/err', 'error_1')); } } $captcha = Captcha::instance('default'); $content = View::factory('index/auth/v_auth_register') ->bind('captcha', $captcha) ->bind('errors', $errors) ->bind('data', $data); // Выводим в шаблон $this->template->page_title = 'Регистрация'; $this->template->block_center = array($content); } 

    Model

    <? php defined ('SYSPATH') or die ('No direct script access.');

     class Model_User extends Model_Auth_User { public function labels() { return array( 'username' => 'Логин', 'email' => 'E-mail', 'password' => 'Пароль', 'password_confirm' => 'Повторить пароль', ); } public function rules() { return array( 'username' => array( array('not_empty'), array('min_length', array(':value', 4)), array('max_length', array(':value', 32)), array(array($this, 'unique'), array('username', ':value')), ), 'password' => array( array('not_empty'), ), 'email' => array( array('not_empty'), array('min_length', array(':value', 6)), array('max_length', array(':value', 127)), array('email'), array(array($this, 'unique'), array('email', ':value')), ), ); } 

    }

    • one
      Validation of email is not through the module Auth. There is a bug in the module. Therefore, I use standard validation - Demyan112rv