1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Users app controller |
6
|
|
|
* |
7
|
|
|
* @author Alexey Krupskiy <[email protected]> |
8
|
|
|
* @link http://inji.ru/ |
9
|
|
|
* @copyright 2015 Alexey Krupskiy |
10
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Inji\Users; |
14
|
|
|
|
15
|
|
|
use Inji\App; |
16
|
|
|
use Inji\Controller; |
17
|
|
|
use Inji\I18n\Text; |
18
|
|
|
use Inji\Msg; |
19
|
|
|
use Inji\Server\Result; |
20
|
|
|
use Inji\Tools; |
21
|
|
|
use Inji\View\Page; |
22
|
|
|
|
23
|
|
|
class UsersAppController extends Controller { |
24
|
|
|
|
25
|
|
|
public function indexAction() { |
26
|
|
|
Tools::redirect('/users/cabinet/profile'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function cabinetAction($activeSection = '') { |
30
|
|
|
$bread = []; |
31
|
|
|
|
32
|
|
|
$sections = $this->module->getSnippets('cabinetSection'); |
33
|
|
|
if (!empty($sections[$activeSection]['name'])) { |
34
|
|
|
$this->view->setTitle($sections[$activeSection]['name'] . ' - ' . Text::module('Users', 'Личный кабинет')); |
|
|
|
|
35
|
|
|
$bread[] = ['text' => 'Личный кабинет', 'href' => '/users/cabinet']; |
36
|
|
|
$bread[] = ['text' => $sections[$activeSection]['name']]; |
37
|
|
|
} else { |
38
|
|
|
$this->view->setTitle('Личный кабинет'); |
39
|
|
|
$bread[] = ['text' => 'Личный кабинет']; |
40
|
|
|
} |
41
|
|
|
$this->view->page(['data' => compact('widgets', 'sections', 'activeSection', 'bread')]); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function loginAction() { |
45
|
|
|
$this->view->setTitle('Авторизация'); |
|
|
|
|
46
|
|
|
$bread = []; |
47
|
|
|
$bread[] = ['text' => 'Авторизация']; |
48
|
|
|
$this->view->page(['data' => compact('bread')]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function passreAction() { |
52
|
|
|
$this->view->setTitle('Восстановление пароля'); |
|
|
|
|
53
|
|
|
$bread = []; |
54
|
|
|
$bread[] = ['text' => 'Восстановление пароля']; |
55
|
|
|
$this->view->page(['data' => compact('bread')]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function registrationAction() { |
59
|
|
|
if (User::$cur->user_id) { |
|
|
|
|
60
|
|
|
Tools::redirect('/', 'Вы уже зарегистрированы'); |
61
|
|
|
} |
62
|
|
|
if (!empty($_POST)) { |
63
|
|
|
$error = false; |
64
|
|
|
if ($this->Recaptcha) { |
|
|
|
|
65
|
|
|
$response = $this->Recaptcha->check($_POST['g-recaptcha-response']); |
|
|
|
|
66
|
|
|
if ($response) { |
67
|
|
|
if (!$response->success) { |
68
|
|
|
\Inji\Msg::add('Вы не прошли проверку на робота', 'danger'); |
69
|
|
|
$error = true; |
70
|
|
|
} |
71
|
|
|
} else { |
72
|
|
|
\Inji\Msg::add('Произошла ошибка, попробуйте ещё раз'); |
73
|
|
|
$error = true; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
if (!$error) { |
77
|
|
|
if ($this->Users->registration($_POST)) { |
|
|
|
|
78
|
|
|
Tools::redirect('/'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
$bread = []; |
83
|
|
|
$bread[] = ['text' => 'Регистрация']; |
84
|
|
|
$socials = \Inji\Users\Social::getList(['where' => ['active', 1]]); |
85
|
|
|
|
86
|
|
|
$page = new Page(['data' => compact('bread', 'socials')]); |
87
|
|
|
$page->setTitle('Регистрация'); |
88
|
|
|
return new Page(['data' => compact('bread', 'socials')]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function fastRegistrationAction() { |
92
|
|
|
$result = new Result(); |
93
|
|
|
if (User::$cur->user_id) { |
|
|
|
|
94
|
|
|
$result->success = false; |
95
|
|
|
$result->content = 'Вы уже зарегистрированы'; |
96
|
|
|
return $result->send(); |
97
|
|
|
} |
98
|
|
|
if (!empty($_POST)) { |
99
|
|
|
$error = false; |
100
|
|
|
if ($this->Recaptcha) { |
|
|
|
|
101
|
|
|
$response = $this->Recaptcha->check($_POST['g-recaptcha-response']); |
102
|
|
|
if ($response) { |
103
|
|
|
if (!$response->success) { |
104
|
|
|
$result->success = false; |
105
|
|
|
$result->content = 'Вы не прошли проверку на робота'; |
106
|
|
|
return $result->send(); |
107
|
|
|
} |
108
|
|
|
} else { |
109
|
|
|
$result->success = false; |
110
|
|
|
$result->content = 'Произошла ошибка, попробуйте ещё раз'; |
111
|
|
|
return $result->send(); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
if (!$error) { |
115
|
|
|
$resultReg = $this->Users->registration($_POST, true, false); |
|
|
|
|
116
|
|
|
if (is_numeric($resultReg)) { |
117
|
|
|
return $result->send(); |
118
|
|
|
} else { |
119
|
|
|
$result->success = false; |
120
|
|
|
$result->content = $resultReg['error']; |
121
|
|
|
return $result->send(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function activationAction($userId = 0, $hash = '') { |
129
|
|
|
$user = User::get((int)$userId); |
130
|
|
|
if (!$user || !$hash || $user->activation !== (string)$hash) { |
131
|
|
|
Tools::redirect('/', 'Во время активации произошли ошибки', 'danger'); |
132
|
|
|
} |
133
|
|
|
$user->activation = ''; |
134
|
|
|
$user->save(); |
135
|
|
|
\Inji::$inst->event('Users-completeActivation', $user); |
136
|
|
|
Tools::redirect('/', 'Вы успешно активировали ваш аккаунт', 'success'); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function attachEmailAction() { |
140
|
|
|
if (User::$cur->mail) { |
141
|
|
|
Tools::redirect('/', 'К вашему аккаунту уже привязан E-Mail'); |
142
|
|
|
} |
143
|
|
|
if (!empty($_POST['mail'])) { |
144
|
|
|
$user_mail = trim($_POST['mail']); |
145
|
|
|
if (!filter_var($user_mail, FILTER_VALIDATE_EMAIL)) { |
146
|
|
|
Msg::add('Вы ввели не корректный E-mail', 'danger'); |
147
|
|
|
} else { |
148
|
|
|
$user = User::get($user_mail, 'mail'); |
149
|
|
|
if ($user && $user->id != User::$cur->id) { |
150
|
|
|
Msg::add('Данный E-mail уже привязан к другому аккаунту', 'danger'); |
151
|
|
|
} else { |
152
|
|
|
User::$cur->mail = $user_mail; |
153
|
|
|
if (!empty($this->module->config['needActivation'])) { |
154
|
|
|
User::$cur->activation = Tools::randomString(); |
155
|
|
|
$from = 'noreply@' . INJI_DOMAIN_NAME; |
156
|
|
|
$to = $user_mail; |
157
|
|
|
$subject = 'Активация аккаунта на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
158
|
|
|
$text = 'Для активации вашего аккаунта перейдите по ссылке <a href = "http://' . INJI_DOMAIN_NAME . '/users/activation/' . User::$cur->id . '/' . User::$cur->activation . '">http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/users/activation/' . User::$cur->id . '/' . User::$cur->activation . '</a>'; |
159
|
|
|
Tools::sendMail($from, $to, $subject, $text); |
160
|
|
|
Msg::add('На указанный почтовый ящик была выслана ваша ссылка для подтверждения E-Mail', 'success'); |
161
|
|
|
} else { |
162
|
|
|
Msg::add('Вы успешно привязали E-Mail к своему аккаунту', 'success'); |
163
|
|
|
} |
164
|
|
|
User::$cur->save(); |
165
|
|
|
Tools::redirect('/'); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
$this->view->page(); |
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function resendActivationAction($userId = 0) { |
173
|
|
|
$user = User::get((int)$userId); |
174
|
|
|
if (!$user) { |
175
|
|
|
Tools::redirect('/', 'Не указан пользователь', 'danger'); |
176
|
|
|
} |
177
|
|
|
if (!$user->activation) { |
178
|
|
|
Tools::redirect('/', 'Пользователь уже активирован'); |
179
|
|
|
} |
180
|
|
|
$from = 'noreply@' . INJI_DOMAIN_NAME; |
181
|
|
|
$to = $user->mail; |
182
|
|
|
$subject = 'Активация аккаунта на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
183
|
|
|
$text = 'Для активации вашего аккаунта перейдите по ссылке <a href = "http://' . INJI_DOMAIN_NAME . '/users/activation/' . $user->id . '/' . $user->activation . '">http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/users/activation/' . $user->id . '/' . $user->activation . '</a>'; |
184
|
|
|
Tools::sendMail($from, $to, $subject, $text); |
185
|
|
|
Tools::redirect('/', 'На указанный почтовый ящик была выслана ваша ссылка для подтверждения E-Mail', 'success'); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getPartnerInfoAction($userId = 0) { |
189
|
|
|
$userId = (int)$userId; |
190
|
|
|
$result = new Result(); |
191
|
|
|
if (!$userId) { |
192
|
|
|
$result->success = false; |
193
|
|
|
$result->content = 'Не указан пользователь'; |
194
|
|
|
$result->send(); |
195
|
|
|
} |
196
|
|
|
$partners = App::$cur->users->getUserPartners(User::$cur, 8); |
|
|
|
|
197
|
|
|
if (empty($partners['users'][$userId])) { |
198
|
|
|
$result->success = false; |
199
|
|
|
$result->content = 'Этот пользователь не находится в вашей структуре'; |
200
|
|
|
$result->send(); |
201
|
|
|
} |
202
|
|
|
$user = $partners['users'][$userId]; |
203
|
|
|
ob_start(); |
204
|
|
|
echo "id:{$user->id}<br />"; |
205
|
|
|
echo "E-mail: <a href='mailto:{$user->mail}'>{$user->mail}</a>"; |
206
|
|
|
$rewards = Money\Reward::getList(['where' => ['active', 1]]); |
|
|
|
|
207
|
|
|
foreach ($rewards as $reward) { |
208
|
|
|
foreach ($reward->conditions as $condition) { |
209
|
|
|
$complete = $condition->checkComplete($userId); |
210
|
|
|
?> |
211
|
|
|
<h5 class="<?= $complete ? 'text-success' : 'text-danger'; ?>"><?= $condition->name(); ?></h5> |
212
|
|
|
<ul> |
213
|
|
|
<?php |
214
|
|
|
foreach ($condition->items as $item) { |
215
|
|
|
$itemComplete = $item->checkComplete($userId); |
216
|
|
|
switch ($item->type) { |
217
|
|
|
case 'event': |
218
|
|
|
$name = \Events\Event::get($item->value, 'event')->name(); |
219
|
|
|
break; |
220
|
|
|
} |
221
|
|
|
?> |
222
|
|
|
<li> |
223
|
|
|
<b class="<?= $itemComplete ? 'text-success' : 'text-danger'; ?>"><?= $name; ?> <?= $item->recivedCount($userId); ?></b>/<?= $item->count; ?> |
|
|
|
|
224
|
|
|
<br/> |
225
|
|
|
</li> |
226
|
|
|
<?php |
227
|
|
|
} |
228
|
|
|
?> |
229
|
|
|
</ul> |
230
|
|
|
<?php |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
$result->content = ob_get_contents(); |
234
|
|
|
ob_end_clean(); |
235
|
|
|
$result->send(); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
} |
239
|
|
|
|