1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Saito - The Threaded Web Forum |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright (c) the Saito Project Developers |
9
|
|
|
* @link https://github.com/Schlaefer/Saito |
10
|
|
|
* @license http://opensource.org/licenses/MIT |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Admin\Controller; |
14
|
|
|
|
15
|
|
|
use App\Model\Table\UsersTable; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @property UsersTable $Users |
19
|
|
|
*/ |
20
|
|
|
class UsersController extends AdminAppController |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritDoc} |
24
|
|
|
*/ |
25
|
|
|
public function initialize() |
26
|
|
|
{ |
27
|
|
|
parent::initialize(); |
28
|
|
|
$this->loadModel('Users'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* List all users. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function index() |
37
|
|
|
{ |
38
|
|
|
$data = $this->Users->find() |
39
|
|
|
->select( |
40
|
|
|
[ |
41
|
|
|
'id', |
42
|
|
|
'username', |
43
|
|
|
'user_type', |
44
|
|
|
'user_email', |
45
|
|
|
'registered', |
46
|
|
|
'user_lock' |
47
|
|
|
] |
48
|
|
|
) |
49
|
|
|
->order(['username' => 'asc']) |
50
|
|
|
->all(); |
51
|
|
|
$this->set('users', $data); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* add user |
56
|
|
|
* |
57
|
|
|
* @return \Cake\Network\Response|void |
58
|
|
|
*/ |
59
|
|
|
public function add() |
60
|
|
|
{ |
61
|
|
|
if (!$this->request->is('post') && empty($this->request->getData())) { |
62
|
|
|
$user = $this->Users->newEntity(); |
63
|
|
|
} else { |
64
|
|
|
$user = $this->Users->register($this->request->getData(), true); |
65
|
|
|
if (!empty($user) && !$user->hasErrors()) { |
66
|
|
|
$this->Flash->set(__('user.admin.add.success'), ['element' => 'success']); |
67
|
|
|
|
68
|
|
|
return $this->redirect(['plugin' => false, 'action' => 'view', $user->get('id')]); |
69
|
|
|
} else { |
70
|
|
|
$this->Flash->set(__('user.admin.add.error'), ['element' => 'error']); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
$this->set('user', $user); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* List all blocked users. |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
public function block() |
82
|
|
|
{ |
83
|
|
|
$this->set('UserBlock', $this->Users->UserBlocks->getAll()); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|