|
23 | 23 | namespace Vvveb\Controller\User;
|
24 | 24 |
|
25 | 25 | use function Vvveb\__;
|
26 |
| -use function Vvveb\url; |
27 | 26 | use function Vvveb\email;
|
28 | 27 | use function Vvveb\siteSettings;
|
29 | 28 | use Vvveb\System\Event;
|
| 29 | +use Vvveb\System\Sites; |
| 30 | +use Vvveb\System\Traits\Spam; |
30 | 31 | use Vvveb\System\User\User;
|
31 | 32 | use Vvveb\System\Validator;
|
32 |
| -use Vvveb\System\Sites; |
| 33 | +use function Vvveb\url; |
33 | 34 |
|
34 | 35 | class Signup extends \Vvveb\Controller\Base {
|
| 36 | + use Spam; |
| 37 | + |
35 | 38 | function addUser() {
|
36 | 39 | //$this->checkAlreadyLoggedIn();
|
37 | 40 | $validator = new Validator(['signup']);
|
38 | 41 |
|
39 | 42 | if ($this->request->post &&
|
40 | 43 | ($this->view->errors['login'] = $validator->validate($this->request->post)) === true) {
|
| 44 | + $isSpam = $this->isSpam($this->request->post); |
| 45 | + |
41 | 46 | //allow only fields that are in the validator list and remove the rest
|
42 | 47 | $userInfo = $validator->filter($this->request->post);
|
43 | 48 | $userInfo['display_name'] = $userInfo['first_name'] . ' ' . $userInfo['last_name'];
|
44 | 49 | $userInfo['username'] = $userInfo['first_name'] . $userInfo['last_name'];
|
| 50 | + $userInfo['spam'] = $isSpam; |
45 | 51 |
|
46 | 52 | list($userInfo) = Event :: trigger(__CLASS__, __FUNCTION__ , $userInfo);
|
47 | 53 |
|
| 54 | + //plugins can also be used to detect spam and set the flag |
| 55 | + if ($userInfo['spam']) { |
| 56 | + $this->view->errors['login'] = __('Spam'); |
| 57 | + |
| 58 | + return; |
| 59 | + } |
| 60 | + |
48 | 61 | if ($userInfo) {
|
49 | 62 | $result = User::add($userInfo);
|
50 | 63 |
|
51 | 64 | $this->view->errors['login'] = [];
|
52 | 65 |
|
53 | 66 | if ($result) {
|
54 |
| - if (is_array($result)) { |
| 67 | + if (isset($result['user'])) { |
55 | 68 | $message = __('User created!');
|
56 | 69 | $this->session->set('success', ['login' => $message]);
|
57 | 70 | $this->view->success['login'][] = $message;
|
@@ -86,7 +99,7 @@ function addUser() {
|
86 | 99 | $this->view->errors['login'] = __('This email is already in use. Please use another one.');
|
87 | 100 | }
|
88 | 101 | } else {
|
89 |
| - $this->view->errors['login'] = __('Error creating user!'); |
| 102 | + $this->view->errors['login'] = __('Error creating account!'); |
90 | 103 | }
|
91 | 104 | }
|
92 | 105 | }
|
|
0 commit comments