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