@@ -14,7 +14,7 @@ |
||
14 | 14 | // the key fields in this table are responsible for the session |
15 | 15 | // this is the session id, expire and data fields. After that the next important field is the user_uuid |
16 | 16 | // then the following additional information fields |
17 | - $this->addColumn(\neon\user\models\Session::tableName(), 'user_uuid', $this->uuid64() .' AFTER `data`'); |
|
17 | + $this->addColumn(\neon\user\models\Session::tableName(), 'user_uuid', $this->uuid64().' AFTER `data`'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function safeDown() |
@@ -6,30 +6,30 @@ |
||
6 | 6 | class m170104_26042017_user_api_tokens extends Migration |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @inheritdoc |
|
11 | - * Install the User, AuthRule, AuthItem, AuthItemChild, AuthAssignment tables |
|
12 | - */ |
|
9 | + /** |
|
10 | + * @inheritdoc |
|
11 | + * Install the User, AuthRule, AuthItem, AuthItemChild, AuthAssignment tables |
|
12 | + */ |
|
13 | 13 | public function safeUp() |
14 | - { |
|
14 | + { |
|
15 | 15 | $sql = "DROP TABLE IF EXISTS ".UserApiToken::tableName(); |
16 | 16 | \Yii::$app->getDb()->createCommand($sql)->execute(); |
17 | 17 | |
18 | - $this->createTable(UserApiToken::tableName(), [ |
|
19 | - 'token'=>'varchar(64) PRIMARY KEY COMMENT "The token"', |
|
20 | - 'name' => 'varchar(100) COMMENT "A name for this token"', |
|
21 | - 'user_id'=>'int COMMENT "foreign key of the user who owns this token"', |
|
22 | - 'active'=>'int not null default 0 COMMENT "whether the token is currently active, 1 is an active token, 0 is a non active token and will not produce successful requests"', |
|
23 | - 'last_used'=>'datetime COMMENT "store the date and time of the last request that used this token"', |
|
24 | - 'used_count'=>'int not null default 0 COMMENT "number of times this token has been used"', |
|
25 | - // timestamps |
|
26 | - 'created_at' => $this->createdAt(), |
|
27 | - 'updated_at' => $this->updatedAt(), |
|
28 | - ]); |
|
29 | - } |
|
18 | + $this->createTable(UserApiToken::tableName(), [ |
|
19 | + 'token'=>'varchar(64) PRIMARY KEY COMMENT "The token"', |
|
20 | + 'name' => 'varchar(100) COMMENT "A name for this token"', |
|
21 | + 'user_id'=>'int COMMENT "foreign key of the user who owns this token"', |
|
22 | + 'active'=>'int not null default 0 COMMENT "whether the token is currently active, 1 is an active token, 0 is a non active token and will not produce successful requests"', |
|
23 | + 'last_used'=>'datetime COMMENT "store the date and time of the last request that used this token"', |
|
24 | + 'used_count'=>'int not null default 0 COMMENT "number of times this token has been used"', |
|
25 | + // timestamps |
|
26 | + 'created_at' => $this->createdAt(), |
|
27 | + 'updated_at' => $this->updatedAt(), |
|
28 | + ]); |
|
29 | + } |
|
30 | 30 | |
31 | - public function safeDown() |
|
32 | - { |
|
33 | - $this->dropTable(UserApiToken::tableName()); |
|
34 | - } |
|
31 | + public function safeDown() |
|
32 | + { |
|
33 | + $this->dropTable(UserApiToken::tableName()); |
|
34 | + } |
|
35 | 35 | } |
@@ -7,17 +7,17 @@ |
||
7 | 7 | { |
8 | 8 | public function safeUp() |
9 | 9 | { |
10 | - $this->createTable(UserInvite::tableName(), [ |
|
11 | - 'token'=>'varchar(255) CHARACTER SET latin1 COLLATE latin1_general_cs PRIMARY KEY COMMENT "The token"', |
|
12 | - 'user_id'=> $this->uuid64( 'foreign key of the user who owns this token')->notNull(), |
|
13 | - // timestamps |
|
14 | - 'expires_at' => $this->dateTime(), |
|
15 | - 'created_at' => $this->createdAt(), |
|
16 | - 'updated_at' => $this->updatedAt(), |
|
17 | - // blames |
|
18 | - 'created_by' => $this->createdBy(), |
|
19 | - 'updated_by' => $this->updatedBy() |
|
20 | - ]); |
|
10 | + $this->createTable(UserInvite::tableName(), [ |
|
11 | + 'token'=>'varchar(255) CHARACTER SET latin1 COLLATE latin1_general_cs PRIMARY KEY COMMENT "The token"', |
|
12 | + 'user_id'=> $this->uuid64( 'foreign key of the user who owns this token')->notNull(), |
|
13 | + // timestamps |
|
14 | + 'expires_at' => $this->dateTime(), |
|
15 | + 'created_at' => $this->createdAt(), |
|
16 | + 'updated_at' => $this->updatedAt(), |
|
17 | + // blames |
|
18 | + 'created_by' => $this->createdBy(), |
|
19 | + 'updated_by' => $this->updatedBy() |
|
20 | + ]); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function safeDown() |
@@ -9,7 +9,7 @@ |
||
9 | 9 | { |
10 | 10 | $this->createTable(UserInvite::tableName(), [ |
11 | 11 | 'token'=>'varchar(255) CHARACTER SET latin1 COLLATE latin1_general_cs PRIMARY KEY COMMENT "The token"', |
12 | - 'user_id'=> $this->uuid64( 'foreign key of the user who owns this token')->notNull(), |
|
12 | + 'user_id'=> $this->uuid64('foreign key of the user who owns this token')->notNull(), |
|
13 | 13 | // timestamps |
14 | 14 | 'expires_at' => $this->dateTime(), |
15 | 15 | 'created_at' => $this->createdAt(), |
@@ -71,22 +71,22 @@ |
||
71 | 71 | 'created_at' => $this->integer(), |
72 | 72 | 'updated_at' => $this->integer(), |
73 | 73 | 'PRIMARY KEY (name)', |
74 | - 'FOREIGN KEY (rule_name) REFERENCES ' . neon()->authManager->ruleTable . ' (name) ON DELETE SET NULL ON UPDATE CASCADE' |
|
74 | + 'FOREIGN KEY (rule_name) REFERENCES '.neon()->authManager->ruleTable.' (name) ON DELETE SET NULL ON UPDATE CASCADE' |
|
75 | 75 | ]); |
76 | 76 | $this->createIndex('idx-auth_item-type', AuthItem::tableName(), 'type'); |
77 | 77 | $this->createTable(AuthItemChild::tableName(), [ |
78 | 78 | 'parent' => $this->string(64)->notNull(), |
79 | 79 | 'child' => $this->string(64)->notNull(), |
80 | 80 | 'PRIMARY KEY (parent, child)', |
81 | - 'FOREIGN KEY (parent) REFERENCES ' . neon()->authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', |
|
82 | - 'FOREIGN KEY (child) REFERENCES ' . neon()->authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE' |
|
81 | + 'FOREIGN KEY (parent) REFERENCES '.neon()->authManager->itemTable.' (name) ON DELETE CASCADE ON UPDATE CASCADE', |
|
82 | + 'FOREIGN KEY (child) REFERENCES '.neon()->authManager->itemTable.' (name) ON DELETE CASCADE ON UPDATE CASCADE' |
|
83 | 83 | ]); |
84 | 84 | $this->createTable(AuthAssignment::tableName(), [ |
85 | 85 | 'item_name' => $this->string(64)->notNull(), |
86 | 86 | 'user_id' => $this->string(64)->notNull(), |
87 | 87 | 'created_at' => $this->integer(), |
88 | 88 | 'PRIMARY KEY (item_name, user_id)', |
89 | - 'FOREIGN KEY (item_name) REFERENCES ' . neon()->authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', |
|
89 | + 'FOREIGN KEY (item_name) REFERENCES '.neon()->authManager->itemTable.' (name) ON DELETE CASCADE ON UPDATE CASCADE', |
|
90 | 90 | ]); |
91 | 91 | $this->createTable(Session::tableName(), [ |
92 | 92 | 'id' => 'CHAR(64) NOT NULL PRIMARY KEY', |
@@ -25,7 +25,7 @@ |
||
25 | 25 | public function safeDown() |
26 | 26 | { |
27 | 27 | $auth = neon()->authManager; |
28 | - $auth->removeAll(); |
|
28 | + $auth->removeAll(); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -17,8 +17,9 @@ |
||
17 | 17 | $this->addColumn(User::tableName(), 'uuid', 'char(22) AFTER `id`'); |
18 | 18 | // fetch 50 users at a time and iterate them one by one |
19 | 19 | // save call will automatically create the uuid if it currently does not exist |
20 | - foreach (User::find()->each(50) as $user) |
|
21 | - $user->save(false, [User::UUID]); |
|
20 | + foreach (User::find()->each(50) as $user) { |
|
21 | + $user->save(false, [User::UUID]); |
|
22 | + } |
|
22 | 23 | // create a unique index |
23 | 24 | $this->createIndex('uuid', User::tableName(), 'uuid', true); |
24 | 25 | } |
@@ -5,23 +5,23 @@ |
||
5 | 5 | class m161211_160816_user_correct_current_field extends Migration |
6 | 6 | { |
7 | 7 | |
8 | - public function safeUp() |
|
9 | - { |
|
8 | + public function safeUp() |
|
9 | + { |
|
10 | 10 | /** |
11 | 11 | * fix an incorrect definition of current in the code and make the name more meaningful |
12 | 12 | */ |
13 | 13 | $table = \neon\user\models\Session::tableName(); |
14 | 14 | $this->dropColumn($table, 'current'); |
15 | 15 | $this->addColumn($table, 'current_url', $this->string(1000)->comment('The current url the user requested in this session')); |
16 | - } |
|
16 | + } |
|
17 | 17 | |
18 | - public function safeDown() |
|
19 | - { |
|
18 | + public function safeDown() |
|
19 | + { |
|
20 | 20 | /** |
21 | 21 | * revert back to the broken definition |
22 | 22 | */ |
23 | 23 | $table = \neon\user\models\Session::tableName(); |
24 | 24 | $this->dropColumn($table, 'current_url'); |
25 | 25 | $this->addColumn($table, 'current', $this->dateTime()->comment('The current url the user requested in this session')); |
26 | - } |
|
26 | + } |
|
27 | 27 | } |
@@ -5,17 +5,17 @@ |
||
5 | 5 | class m170104_161200_use_baseclass_timestamps extends Migration |
6 | 6 | { |
7 | 7 | |
8 | - public function safeUp() |
|
9 | - { |
|
8 | + public function safeUp() |
|
9 | + { |
|
10 | 10 | $table = \neon\user\models\User::tableName(); |
11 | 11 | $this->renameColumn($table, 'created_on', 'created_at'); |
12 | 12 | $this->renameColumn($table, 'updated_on', 'updated_at'); |
13 | - } |
|
13 | + } |
|
14 | 14 | |
15 | - public function safeDown() |
|
16 | - { |
|
15 | + public function safeDown() |
|
16 | + { |
|
17 | 17 | $table = \neon\user\models\User::tableName(); |
18 | 18 | $this->renameColumn($table, 'created_at', 'created_on'); |
19 | 19 | $this->renameColumn($table, 'updated_at', 'updated_on'); |
20 | - } |
|
20 | + } |
|
21 | 21 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | /** |
126 | 126 | * @inheritdoc |
127 | 127 | */ |
128 | - public function getDataMap($key, $query='', $filters=[], $fields=[], $start=0, $length=100) |
|
128 | + public function getDataMap($key, $query = '', $filters = [], $fields = [], $start = 0, $length = 100) |
|
129 | 129 | { |
130 | 130 | if ($key === 'users') { |
131 | 131 | return User::getUserList($query, $filters, $fields, $start, $length); |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @param array &$roles the roles that matched |
277 | 277 | * @return boolean whether it matched any roles |
278 | 278 | */ |
279 | - public function routeHasRoles($route, &$roles=null) |
|
279 | + public function routeHasRoles($route, &$roles = null) |
|
280 | 280 | { |
281 | 281 | $roles = []; |
282 | 282 | foreach ($this->_routes as $r) { |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | } |
286 | 286 | } |
287 | 287 | // allow guest access if this is the only allowed role |
288 | - if (count($roles)==1 && isset($roles['?'])) |
|
288 | + if (count($roles) == 1 && isset($roles['?'])) |
|
289 | 289 | return false; |
290 | 290 | // otherwise restrict to requiring a role if one matched |
291 | 291 | return (count($roles) > 0); |
@@ -144,8 +144,9 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function getMapResults($requestKey) |
146 | 146 | { |
147 | - if (!isset($this->_mapRequestKey[$requestKey])) |
|
148 | - throw new \InvalidArgumentException('The provided request key "'.$requestKey.'" does not exist'); |
|
147 | + if (!isset($this->_mapRequestKey[$requestKey])) { |
|
148 | + throw new \InvalidArgumentException('The provided request key "'.$requestKey.'" does not exist'); |
|
149 | + } |
|
149 | 150 | list($key, $ids, $fields) = $this->_mapRequestKey[$requestKey]; |
150 | 151 | if ($key === 'users') { |
151 | 152 | return User::getUserList('', ['uuid' => $ids]); |
@@ -255,15 +256,17 @@ discard block |
||
255 | 256 | public function setRoles(array $roles) |
256 | 257 | { |
257 | 258 | foreach ($roles as $role => $details) { |
258 | - if (!array_key_exists($role, $this->_roles)) |
|
259 | - $this->_roles[$role] = ['routes'=>[]]; |
|
259 | + if (!array_key_exists($role, $this->_roles)) { |
|
260 | + $this->_roles[$role] = ['routes'=>[]]; |
|
261 | + } |
|
260 | 262 | if (array_key_exists('routes', $details)) { |
261 | 263 | foreach ($details['routes'] as $r) { |
262 | 264 | $this->_roles[$role]['routes'][$r] = $r; |
263 | 265 | $this->_routes2Roles[$r][$role] = $role; |
264 | 266 | } |
265 | - if (array_key_exists('homeUrl', $details)) |
|
266 | - $this->_roles[$role]['homeUrl'] = $details['homeUrl']; |
|
267 | + if (array_key_exists('homeUrl', $details)) { |
|
268 | + $this->_roles[$role]['homeUrl'] = $details['homeUrl']; |
|
269 | + } |
|
267 | 270 | $this->_roles[$role]['label'] = (array_key_exists('label', $details) ? $details['label'] : $role); |
268 | 271 | } |
269 | 272 | } |
@@ -285,8 +288,9 @@ discard block |
||
285 | 288 | } |
286 | 289 | } |
287 | 290 | // allow guest access if this is the only allowed role |
288 | - if (count($roles)==1 && isset($roles['?'])) |
|
289 | - return false; |
|
291 | + if (count($roles)==1 && isset($roles['?'])) { |
|
292 | + return false; |
|
293 | + } |
|
290 | 294 | // otherwise restrict to requiring a role if one matched |
291 | 295 | return (count($roles) > 0); |
292 | 296 | } |