Total Complexity | 44 |
Total Lines | 213 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like UsersAppController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UsersAppController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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() { |
||
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() { |
||
170 | } |
||
171 | |||
172 | public function resendActivationAction($userId = 0) { |
||
173 | $user = User::get((int)$userId); |
||
174 | if (!$user) { |
||
186 | } |
||
187 | |||
188 | public function getPartnerInfoAction($userId = 0) { |
||
236 | } |
||
237 | |||
238 | } |
||
239 |