|
@@ -132,14 +132,14 @@ export class UserManager
|
132
|
132
|
}
|
133
|
133
|
try {
|
134
|
134
|
//If no ADMIN user exists next created user will be made ADMIN
|
135
|
|
- if(this.checkForAdmin){
|
136
|
|
- const admin:User = await this.knexModule
|
137
|
|
- .knex('users')
|
138
|
|
- .where(<SomeOf<User>>{
|
139
|
|
- rank: 'ADMIN'
|
140
|
|
- }).first()
|
141
|
|
-
|
142
|
|
- if(!admin){
|
|
135
|
+ if (this.checkForAdmin) {
|
|
136
|
+ const admin: User = await this.knexModule
|
|
137
|
+ .knex('users')
|
|
138
|
+ .where(<SomeOf<User>>{
|
|
139
|
+ rank: 'ADMIN'
|
|
140
|
+ }).first()
|
|
141
|
+
|
|
142
|
+ if (!admin) {
|
143
|
143
|
user.rank = 'ADMIN'
|
144
|
144
|
}
|
145
|
145
|
this.checkForAdmin = false
|
|
@@ -182,10 +182,11 @@ export class UserManager
|
182
|
182
|
|
183
|
183
|
await Promise.all(
|
184
|
184
|
[...this.admin.frontworkComponents].flatMap(exp => exp.RPCFeatures().map(async (feature) => {
|
185
|
|
- try {
|
186
|
|
- await this.knexModule.knex.insert({ rpcname: feature.name }).into('rpcpermissions')
|
187
|
|
- } catch (e) {
|
188
|
|
- }
|
|
185
|
+ await this.knexModule
|
|
186
|
+ .knex('rpcpermissions')
|
|
187
|
+ .insert(<SomeOf<RPCPermission>>{
|
|
188
|
+ rpcname: feature.name
|
|
189
|
+ })
|
189
|
190
|
})))
|
190
|
191
|
|
191
|
192
|
this.privilegedServer = await this.startRankServer()
|
|
@@ -212,6 +213,7 @@ export class UserManager
|
212
|
213
|
|
213
|
214
|
let user: User, token: Token
|
214
|
215
|
try {
|
|
216
|
+ //@ts-ignore
|
215
|
217
|
[user, token] = await Promise.race([socket.call('getUserData'), new Promise((res, rej) => { setTimeout(rej, 250); })])
|
216
|
218
|
} catch (e) {
|
217
|
219
|
getLogger('UserManager#checkConnection').debug('Client didn\'t respond', e)
|
|
@@ -244,9 +246,12 @@ export class UserManager
|
244
|
246
|
|
245
|
247
|
adminChangePassword = async (username: string, pwHash: string): Promise<User> => {
|
246
|
248
|
const salted = await saltedHash(pwHash, salt)
|
247
|
|
- await this.knexModule.knex('users')
|
248
|
|
- .update({ pwhash: salted })
|
249
|
|
- .where({
|
|
249
|
+ await this.knexModule
|
|
250
|
+ .knex('users')
|
|
251
|
+ .update(<SomeOf<User>>{
|
|
252
|
+ pwhash: salted
|
|
253
|
+ })
|
|
254
|
+ .where(<SomeOf<User>>{
|
250
|
255
|
username: username.toLowerCase()
|
251
|
256
|
})
|
252
|
257
|
|
|
@@ -258,7 +263,9 @@ export class UserManager
|
258
|
263
|
|
259
|
264
|
setPermission = async (permission: RPCPermission) => {
|
260
|
265
|
await this.knexModule.knex('rpcpermissions')
|
261
|
|
- .where('rpcname', '=', permission.rpcname)
|
|
266
|
+ .where(<SomeOf<RPCPermission>>{
|
|
267
|
+ rpcname: permission.rpcname
|
|
268
|
+ })
|
262
|
269
|
.update(permission)
|
263
|
270
|
|
264
|
271
|
await Promise.all(
|
|
@@ -276,7 +283,9 @@ export class UserManager
|
276
|
283
|
const perm: RPCPermission = await this.knexModule.knex
|
277
|
284
|
.select(rank)
|
278
|
285
|
.from('rpcpermissions')
|
279
|
|
- .where('rpcname', '=', <string>feature)
|
|
286
|
+ .where(<SomeOf<RPCPermission>>{
|
|
287
|
+ rpcname: feature
|
|
288
|
+ })
|
280
|
289
|
.first()
|
281
|
290
|
|
282
|
291
|
if (!perm) return false
|
|
@@ -312,9 +321,7 @@ export class UserManager
|
312
|
321
|
//getLogger('UserManager#adminLogout#kick').debug(String(e))
|
313
|
322
|
}
|
314
|
323
|
})
|
315
|
|
- this.allowed = this.allowed.filter(allowed => {
|
316
|
|
- return allowed != token
|
317
|
|
- })
|
|
324
|
+ this.allowed = this.allowed.filter(allowed => allowed != token)
|
318
|
325
|
delete this.userConnections[username]
|
319
|
326
|
}
|
320
|
327
|
} catch (e) {
|
|
@@ -342,9 +349,7 @@ export class UserManager
|
342
|
349
|
throw new Error('login failed')
|
343
|
350
|
}
|
344
|
351
|
|
345
|
|
- getUserRecordByToken(tokenValue: string) {
|
346
|
|
- return Object.entries(this.userConnections).find(([k, v]) => v.token.value === tokenValue)
|
347
|
|
- }
|
|
352
|
+ getUserRecordByToken = (tokenValue: string) : [string, UserRecord] => Object.entries(this.userConnections).find(([k, v]) => v.token.value === tokenValue)
|
348
|
353
|
|
349
|
354
|
getToken = (tokenValue: string): Token | void => {
|
350
|
355
|
const [username, userRecord] = this.getUserRecordByToken(tokenValue)
|