Newer
Older
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_Sign extends Controller_Handler {
parent::before();
Andrew Rudenets
committed
$this->post->rule('login', 'email')->rule('login', 'not_empty');
$checkLogin = true;
$response['success'] = false;
Andrew Rudenets
committed
if(!$this->post->check())
$this->post = Validation::factory($this->post->data());
Andrew Rudenets
committed
$this->post->rule('login', 'alpha_dash')->rule('login', 'not_empty');
if(!$this->post->check())
{
// Data is not safe, don't even try to authorize
Andrew Rudenets
committed
}
Andrew Rudenets
committed
$response['success'] = User::instance()
->signIn($this->post['login'],
$this->post['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('email', 'email');
Andrew Rudenets
committed
if($this->post->check())
Andrew Rudenets
committed
list($response['success'], $attempt) = User::instance()
->signUp($this->post['activation_code'],
$this->post['email'],
$this->post['login'],
$this->post['password']);
Andrew Rudenets
committed
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_remindPassword()
{
$response['success'] = false;
$this->post->rule('email', 'not_empty')->rule('email', 'email');
Account::createRecoveryRequest($this->post['email']);
RomanSteinberg
committed
$response['success'] = true;
RomanSteinberg
committed
else
$response['error'] = 'Пользователь с таким e-mail адресом не зарегистрирован в системе!';
RomanSteinberg
committed
else
$response['error'] = 'Введенная строка не является e-mail адресом!';
$this->response->body(json_encode($response));
}
public function action_changePassword()
$config = Kohana::$config->load('security.securityPolicy');
$response['success'] = false;
$this->post->rule('token', 'alpha_numeric')
->rule('password', 'min_length', array(':value', $config['password']['length']))
->rule('confirm_password', 'matches', array(':validation', 'confirm_password', 'password'));
if($this->post->check())
{
Account::changePasswordByToken($token, $this->post['password']);
$response['success'] = true;
}
}
if(!$response['success'])
{
$response['errors'] = $this->post->errors ('signin');
}
$this->response->body(json_encode($response));