Skip to content

Commit c68b908

Browse files
author
fuze
committed
Метод завершения регистрации
1 parent d89e710 commit c68b908

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
class actionAuthApiAuthConfirm extends cmsAction {
4+
5+
/**
6+
* Блокировка прямого вызова экшена
7+
* обязательное свойство
8+
* @var boolean
9+
*/
10+
public $lock_explicit_call = true;
11+
/**
12+
* Результат запроса
13+
* обязательное свойство
14+
* @var array
15+
*/
16+
public $result;
17+
/**
18+
* Флаг, обязующий проверять параметр sig запроса
19+
* sig привязан к домену сайта и к ip адресу посетителя
20+
* @var boolean
21+
*/
22+
public $check_sig = true;
23+
24+
/**
25+
* Возможные параметры запроса
26+
* с правилами валидации
27+
* Если запрос имеет параметры, необходимо описать их здесь
28+
* Правила валидации параметров задаются по аналогии с полями форм
29+
* @var array
30+
*/
31+
public $request_params = array(
32+
'code' => array(
33+
'rules' => array(
34+
array('required'),
35+
array('regexp', '/^[0-9a-f]{32}$/i')
36+
)
37+
),
38+
'user_id' => array(
39+
'default' => 0,
40+
'rules' => array(
41+
array('required'),
42+
array('digits')
43+
)
44+
)
45+
);
46+
47+
private $users_model, $user;
48+
49+
public function validateApiRequest() {
50+
51+
if (empty($this->options['is_reg_enabled'])){
52+
return array('error_code' => 323);
53+
}
54+
55+
if (!$this->isIPAllowed(cmsUser::get('ip'))){
56+
57+
return array(
58+
'error_code' => 15,
59+
'error_msg' => strip_tags(sprintf(LANG_AUTH_RESTRICTED_IP, cmsUser::get('ip')))
60+
);
61+
62+
}
63+
64+
$this->users_model = cmsCore::getModel('users');
65+
66+
$this->user = $this->users_model->getUserByPassToken($this->request->get('code'));
67+
if (!$this->user || $this->user['id'] != $this->request->get('user_id')) {
68+
return array('error_code' => 1110);
69+
}
70+
71+
return false;
72+
73+
}
74+
75+
public function run(){
76+
77+
$this->users_model->unlockUser($this->user['id']);
78+
$this->users_model->clearUserPassToken($this->user['id']);
79+
80+
cmsEventsManager::hook('user_registered', $this->user);
81+
82+
$this->result = array(
83+
'success' => true,
84+
'success_text' => LANG_REG_SUCCESS_VERIFIED
85+
);
86+
87+
}
88+
89+
}

package/system/languages/en/controllers/api/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
define('LANG_API_ERROR321', 'Item is not published');
3434
define('LANG_API_ERROR322', 'Content type not found');
3535
define('LANG_API_ERROR323', 'Register is forbidden');
36+
define('LANG_API_ERROR1110', 'Incorrect code');

package/system/languages/ru/controllers/api/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
define('LANG_API_ERROR321', 'Запись не опубликована');
3434
define('LANG_API_ERROR322', 'Тип контента не найден');
3535
define('LANG_API_ERROR323', 'Регистрация запрещена');
36+
define('LANG_API_ERROR1110', 'Неправильный код');

0 commit comments

Comments
 (0)