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')), ), ); }
}