23 lines
858 B
PHP
23 lines
858 B
PHP
<?php defined('SYSPATH') or die('No direct script access.');
|
|
|
|
class Controller_Register extends Controller_Template {
|
|
public $template = 'register';
|
|
public function action_view() {
|
|
if(Auth::instance()->logged_in()) return $this->request->redirect('');
|
|
if ($_POST){
|
|
$data = arr::extract($_POST, array('username', 'password', 'email', 'password_confirm'));
|
|
$user = ORM::factory('user')->values($data);
|
|
if ($user->check()){
|
|
$user->create();
|
|
$login_role = new Model_Role(array('name' =>'login'));
|
|
$author_role = new Model_Role(array('name' =>'author'));
|
|
$user->add('roles',$login_role);
|
|
$user->add('roles',$author_role);
|
|
Auth::instance()->login($data['login'], $data['password']);
|
|
$this->request->redirect('');
|
|
}
|
|
else $this->template->error = $post->errors('register');//"Ошибка валидации.";
|
|
}
|
|
}
|
|
}
|