From e9d96229bfbfc5106e4e016a0740174223286995 Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 30 Aug 2018 13:17:20 +0200 Subject: [PATCH 1/2] Added create user for admin page --- webapp/src/app/pages/admin/admin.component.ts | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/webapp/src/app/pages/admin/admin.component.ts b/webapp/src/app/pages/admin/admin.component.ts index 239f9ffb..561459dd 100644 --- a/webapp/src/app/pages/admin/admin.component.ts +++ b/webapp/src/app/pages/admin/admin.component.ts @@ -21,6 +21,8 @@ import { }) export class AdminComponent implements OnInit, OnDestroy { + @ViewChild('addOrEditUserModal') addOrEditUserModal: any + private myUser: User; private userToRemove: User; public users: User[] = []; @@ -45,6 +47,11 @@ export class AdminComponent implements OnInit, OnDestroy { private organization: Organization; public organizations: Organization[] = []; + public addUserFlag = true; + private userToAddOrEdit: User = new User(); + public verifyPassword = ''; + public errorMessage = ''; + private userRef: FireLoopRef; private userSub: Subscription; @@ -230,8 +237,50 @@ export class AdminComponent implements OnInit, OnDestroy { }); } - editUser() { + openAddUserModal(): void { + this.userToAddOrEdit = new User(); + this.verifyPassword = ''; + this.addUserFlag = true; + + this.addOrEditUserModal.show(); + } + + verify(): void { + if (this.userToAddOrEdit.password !== this.verifyPassword) { + this.errorMessage = 'Passwords do not match'; + } else { + this.errorMessage = ''; + } + } + + addUser(): void { + console.log('Admin | Try to create user...', this.userToAddOrEdit); + + this.userToAddOrEdit.email = this.userToAddOrEdit.email.toLocaleLowerCase(); + this.userToAddOrEdit.id = null; + this.userToAddOrEdit.createdAt = new Date(); + + this.userRef.create(this.userToAddOrEdit).subscribe((user: User) => { + console.log('Admin | User created', user); + this.getUsers(); + if (this.toast) + this.toasterService.clear(this.toast.toastId, this.toast.toastContainerId); + this.toast = this.toasterService.pop('success', 'Success', 'Account was created successfully.'); + }, (err) => { + if (err.error.statusCode === 422) { + if (this.toast) + this.toasterService.clear(this.toast.toastId, this.toast.toastContainerId); + this.toast = this.toasterService.pop('error', 'Error', 'Email exists.'); + console.log('Admin | Error 422 | Email already taken'); + } else { + if (this.toast) + this.toasterService.clear(this.toast.toastId, this.toast.toastContainerId); + this.toast = this.toasterService.pop('error', 'Error', 'Invalid username or password'); + console.log('Admin | Error | Invalid username or password ', err); + } + }); + this.addOrEditUserModal.hide(); } deleteOrganization(organization: Organization): void { From c2361b4d912f2d8705bef95cd9eac5357caf8704 Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 30 Aug 2018 13:19:21 +0200 Subject: [PATCH 2/2] Added create user for admin page --- .../src/app/pages/admin/admin.component.html | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/webapp/src/app/pages/admin/admin.component.html b/webapp/src/app/pages/admin/admin.component.html index 476bf904..d267e499 100644 --- a/webapp/src/app/pages/admin/admin.component.html +++ b/webapp/src/app/pages/admin/admin.component.html @@ -194,7 +194,7 @@

Users

- @@ -379,6 +379,52 @@

Organizations

+ +