Newer
Older
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_Sign extends Controller_Handler
{
public function before() {
parent::before();
}
public function action_in() {
$ok = User::instance()->signIn($_POST['login'], $_POST['password']);
if (!$ok) $this->fail();
}
public function action_up() {
$config = Kohana::$config->load('security.securityPolicy');
->rule('activation_code', 'alpha_numeric')
->rule('password', 'min_length', [':value', $config['password']['length']])
->rule('confirm_password', 'matches', [':validation', 'confirm_password', 'password'])
->rule('email', 'not_empty')
->rule('email', 'email');
if (!$this->post->check())
$this->fail($this->post->errors('signin'));
RomanSteinberg
committed
if ($err = User::instance()->signUp($_POST['activation_code'], $_POST['email'], $_POST['login'], $_POST['password']))
$this->fail(I18n::get($err));
}
public function action_remindPassword() {
$this->post->rule('email', 'not_empty')->rule('email', 'email');
if (!$this->post->check())
$this->fail('Введенная строка не является <span>e‑mail</span> адресом!');
if (!Account::doesEmailExist($_POST['email']))
$this->fail('Пользователь с таким <span>e-mail</span> адресом не зарегистрирован в системе!');
Account::createRecoveryRequest($_POST['email']);
public function action_changePassword() {
$res['success'] = false;
$config = Kohana::$config->load('security.securityPolicy');
$this->post->rule('token', 'alpha_numeric')
->rule('password', 'min_length', [':value', $config['password']['length']])
->rule('confirm_password', 'matches', [':validation', 'confirm_password', 'password']);
if ($this->post->check()) {
$token = $_POST['token'];
if (Account::checkToken($token)) {
Account::changePasswordByToken($token, $_POST['password']);
$res['success'] = true;
}
}
if (!$res['success']) {
$res['errors'] = $this->post->errors('signin');
}
$this->response->body(json_encode($res));
}
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
public function action_openidlogin()
{
$openid = new OpenID;
$openid->SetIdentity("https://openid.sfedu.ru/server.php/idpage?user=" . $_GET["loginopenid"]);
$openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]);
$openid->SetOptionalFields(['email', 'nickname', 'r61globalkey', 'staff', 'student']);
if ($openid->GetOpenIDServer()) {
$openid->SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . '/~dev_rating/handler/sign/openidfinish');
$openid->Redirect();
} else {
$error = $openid->GetError();
echo "ERROR CODE: " . $error['code'] . "<br>";
echo "ERROR DESCRIPTION: " . $error['description'] . "<br>";
}
}
public function action_openidfinish()
{
if ($_GET["openid_sreg_student"] !== '1') {
$this->fail('К сожалению, личный кабинет сотрудника пока что находится в разработке. Следите за новостями!');
}
if ($_GET['openid_mode'] == 'id_res') {
$openid = new OpenID;
$openid->SetIdentity($_GET['openid_identity']);
$openid_validation_result = $openid->ValidateWithServer();
if ($openid_validation_result == true) {
$this->openid_signIn();
} else if ($openid->IsError() == true) {
$error = $openid->GetError();
echo 'Ошибка!';
echo "[" . $error['code'] . "]: " . $error['description'];
} else {
echo 'Ошибка!';
echo "При авторизации что-то пошло не так. Попробуете снова?";
}
} else if ($_GET['openid_mode'] == 'cancel') {
echo 'Какая досада!';
echo "Вы досрочно прекратили процесс авторизации. Надеемся, что у Вас всё хорошо.";
}
}
private function openid_signIn()
{
$flags = [
'isStudent' => $_GET["openid_sreg_student"],
'isStaff' => $_GET["openid_sreg_staff"]
];
echo 'Добро пожаловать!';
// $this->redirect_url = Route::url('evaluation:student');
//
// Account::signIn($_GET["openid_sig"], $_GET["openid_sreg_r61globalkey"], $flags);
}