Newer
Older
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_Sign extends Controller_Handler {
$this->setAccessLevel(self::ACCESS_GUEST);
parent::before();
Andrew Rudenets
committed
$this->post->rule('login', 'email')->rule('login', 'not_empty');
$checklogin = true; $response['success'] = false;
if(!$this->post->check())
Andrew Rudenets
committed
$this->post = Validation::factory($this->post->as_array());
$this->post->rule('login', 'alpha_dash')->rule('login', 'not_empty');
if(!$this->post->check())
{
// Данные не безопасны, даже не пытаемся авторизоваться
$checklogin = false;
}
Andrew Rudenets
committed
if($checklogin)
Andrew Rudenets
committed
$response['success'] = User::instance()
Andrew Rudenets
committed
->signIn($this->post->offsetGet('login'),
$this->post->offsetGet('password'));
Andrew Rudenets
committed
$this->response->body(json_encode($response));
Andrew Rudenets
committed
$config = Kohana::$config->load('security.securityPolicy');
Andrew Rudenets
committed
$this->post->rule('activation_code', 'alpha_numeric')
->rule('login', $config['login']['allowedSymbols'])
->rule('password', 'min_length', array(':value', $config['password']['length']))
->rule('confirm_password', 'matches', array(':validation', 'confirm_password', 'password'))
->rule('email', 'not_empty')
->rule('confirm_email', 'matches', array(':validation', 'confirm_email', 'email'));
Andrew Rudenets
committed
if($this->post->check())
Andrew Rudenets
committed
list($response['success'], $attempt) = User::instance()
Andrew Rudenets
committed
->signUp($this->post->offsetGet('activation_code'),
$this->post->offsetGet('email'),
$this->post->offsetGet('login'),
$this->post->offsetGet('password'));
if(!$response['success'])
Andrew Rudenets
committed
switch ($attempt)
Andrew Rudenets
committed
case 'login_exists':
$this->post->error('login', 'already_exists');
break;
case 'mail_exists':
$this->post->error('email', 'already_exists');
break;
case 'invalid_code':
$this->post->error('activation_code', 'invalid_code');
break;
Andrew Rudenets
committed
{
$response['errors'] = $this->post->errors ('signin');
}
$this->response->body(json_encode($response));
}
public function action_remindpass()
{
}
}