Skip to content

Commit 7b7ca45

Browse files
committed
check for existing user/role
1 parent 9930441 commit 7b7ca45

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

OpenFlow/src/DatabaseConnection.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,20 @@ export class DatabaseConnection {
468468
item = await this.Cleanmembers(item as any, null);
469469
}
470470

471+
if (collectionname === "users" && item._type === "user") {
472+
var u: TokenUser = (item as any);
473+
if (u.username == null || u.username == "") { throw new Error("Username is mandatory"); }
474+
if (u.name == null || u.name == "") { throw new Error("Name is mandatory"); }
475+
var exists = await User.FindByUsername(u.username, TokenUser.rootToken());
476+
if (exists != null) { throw new Error("Access denied"); }
477+
}
478+
if (collectionname === "users" && item._type === "role") {
479+
var r: Role = (item as any);
480+
if (r.name == null || r.name == "") { throw new Error("Name is mandatory"); }
481+
var exists2 = await Role.FindByName(r.name);
482+
if (exists2 != null) { throw new Error("Access denied"); }
483+
}
484+
471485
// var options:CollectionInsertOneOptions = { writeConcern: { w: parseInt((w as any)), j: j } };
472486
var options: CollectionInsertOneOptions = { w: w, j: j };
473487
//var options: CollectionInsertOneOptions = { w: "majority" };
@@ -476,7 +490,7 @@ export class DatabaseConnection {
476490
if (collectionname === "users" && item._type === "user") {
477491
var users: Role = await Role.FindByNameOrId("users", jwt);
478492
users.AddMember(item);
479-
await users.Save(jwt)
493+
await users.Save(jwt);
480494
}
481495
if (collectionname === "users" && item._type === "role") {
482496
item.addRight(item._id, item.name, [Rights.read]);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.416
1+
0.0.417

0 commit comments

Comments
 (0)