/**
* Register a new user.
*
* @access public
*/
public function action_signup()
{
if (isset($_POST) && Valid::not_empty($_POST))
{
// validate
$post = Validation::factory($_POST)
->rule('username', 'not_empty')
->rule('username', 'alpha_dash', array(':value', TRUE))
->rule('username', 'min_length', array(':value', 3))
->rule('username', 'max_length', array(':value', 40))
->rule('email', 'email')
->rule('email', 'email_domain') // НА ЛОКАЛХОСТЕ ЭТО ЛУЧШЕ ОТКЛЮЧИТЬ
->rule('password', 'not_empty')
->rule('password', 'min_length', array(':value', 3))
->rule('password', 'max_length', array(':value', 64))
->rule('password_confirm', 'matches', array(':validation', 'password_confirm', 'password'));
if ($post->check())
{
// save
$model = ORM::factory('user');
$model->values(array(
'username' => HTML::entities(strip_tags($post['username'])),
'email' => $post['email'],
'password' => $post['password'],
'password_confirm' => $post['password_confirm'],
));
try
{
$model->save();
// Grant user login role
$model->add('roles', ORM::factory('role', array('name' => 'login')));
$model->add('roles', ORM::factory('role', array('name' => 'client')));
// Reset values so form is not sticky
$_POST = array();
// success login
if ($this->_auth->login($post['username'], $post['password']))
{
if($this->_auth->logged_in('client'))
// Redirect to first login user page
$this->request->redirect(Route::get('user')->uri(array(
'controller'=>'user',
'action' => 'first_login',
'id' => $post['username']
)));
// Or as: $this->request->redirect('user');
}
else
{
// Error athorization
$this->template->styles['public/css/error.css'] = 'screen, projection';
// Set errors using custom messages
$this->errors[] = 'Ошибка автризации!';
}
}
catch (ORM_Validation_Exception $e)
{
$this->template->styles['public/css/error.css'] = 'screen, projection';
// Set errors using custom messages
$this->errors = $e->errors('models');
//echo Debug::vars($this->errors);
}
}
else
{
// TODO: Error
}
}
$view = 'sign/' . $this->request->action();
$content = View::factory($view)
->bind('errors', $this->errors);
$this->template->title = 'Регистрация';
$this->template->styles['public/css/signup.css'] = 'screen, projection';
$this->template->content = $content;
}
где нибудь а абстрактном классе, в before() определите.
/**
* Stores the Auth instanse.
*
* @var Auth
*/
protected $_auth;
/**
* The before() method is called before controller action.
* In our template controller we override this method so that we can
* set up default values. These variables are then available to our
* controllers if they need to be modified.
*
* @access public
*/
public function before()
{
$this->_auth = Auth::instance();
parent::before();
}
Потом к текущему пользователю можно обращаться как угодно.
$this->_auth->get_user()->username
$this->_auth->get_user()->id
Или как угодно.
echo Debug::vars($this->_auth->get_user());