@@ -48,7 +48,7 @@ |
||
48 | 48 | public function __invoke(Request $request, Response $response, callable $next = null) |
49 | 49 | { |
50 | 50 | if (0 === strpos($request->getUri()->getPath(), '/admin')) { |
51 | - $this->config['templates']['layout'] = 'layout/admin'; |
|
51 | + $this->config[ 'templates' ][ 'layout' ] = 'layout/admin'; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | return $next($request, $response); |
@@ -4,8 +4,6 @@ |
||
4 | 4 | namespace Core\Service; |
5 | 5 | |
6 | 6 | use Core\Mapper\AdminUsersMapper; |
7 | -use Zend\Db\TableGateway\TableGateway; |
|
8 | -use Zend\Db\Sql\Predicate\Expression; |
|
9 | 7 | use Zend\Paginator\Adapter\DbSelect; |
10 | 8 | use Zend\Paginator\Paginator; |
11 | 9 | use Zend\Crypt\Password\Bcrypt; |
@@ -106,7 +106,7 @@ |
||
106 | 106 | * Update or Insert user. |
107 | 107 | * |
108 | 108 | * @param Array $data Data from POST |
109 | - * @param null $userId UUID of user if we want to edit or 0 to add new user |
|
109 | + * @param integer $userId UUID of user if we want to edit or 0 to add new user |
|
110 | 110 | * @throws \Exception |
111 | 111 | */ |
112 | 112 | public function save($data, $userId = 0) |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | { |
53 | 53 | $user = $this->adminUsersMapper->getByEmail($email); |
54 | 54 | |
55 | - if(!$user){ |
|
55 | + if (!$user) { |
|
56 | 56 | throw new \Exception('User does not exist.'); |
57 | 57 | } |
58 | 58 | |
59 | - if(!$this->crypt->verify($password, $user->password)){ |
|
59 | + if (!$this->crypt->verify($password, $user->password)) { |
|
60 | 60 | throw new \Exception('Password does not match.'); |
61 | 61 | } |
62 | 62 | |
63 | - if($user->status != 1){ |
|
63 | + if ($user->status != 1) { |
|
64 | 64 | throw new \Exception('User is not active.'); |
65 | 65 | } |
66 | 66 | |
@@ -112,18 +112,18 @@ discard block |
||
112 | 112 | public function save($data, $userId = 0) |
113 | 113 | { |
114 | 114 | //@todo Validate data |
115 | - if($data['password'] == ''){ |
|
116 | - unset($data['password']); |
|
115 | + if ($data[ 'password' ] == '') { |
|
116 | + unset($data[ 'password' ]); |
|
117 | 117 | } |
118 | - else{ |
|
119 | - $data['password'] = $this->crypt->create($data['password']); |
|
118 | + else { |
|
119 | + $data[ 'password' ] = $this->crypt->create($data[ 'password' ]); |
|
120 | 120 | } |
121 | 121 | |
122 | - if($userId){ |
|
123 | - $this->adminUsersMapper->update($data, ['admin_user_uuid' => $userId]); |
|
122 | + if ($userId) { |
|
123 | + $this->adminUsersMapper->update($data, [ 'admin_user_uuid' => $userId ]); |
|
124 | 124 | } |
125 | - else{ |
|
126 | - $data['admin_user_uuid'] = Uuid::uuid1()->toString(); |
|
125 | + else { |
|
126 | + $data[ 'admin_user_uuid' ] = Uuid::uuid1()->toString(); |
|
127 | 127 | $this->adminUsersMapper->insert($data); |
128 | 128 | } |
129 | 129 | } |
@@ -136,6 +136,6 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function delete($userId) |
138 | 138 | { |
139 | - return (bool)$this->adminUsersMapper->delete(['admin_user_uuid' => $userId]); |
|
139 | + return (bool) $this->adminUsersMapper->delete([ 'admin_user_uuid' => $userId ]); |
|
140 | 140 | } |
141 | 141 | } |
@@ -114,15 +114,13 @@ |
||
114 | 114 | //@todo Validate data |
115 | 115 | if($data['password'] == ''){ |
116 | 116 | unset($data['password']); |
117 | - } |
|
118 | - else{ |
|
117 | + } else{ |
|
119 | 118 | $data['password'] = $this->crypt->create($data['password']); |
120 | 119 | } |
121 | 120 | |
122 | 121 | if($userId){ |
123 | 122 | $this->adminUsersMapper->update($data, ['admin_user_uuid' => $userId]); |
124 | - } |
|
125 | - else{ |
|
123 | + } else{ |
|
126 | 124 | $data['admin_user_uuid'] = Uuid::uuid1()->toString(); |
127 | 125 | $this->adminUsersMapper->insert($data); |
128 | 126 | } |
@@ -6,27 +6,27 @@ |
||
6 | 6 | { |
7 | 7 | public function up() |
8 | 8 | { |
9 | - $this->table('admin_users', ['id' => false, 'primary_key' => 'admin_user_uuid']) |
|
10 | - ->addColumn('admin_user_uuid', 'binary', ['limit' => 16]) |
|
9 | + $this->table('admin_users', [ 'id' => false, 'primary_key' => 'admin_user_uuid' ]) |
|
10 | + ->addColumn('admin_user_uuid', 'binary', [ 'limit' => 16 ]) |
|
11 | 11 | ->addColumn('first_name', 'text') |
12 | 12 | ->addColumn('last_name', 'text') |
13 | - ->addColumn('email', 'string', ['limit' => 128]) |
|
14 | - ->addColumn('password', 'char', ['limit' => 60]) |
|
15 | - ->addColumn('status', 'integer', ['default' => 0])// 0 => not active, 1 = active |
|
16 | - ->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP']) |
|
17 | - ->addColumn('last_login', 'datetime', ['null' => true]) |
|
18 | - ->addIndex(['email'], ['name' => 'email_INDEX']) |
|
13 | + ->addColumn('email', 'string', [ 'limit' => 128 ]) |
|
14 | + ->addColumn('password', 'char', [ 'limit' => 60 ]) |
|
15 | + ->addColumn('status', 'integer', [ 'default' => 0 ])// 0 => not active, 1 = active |
|
16 | + ->addColumn('created_at', 'datetime', [ 'default' => 'CURRENT_TIMESTAMP' ]) |
|
17 | + ->addColumn('last_login', 'datetime', [ 'null' => true ]) |
|
18 | + ->addIndex([ 'email' ], [ 'name' => 'email_INDEX' ]) |
|
19 | 19 | ->create(); |
20 | 20 | |
21 | 21 | $faker = Faker\Factory::create(); |
22 | 22 | $count = rand(100, 150); |
23 | - for($i = 0; $i < $count; $i++){ |
|
23 | + for ($i = 0; $i < $count; $i++) { |
|
24 | 24 | $data = [ |
25 | 25 | 'admin_user_uuid' => $faker->uuid, |
26 | 26 | 'email' => $faker->email, |
27 | 27 | 'first_name' => $faker->firstName, |
28 | 28 | 'last_name' => $faker->lastName, |
29 | - 'password' => '$2y$10$jhGH8RXl269ho1CrLaDiregVuW84HegLHmBFUCKTgDQTH2XgPZyBK',//password = testtest |
|
29 | + 'password' => '$2y$10$jhGH8RXl269ho1CrLaDiregVuW84HegLHmBFUCKTgDQTH2XgPZyBK', //password = testtest |
|
30 | 30 | 'status' => rand(0, 1), |
31 | 31 | 'last_login' => rand(0, 10) === 7 ? null : $faker->dateTimeBetween('-10 days', 'now')->format('Y-m-d H:i:s'), |
32 | 32 | 'created_at' => $faker->dateTimeBetween('-20 days', '-10 days')->format('Y-m-d H:i:s'), |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | 'name' => 'home', |
25 | 25 | 'path' => '/', |
26 | 26 | 'middleware' => Web\Action\IndexAction::class, |
27 | - 'allowed_methods' => ['GET'], |
|
27 | + 'allowed_methods' => [ 'GET' ], |
|
28 | 28 | ], |
29 | 29 | [ |
30 | 30 | 'name' => 'about', |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | 'name' => 'api.ping', |
41 | 41 | 'path' => '/api/ping', |
42 | 42 | 'middleware' => Web\Action\PingAction::class, |
43 | - 'allowed_methods' => ['GET'], |
|
43 | + 'allowed_methods' => [ 'GET' ], |
|
44 | 44 | ], |
45 | 45 | [ |
46 | 46 | 'name' => 'auth', |
47 | 47 | 'path' => '/auth/:action', |
48 | 48 | 'middleware' => Admin\Controller\AuthController::class, |
49 | - 'allowed_methods' => ['GET', 'POST'], |
|
49 | + 'allowed_methods' => [ 'GET', 'POST' ], |
|
50 | 50 | ], |
51 | 51 | |
52 | 52 | // Admin |
@@ -54,31 +54,31 @@ discard block |
||
54 | 54 | 'name' => 'admin', |
55 | 55 | 'path' => '/admin', |
56 | 56 | 'middleware' => Admin\Action\IndexAction::class, |
57 | - 'allowed_methods' => ['GET'], |
|
57 | + 'allowed_methods' => [ 'GET' ], |
|
58 | 58 | ], |
59 | 59 | [ |
60 | 60 | 'name' => 'admin.users', |
61 | 61 | 'path' => '/admin/users', |
62 | 62 | 'middleware' => Admin\Controller\UserController::class, |
63 | - 'allowed_methods' => ['GET'] |
|
63 | + 'allowed_methods' => [ 'GET' ] |
|
64 | 64 | ], |
65 | 65 | [ |
66 | 66 | 'name' => 'admin.users.action', |
67 | 67 | 'path' => '/admin/users/:action/:id', |
68 | 68 | 'middleware' => Admin\Controller\UserController::class, |
69 | - 'allowed_methods' => ['GET', 'POST'] |
|
69 | + 'allowed_methods' => [ 'GET', 'POST' ] |
|
70 | 70 | ], |
71 | 71 | [ |
72 | 72 | 'name' => 'admin.tags', |
73 | 73 | 'path' => '/admin/tags', |
74 | 74 | 'middleware' => Admin\Controller\TagController::class, |
75 | - 'allowed_methods' => ['GET'], |
|
75 | + 'allowed_methods' => [ 'GET' ], |
|
76 | 76 | ], |
77 | 77 | [ |
78 | 78 | 'name' => 'admin.posts', |
79 | 79 | 'path' => '/admin/posts', |
80 | 80 | 'middleware' => Admin\Controller\PostController::class, |
81 | - 'allowed_methods' => ['GET'], |
|
81 | + 'allowed_methods' => [ 'GET' ], |
|
82 | 82 | ], |
83 | 83 | ], |
84 | 84 | ]; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | public function get($id) |
33 | 33 | { |
34 | - return $this->select(['admin_user_uuid' => $id])->current(); |
|
34 | + return $this->select([ 'admin_user_uuid' => $id ])->current(); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function getByEmail(string $email) |
44 | 44 | { |
45 | - return $this->select(['email' => $email])->current(); |
|
45 | + return $this->select([ 'email' => $email ])->current(); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function updateLogin(string $uuid) : int |
55 | 55 | { |
56 | - return $this->update(['last_login' => date('Y-m-d H:i:s')], ['admin_user_uuid' => $uuid]); |
|
56 | + return $this->update([ 'last_login' => date('Y-m-d H:i:s') ], [ 'admin_user_uuid' => $uuid ]); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function getPaginationSelect($userId) |
60 | 60 | { |
61 | - $select = $this->getSql()->select()->order(['created_at' => 'desc']); |
|
61 | + $select = $this->getSql()->select()->order([ 'created_at' => 'desc' ]); |
|
62 | 62 | |
63 | 63 | $select->where->notEqualTo('admin_user_uuid', $userId); |
64 | 64 |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | { |
65 | 65 | $user = $this->session->getStorage()->user; |
66 | 66 | $params = $this->request->getQueryParams(); |
67 | - $page = isset($params['page']) ? $params['page'] : self::DEFAUTL_PAGE; |
|
68 | - $limit = isset($params['limit']) ? $params['limit'] : self::DEFAUTL_LIMIT; |
|
67 | + $page = isset($params[ 'page' ]) ? $params[ 'page' ] : self::DEFAUTL_PAGE; |
|
68 | + $limit = isset($params[ 'limit' ]) ? $params[ 'limit' ] : self::DEFAUTL_LIMIT; |
|
69 | 69 | |
70 | 70 | //$filter = [ |
71 | 71 | // 'first_name' => isset($params['first_name']) ? $params['first_name'] : '', |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $adminUsers = $this->adminUserService->getPagination($page, $limit, $user->admin_user_uuid); |
76 | 76 | |
77 | - return new HtmlResponse($this->template->render('admin::user/index', ['list' => $adminUsers])); |
|
77 | + return new HtmlResponse($this->template->render('admin::user/index', [ 'list' => $adminUsers ])); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | $userId = $this->request->getAttribute('id'); |
88 | 88 | $user = $this->adminUserService->getUser($userId); |
89 | 89 | |
90 | - return new HtmlResponse($this->template->render('admin::user/edit', ['user' => $user])); |
|
90 | + return new HtmlResponse($this->template->render('admin::user/edit', [ 'user' => $user ])); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | public function doedit() |
94 | 94 | { |
95 | - try{ |
|
95 | + try { |
|
96 | 96 | $userId = $this->request->getAttribute('id'); |
97 | 97 | $data = $this->request->getParsedBody(); |
98 | 98 | |
@@ -100,23 +100,23 @@ discard block |
||
100 | 100 | |
101 | 101 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users')); |
102 | 102 | } |
103 | - catch(\Exception $e){ |
|
103 | + catch (\Exception $e) { |
|
104 | 104 | return $this->response->withStatus(302)->withHeader( |
105 | 105 | 'Location', |
106 | - $this->router->generateUri('admin.users.action', ['action' => 'edit', 'id' => $userId]) |
|
106 | + $this->router->generateUri('admin.users.action', [ 'action' => 'edit', 'id' => $userId ]) |
|
107 | 107 | ); |
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | 111 | public function delete() |
112 | 112 | { |
113 | - try{ |
|
113 | + try { |
|
114 | 114 | $userId = $this->request->getAttribute('id'); |
115 | 115 | $this->adminUserService->delete($userId); |
116 | 116 | |
117 | 117 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users')); |
118 | 118 | } |
119 | - catch(\Exception $e){ |
|
119 | + catch (\Exception $e) { |
|
120 | 120 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users')); |
121 | 121 | } |
122 | 122 | } |
@@ -99,8 +99,7 @@ discard block |
||
99 | 99 | $this->adminUserService->save($data, $userId); |
100 | 100 | |
101 | 101 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users')); |
102 | - } |
|
103 | - catch(\Exception $e){ |
|
102 | + } catch(\Exception $e){ |
|
104 | 103 | return $this->response->withStatus(302)->withHeader( |
105 | 104 | 'Location', |
106 | 105 | $this->router->generateUri('admin.users.action', ['action' => 'edit', 'id' => $userId]) |
@@ -115,8 +114,7 @@ discard block |
||
115 | 114 | $this->adminUserService->delete($userId); |
116 | 115 | |
117 | 116 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users')); |
118 | - } |
|
119 | - catch(\Exception $e){ |
|
117 | + } catch(\Exception $e){ |
|
120 | 118 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users')); |
121 | 119 | } |
122 | 120 | } |