diff --git a/online-survey-app/src/app/case/services/case.service.ts b/online-survey-app/src/app/case/services/case.service.ts index 20b084ba35..ea8e44d5af 100644 --- a/online-survey-app/src/app/case/services/case.service.ts +++ b/online-survey-app/src/app/case/services/case.service.ts @@ -6,7 +6,6 @@ import { NotificationStatus, Notification, NotificationType } from './../classes import { TangyFormService } from 'src/app/tangy-forms/tangy-form.service'; import { CaseDefinitionsService } from './case-definitions.service'; import { HttpClient } from '@angular/common/http'; -import { UserService } from 'src/app/core/auth/_services/user.service'; // Classes. import { TangyFormResponseModel } from 'tangy-form/tangy-form-response-model.js'; import { Case } from '../classes/case.class' @@ -102,7 +101,6 @@ class CaseService { constructor( private tangyFormService: TangyFormService, private caseDefinitionsService: CaseDefinitionsService, - private userService:UserService, private appConfigService:AppConfigService, private http:HttpClient ) { diff --git a/online-survey-app/src/app/case/services/cases.service.spec.ts b/online-survey-app/src/app/case/services/cases.service.spec.ts index 1ccaee9023..140a520e25 100644 --- a/online-survey-app/src/app/case/services/cases.service.spec.ts +++ b/online-survey-app/src/app/case/services/cases.service.spec.ts @@ -1,7 +1,6 @@ import { TestBed } from '@angular/core/testing'; import { CasesService } from './cases.service'; -import { UserService } from 'src/app/shared/_services/user.service'; import { HttpClientModule } from '@angular/common/http'; import { CaseEventInfo } from './case-event-info.class'; import { CASE_EVENT_STATUS_IN_PROGRESS } from '../classes/case-event.class'; @@ -237,10 +236,6 @@ describe('CasesService', () => { imports:[HttpClientModule], providers: [ {provide:CasesService, useClass:MockCasesService}, - { - provide: UserService, - useClass: MockUserService - } ] })); diff --git a/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.css b/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.css deleted file mode 100644 index 7e475170aa..0000000000 --- a/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.css +++ /dev/null @@ -1,9 +0,0 @@ -form { - margin: 20px; -} - -:host() { - - display: block; - padding-right: 45px; -} \ No newline at end of file diff --git a/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.html b/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.html deleted file mode 100644 index 99bdd90ae9..0000000000 --- a/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.html +++ /dev/null @@ -1,59 +0,0 @@ -
-

- {{'Edit User'|translate}} {{user.username}} -

-
- - - - - {{'This Field is Required'|translate}} - - -
-
- - - - {{'This Field is Required'|translate}} - - -
-
- - - - {{'Please enter a valid email address'|translate}} - - -
-
- Update User password? -
-
-
- - - -
-
- - - - {{'Passwords do not match'|translate}} - - -
- - {{statusMessage.message}} - -

- -

-
-
\ No newline at end of file diff --git a/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.spec.ts b/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.spec.ts deleted file mode 100644 index 3702bd7a39..0000000000 --- a/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { EditUserComponent } from './edit-user.component'; - -describe('EditUserComponent', () => { - let component: EditUserComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ EditUserComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(EditUserComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.ts b/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.ts deleted file mode 100644 index d261999573..0000000000 --- a/online-survey-app/src/app/core/auth/_components/edit-user/edit-user.component.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import { User } from '../user-registration/user.model.interface'; -import { UserService } from '../../_services/user.service'; -import { ActivatedRoute, Router } from '@angular/router'; -import { TangyErrorHandler } from 'src/app/shared/_services/tangy-error-handler.service'; -import { _TRANSLATE } from 'src/app/shared/_services/translation-marker'; -import {HttpClient} from "@angular/common/http"; - -@Component({ - selector: 'app-edit-user', - templateUrl: './edit-user.component.html', - styleUrls: ['./edit-user.component.css'] -}) -export class EditUserComponent implements OnInit { - user: User; - updateUserPassword = false; - statusMessage = { type: '', message: '' }; - disableSubmit = false; - passwordIsNotStrong = { type: 'error', message: _TRANSLATE('Password is not strong enough.') }; - incorrectAdminPassword = { type: 'error', message: _TRANSLATE('Incorrect Admin Password') }; - passwordPolicy: string - passwordRecipe: string - constructor( - private userService: UserService, - private route: ActivatedRoute, - private errorHandler: TangyErrorHandler, - private router: Router, - private httpClient: HttpClient - ) { } - - async ngOnInit() { - this.user = await this.userService.getAUserByUsername(this.route.snapshot.paramMap.get('username')) as User; - this.user.password = ''; - this.user.confirmPassword = ''; - try { - const result: any = await this.httpClient.get('/configuration/passwordPolicyConfig').toPromise(); - if(result.T_PASSWORD_POLICY){ - this.passwordPolicy = result.T_PASSWORD_POLICY; - } - if(result.T_PASSWORD_RECIPE){ - this.passwordRecipe = result.T_PASSWORD_RECIPE; - } - } catch (error) { - if (typeof error.status === 'undefined') { - this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.')); - } - } - this.passwordIsNotStrong.message = this.passwordIsNotStrong.message + ' ' + this.passwordRecipe - } - - async editUser() { - try { - if (!this.updateUserPassword) { - this.user.password = null; - this.user.confirmPassword = null; - } - const policy = new RegExp(this.passwordPolicy) - if (!policy.test(this.user.password)) { - this.statusMessage = this.passwordIsNotStrong - // this.disableSubmit = true - // this.errorHandler.handleError(this.passwordIsNotStrong.message); - return - } else { - // Clear out statusMessage is it had been set earlier. - this.statusMessage = { type: '', message: '' }; - } - const data = await this.userService.updateUserDetails({...this.user, updateUserPassword: this.updateUserPassword}); - if (data === 200) { - this.errorHandler.handleError(_TRANSLATE('User Details Updated Successfully')); - this.router.navigate(['users']) - } else { - this.errorHandler.handleError(_TRANSLATE('User Details could not be Updated')); - } - } catch (error) { - this.errorHandler.handleError(_TRANSLATE('User Details could not be Updated')); - } - } -} diff --git a/online-survey-app/src/app/core/auth/_components/login/login.component.css b/online-survey-app/src/app/core/auth/_components/login/login.component.css deleted file mode 100644 index e347211a77..0000000000 --- a/online-survey-app/src/app/core/auth/_components/login/login.component.css +++ /dev/null @@ -1,33 +0,0 @@ -mat-card { - width: 300px; - margin: 30px auto; -} -.mat-title { - color: var(--primary-color); - font-size: 1.5em; - font-weight: 400; - font-family: Roboto, 'Helvetica Nue', sans-serif; -} -#logo { - margin-bottom: 15px; -} -mat-placeholder i { - margin-right: 0.075em; -} - -input.mat-input-element { - margin-top: 1em; -} - -.mat-placeholder-required.mat-form-field-required-marker.ng-tns-c6-2 - .mat-form-field-invalid - .mat-form-field-placeholder.mat-accent, -.mat-form-field-invalid - .mat-form-field-placeholder - .mat-form-field-required-marker { - position: relative; - bottom: 1em !important; -} -.mat-form-field { - width: 100%; -} diff --git a/online-survey-app/src/app/core/auth/_components/login/login.component.html b/online-survey-app/src/app/core/auth/_components/login/login.component.html deleted file mode 100644 index 839e51e028..0000000000 --- a/online-survey-app/src/app/core/auth/_components/login/login.component.html +++ /dev/null @@ -1,31 +0,0 @@ - - Loading... - - -
- - - - - face - {{'Username'|translate}} - - -
- - - - lock_open - {{'Password'|translate}} - - -
- - - {{'Register'|translate}} - - {{errorMessage}} - -
-
- \ No newline at end of file diff --git a/online-survey-app/src/app/core/auth/_components/login/login.component.spec.ts b/online-survey-app/src/app/core/auth/_components/login/login.component.spec.ts deleted file mode 100644 index d6d85a8465..0000000000 --- a/online-survey-app/src/app/core/auth/_components/login/login.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { LoginComponent } from './login.component'; - -describe('LoginComponent', () => { - let component: LoginComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ LoginComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(LoginComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/online-survey-app/src/app/core/auth/_components/login/login.component.ts b/online-survey-app/src/app/core/auth/_components/login/login.component.ts deleted file mode 100644 index 4194829b0d..0000000000 --- a/online-survey-app/src/app/core/auth/_components/login/login.component.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; -import { AuthenticationService } from '../../_services/authentication.service'; -import { _TRANSLATE } from 'src/app/shared/_services/translation-marker'; - - -@Component({ - selector: 'login', - templateUrl: './login.component.html', - styleUrls: ['./login.component.css'] -}) -export class LoginComponent implements OnInit { - - errorMessage = ''; - returnUrl: string; // stores the value of the url to redirect to after login - user = { username: '', password: '' }; - @ViewChild('customLoginMarkup', {static: true}) customLoginMarkup: ElementRef; - ready = false - - constructor( - private authenticationService: AuthenticationService, - private route: ActivatedRoute, - private router: Router, - ) { } - - async ngOnInit() { - this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || 'forms-list'; - - if (await this.authenticationService.isLoggedIn()) { - this.router.navigate([this.returnUrl]); - return; - } - this.customLoginMarkup.nativeElement.innerHTML = await this.authenticationService.getCustomLoginMarkup() - this.ready = true - } - async loginUser() { - try { - - if (window.location.origin.startsWith('http://localhost')) { - // If we are running on localhost, we want to use the local server for authentication - sessionStorage.setItem(this.user.username, this.user.password); - this.router.navigate([this.returnUrl]); - } else if (await this.authenticationService.login(this.user.username, this.user.password)) { - this.router.navigate([this.returnUrl]); - } else { - this.errorMessage = _TRANSLATE('Login Unsuccesful'); - } - } catch (error) { - this.errorMessage = _TRANSLATE('Login Unsuccesful'); - console.error(error); - } - } - -} diff --git a/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.css b/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.css deleted file mode 100644 index 09e9b04a15..0000000000 --- a/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.css +++ /dev/null @@ -1,4 +0,0 @@ -#container { - margin: 0px 15px; - -} \ No newline at end of file diff --git a/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.html b/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.html deleted file mode 100644 index dea5885145..0000000000 --- a/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.html +++ /dev/null @@ -1,68 +0,0 @@ -

- {{'Edit User'|translate }} {{user.username}} -

- -

- {{'Edit User'|translate }} -

-
-
-
- - - - - {{'This Field is Required'|translate}} - - -
-
- - - - {{'This Field is Required'|translate}} - - -
-
- - - - {{'Please enter a valid email address'|translate}} - - -
-
- Update User password? -
-
-
- - - - - - -
-
- - - - {{'Passwords do not match'|translate}} - - -
- - {{statusMessage.message}} - -

- -

-
-
\ No newline at end of file diff --git a/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.spec.ts b/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.spec.ts deleted file mode 100644 index e3bb688e39..0000000000 --- a/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { UpdatePersonalProfileComponent } from './update-personal-profile.component'; - -describe('UpdatePersonalProfileComponent', () => { - let component: UpdatePersonalProfileComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ UpdatePersonalProfileComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(UpdatePersonalProfileComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.ts b/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.ts deleted file mode 100644 index 12dee61574..0000000000 --- a/online-survey-app/src/app/core/auth/_components/update-personal-profile/update-personal-profile.component.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { Router } from '@angular/router'; -import { Component, OnInit } from '@angular/core'; -import { MenuService } from 'src/app/shared/_services/menu.service'; -import { _TRANSLATE } from 'src/app/shared/_services/translation-marker'; -import { UserService } from '../../_services/user.service'; -import { User } from '../user-registration/user.model.interface'; -import { TangyErrorHandler } from 'src/app/shared/_services/tangy-error-handler.service'; -import {HttpClient} from "@angular/common/http"; - -@Component({ - selector: 'app-update-personal-profile', - templateUrl: './update-personal-profile.component.html', - styleUrls: ['./update-personal-profile.component.css'] -}) -export class UpdatePersonalProfileComponent implements OnInit { - - user; - updateUserPassword = false; - statusMessage = { type: '', message: '' }; - disableSubmit = false; - passwordIsNotStrong = { type: 'error', message: _TRANSLATE('Password is not strong enough.') }; - incorrectAdminPassword = { type: 'error', message: _TRANSLATE('Incorrect Admin Password') }; - passwordPolicy: string - passwordRecipe: string - config:any = { enabledModules: [] } - - constructor( - private menuService: MenuService, - private userService: UserService, - private errorHandler: TangyErrorHandler, - private router: Router, - private httpClient: HttpClient - ) { } - - async ngOnInit() { - this.menuService.setContext(_TRANSLATE('Update My Profile')); - this.user = await this.userService.getMyUser(); - this.user.password = ''; - this.user.confirmPassword = ''; - try { - const result: any = await this.httpClient.get('/configuration/passwordPolicyConfig').toPromise(); - if(result.T_PASSWORD_POLICY){ - this.passwordPolicy = result.T_PASSWORD_POLICY; - } - if(result.T_PASSWORD_RECIPE){ - this.passwordRecipe = result.T_PASSWORD_RECIPE; - } - } catch (error) { - if (typeof error.status === 'undefined') { - this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.')); - } - } - this.passwordIsNotStrong.message = this.passwordIsNotStrong.message + ' ' + this.passwordRecipe - } - async editUser() { - this.statusMessage = { type: '', message: '' }; - try { - if (!this.updateUserPassword) { - this.user.password = null; - this.user.confirmPassword = null; - this.user.currentPassword = null; - } - - // const policy = new RegExp('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})'); - const policy = new RegExp(this.passwordPolicy) - if (!policy.test(this.user.password)) { - this.statusMessage = this.passwordIsNotStrong - // this.disableSubmit = true - // this.errorHandler.handleError(this.passwordIsNotStrong.message); - return - } else { - // Clear out statusMessage is it had been set earlier. - this.statusMessage = { type: '', message: '' }; - } - - const data = await this.userService.updateMyUser({...this.user, updateUserPassword: this.updateUserPassword}); - if (data === 200) { - this.errorHandler.handleError(_TRANSLATE('User Details Updated Successfully')); - this.router.navigate(['/']) - } else { - this.errorHandler.handleError(_TRANSLATE('User Details could not be Updated')); - } - } catch (error) { - this.errorHandler.handleError(_TRANSLATE('User Details could not be Updated')); - } - } -} diff --git a/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.css b/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.css deleted file mode 100644 index 03834b16a8..0000000000 --- a/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.css +++ /dev/null @@ -1,16 +0,0 @@ -.tangy-input-width{ - width: 80%; -} - -p { - margin: 15px; -} - -mat-checkbox{ - display: block; - margin: 0 10px; -} - -button { - margin-left: 15px; -} diff --git a/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.html b/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.html deleted file mode 100644 index 81450a32a7..0000000000 --- a/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.html +++ /dev/null @@ -1,16 +0,0 @@ - -
-
-

{{'Update Role of' | translate}}: {{username}}

- -
-

- - {{role.role}} - -

-

{{'No Roles exist yet. '|translate}}

- -
\ No newline at end of file diff --git a/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.spec.ts b/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.spec.ts deleted file mode 100644 index 1db6f21c83..0000000000 --- a/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { UpdateUserRoleComponent } from './update-user-role.component'; - -describe('UpdateUserRoleComponent', () => { - let component: UpdateUserRoleComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ UpdateUserRoleComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(UpdateUserRoleComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.ts b/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.ts deleted file mode 100644 index 497de34091..0000000000 --- a/online-survey-app/src/app/core/auth/_components/update-user-role/update-user-role.component.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { Component, OnInit, AfterViewInit, ElementRef, ViewChild } from '@angular/core'; -import { Breadcrumb } from 'src/app/shared/_components/breadcrumb/breadcrumb.component'; -import { _TRANSLATE } from 'src/app/shared/_services/translation-marker'; -import { ActivatedRoute, Router } from '@angular/router'; -import { GroupsService } from 'src/app/groups/services/groups.service'; -import { UserService } from '../../_services/user.service'; -import { TangyErrorHandler } from 'src/app/shared/_services/tangy-error-handler.service'; -import { AuthenticationService } from '../../_services/authentication.service'; - -@Component({ - selector: 'app-update-user-role', - templateUrl: './update-user-role.component.html', - styleUrls: ['./update-user-role.component.css'] -}) -export class UpdateUserRoleComponent implements OnInit { - - user; - username; - role; - groupId; - title = _TRANSLATE('Update User\'s roles'); - breadcrumbs: Array = []; - allRoles; - myGroup; - @ViewChild('search', { static: false }) search: ElementRef; - constructor( - private route: ActivatedRoute, - private groupsService: GroupsService, - private usersService: UserService, - private errorHandler: TangyErrorHandler, - private router: Router, - private authenticationService: AuthenticationService - ) { } - - async ngOnInit() { - this.breadcrumbs = [ - { - label: _TRANSLATE('Security'), - url: `security` - }, - { - label: _TRANSLATE(`Update User's Roles`), - url: `security/assign-role` - } - ]; - this.username = this.route.snapshot.paramMap.get('username'); - this.groupId = this.route.snapshot.paramMap.get('groupId'); - this.allRoles = await this.authenticationService.getAllRoles(this.groupId); - this.user = await this.usersService.getAUserByUsername(this.username); - this.myGroup = this.user.groups.find(g => g.groupName === this.groupId); - this.myGroup.roles = this.myGroup?.roles ?? []; - this.role = { groupName: this.groupId, roles: this.myGroup.roles }; - } - - async addUserToGroup() { - try { - await this.groupsService.addUserToGroup(this.groupId, this.username, this.role); - this.errorHandler.handleError(_TRANSLATE('User Added to Group Successfully')); - this.router.navigate([`groups/${this.groupId}`]); - } catch (error) { - console.log(error); - } - } - - doesUserHaveRole(role) { - return this.myGroup.roles.indexOf(role) >= 0; - } - onSelectChange(role, value) { - if (value) { - this.role.roles = [...new Set([...this.role.roles, role])]; - } else { - this.role.roles = this.role.roles.filter(perm => perm !== role); - } - } - -} diff --git a/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.css b/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.css deleted file mode 100644 index 6c157bdf31..0000000000 --- a/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.css +++ /dev/null @@ -1,3 +0,0 @@ -.tangy-full-width { - width: 98%; -} diff --git a/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.html b/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.html deleted file mode 100644 index f80e1a10f4..0000000000 --- a/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.html +++ /dev/null @@ -1,70 +0,0 @@ -
- - - {{'Add New User'|translate}} - - -
- - -
-
- - {{'Username Unavailable'|translate}} - {{'Username Available'|translate}} - - {{'This Field is Required'|translate}} - - -
-
-
- - - - - {{'This Field is Required'|translate}} - - -
-
- - - - {{'This Field is Required'|translate}} - - -
-
- - - - {{'Please enter a valid email address'|translate}} - - -
-
- - - -
-
- - - - {{'Passwords do not match'|translate}} - - -
-
- -
-
-
-
\ No newline at end of file diff --git a/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.spec.ts b/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.spec.ts deleted file mode 100644 index 39b3cb325f..0000000000 --- a/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { UserRegistrationComponent } from './user-registration.component'; - -describe('UserRegistrationComponent', () => { - let component: UserRegistrationComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ UserRegistrationComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(UserRegistrationComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.ts b/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.ts deleted file mode 100644 index 48bd0d4359..0000000000 --- a/online-survey-app/src/app/core/auth/_components/user-registration/user-registration.component.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { Component, OnInit, AfterContentInit } from '@angular/core'; -import { TangyErrorHandler } from 'src/app/shared/_services/tangy-error-handler.service'; -import { _TRANSLATE } from 'src/app/shared/_services/translation-marker'; -import { UserService } from '../../_services/user.service'; -import { User } from './user.model.interface'; -import {ActivatedRoute} from '@angular/router'; - - -@Component({ - selector: 'app-user-registration', - templateUrl: './user-registration.component.html', - styleUrls: ['./user-registration.component.css'] -}) -export class UserRegistrationComponent implements OnInit, AfterContentInit { - - user: User = { - username: '', - password: '', - email: '', - firstName: '', - lastName: '' - }; - userExists: boolean = null; - userNameUnavailableMessage = { type: 'error', message: _TRANSLATE('Username Unavailable') }; - userNameAvailableMessage = { type: 'success', message: _TRANSLATE('Username Available') }; - couldNotCreateUserMessage = { type: 'error', message: _TRANSLATE('Could Not Create User') }; - id: string; - - constructor(private userService: UserService, private errorHandler: TangyErrorHandler, private route: ActivatedRoute) { } - - ngOnInit() { - } - - async ngAfterContentInit() { - this.route.params.subscribe(async params => { - this.id = params.id; - // await this.userService.doesUserExist(this.id); - }) - } - - async createUser() { - try { - delete this.user.confirmPassword; - const userData = Object.assign({}, this.user); - if (!(await this.doesUserExist(this.user.username))) { - const result: any = await this.userService.createUser(userData); - if (result && result.statusCode && result.statusCode === 200) { - this.errorHandler.handleError(_TRANSLATE('User Created Succesfully')); - this.user = { - username: '', - password: '', - email: '', - firstName: '', - lastName: '' - }; - } else { - this.errorHandler.handleError(_TRANSLATE('Could Not Create User')); - } - return result; - } - } catch (error) { - this.errorHandler.handleError(_TRANSLATE('Could Not Create User')); - } - } - - async doesUserExist(username: string) { - try { - this.user.username = username.replace(/\s/g, ''); // Remove all whitespaces including spaces and tabs - if (this.user.username.length > 0) { - this.userExists = await this.userService.doesUserExist(username); - return this.userExists; - } else { - this.userExists = null; - return this.userExists; - } - } catch (error) { - console.error(error); - } - } - -} diff --git a/online-survey-app/src/app/core/auth/_components/user-registration/user.model.interface.ts b/online-survey-app/src/app/core/auth/_components/user-registration/user.model.interface.ts deleted file mode 100644 index 3346f356e9..0000000000 --- a/online-survey-app/src/app/core/auth/_components/user-registration/user.model.interface.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface User { - username: string; - password: string; - email: string; - firstName:string; - lastName:string; - confirmPassword?: string; -} diff --git a/online-survey-app/src/app/core/auth/_services/authentication.service.ts b/online-survey-app/src/app/core/auth/_services/authentication.service.ts index 1f67df0f17..2f30577f07 100644 --- a/online-survey-app/src/app/core/auth/_services/authentication.service.ts +++ b/online-survey-app/src/app/core/auth/_services/authentication.service.ts @@ -16,25 +16,6 @@ export class AuthenticationService { this.currentUserLoggedIn$ = new Subject(); } - async login(username: string, password: string) { - try { - const data = await this.http.post('/login', {username, password}, {observe: 'response'}).toPromise(); - if (data.status === 200) { - const token = data.body['data']['token']; - await this.setTokens(token); - return true; - } else { - return false; - } - } catch (error) { - console.error(error); - sessionStorage.removeItem('token'); - sessionStorage.removeItem('user_id'); - sessionStorage.removeItem('permissions'); - return false; - } - } - async surveyLogin(accessCode: string) { const appConfig = await this.appConfigService.getAppConfig(); const groupId = appConfig['groupId']; diff --git a/online-survey-app/src/app/core/auth/_services/user.service.spec.ts b/online-survey-app/src/app/core/auth/_services/user.service.spec.ts deleted file mode 100644 index b26195c25d..0000000000 --- a/online-survey-app/src/app/core/auth/_services/user.service.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { TestBed, inject } from '@angular/core/testing'; - -import { UserService } from './user.service'; - -describe('UserService', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [UserService] - }); - }); - - it('should be created', inject([UserService], (service: UserService) => { - expect(service).toBeTruthy(); - })); -}); diff --git a/online-survey-app/src/app/core/auth/_services/user.service.ts b/online-survey-app/src/app/core/auth/_services/user.service.ts deleted file mode 100644 index 55c91fd7b1..0000000000 --- a/online-survey-app/src/app/core/auth/_services/user.service.ts +++ /dev/null @@ -1,154 +0,0 @@ -import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; - -import { TangyErrorHandler } from 'src/app/shared/_services/tangy-error-handler.service'; -import { _TRANSLATE } from 'src/app/shared/_services/translation-marker'; - -@Injectable() -export class UserService { - - constructor(private httpClient: HttpClient, private errorHandler: TangyErrorHandler, private http: HttpClient) { } - - async createUser(payload) { - try { - if (!(await this.doesUserExist(payload.username))) { - const result = await this.httpClient.post('/users/register-user', payload).toPromise(); - return result; - } - - } catch (error) { - this.showError(error); - } - - } - - async doesUserExist(username: string) { - try { - const result: any = await this.httpClient.get(`/users/userExists/${username}`).toPromise(); - return result.data; - } catch (error) { - this.showError(error); - - } - } - - async getAllUsers() { - try { - const users: any = await this.httpClient.get('/users').toPromise(); - return users.data; - } catch (error) { - this.showError(error); - - } - } - - async getCurrentUser() { - return await sessionStorage.getItem('user_id'); - } - private showError(error: any) { - console.log(error); - if (typeof error.status === 'undefined') { - this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.')); - } - } - - async canManageSitewideUsers() { - return await this.http.get('/user/permission/can-manage-sitewide-users').toPromise() - } - - async getMyUser() { - try { - if (sessionStorage.getItem('user_id') === 'user1') { - return { - email: 'user1@tangerinecentral.org', - firstName: 'user1', - lastName: 'user1', - username: 'user1', - _id: 'user1' - } - } else { - const data = await this.http.get(`/users/findMyUser/`, {observe: 'response'}).toPromise(); - if (data.status === 200) { - return data.body['data']; - } - } - } catch (error) { - console.error(error); - this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.')); - } - } - - async getAUserByUsername(username) { - try { - const data = await this.http.get(`/users/findOneUser/${username}`, {observe: 'response'}).toPromise(); - if (data.status === 200) { - return data.body['data']; - } - } catch (error) { - console.error(error); - this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.')); - } - } - - async searchUsersByUsername(username: string) { - try { - const data: any = await this.httpClient - .get(`/users/byUsername/${username}`) - .toPromise(); - return data.data; - } catch (error) { - console.error(error); - if (typeof error.status === 'undefined') { - this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.')); - } - } - } - - async deleteUser(username: string) { - try { - const data = await this.http.delete(`/users/delete/${username}`, {observe: 'response'}).toPromise(); - if (data.status === 200) { - return true; - } - } catch (error) { - console.error(error); - return false; - } - } - async restoreUser(username: string) { - try { - const data = await this.http.patch(`/users/restore/${username}`, {isActive: true}, {observe: 'response'}).toPromise(); - if (data.status === 200) { - return true; - } - } catch (error) { - console.error(error); - return false; - } - } - - async updateUserDetails(payload) { - try { - const data = await this.httpClient.put(`/users/update/${payload.username}`, payload, {observe: 'response'}).toPromise(); - if (data.status === 200) { - return data.status; - } - } catch (error) { - console.error(error); - return 500; - } - } - async updateMyUser(payload) { - try { - const data = await this.httpClient.put(`/users/updateMyUser/`, - payload, {observe: 'response'}).toPromise(); - if (data.status === 200) { - return data.status; - } - } catch (error) { - console.error(error); - return 500; - } - } - -} diff --git a/online-survey-app/src/app/core/auth/auth-routing.module.ts b/online-survey-app/src/app/core/auth/auth-routing.module.ts index e0b5fa9b74..1804ab241c 100644 --- a/online-survey-app/src/app/core/auth/auth-routing.module.ts +++ b/online-survey-app/src/app/core/auth/auth-routing.module.ts @@ -1,13 +1,8 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { SurveyLoginComponent } from './_components/survey-login/survey-login.component'; -import { UserRegistrationComponent } from './_components/user-registration/user-registration.component'; const routes: Routes = [ - { - path: 'register-user', - component: UserRegistrationComponent - }, { path: 'survey-login', component: SurveyLoginComponent diff --git a/online-survey-app/src/app/core/auth/auth.module.ts b/online-survey-app/src/app/core/auth/auth.module.ts index 5e6cf3ba04..a6eed353c6 100644 --- a/online-survey-app/src/app/core/auth/auth.module.ts +++ b/online-survey-app/src/app/core/auth/auth.module.ts @@ -10,12 +10,9 @@ import { MatTableModule } from '@angular/material/table'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { SharedModule } from '../../shared/shared.module'; import { AuthRoutingModule } from './auth-routing.module'; -import { LoginComponent } from './_components/login/login.component'; import { SurveyLoginComponent } from './_components/survey-login/survey-login.component'; -import { UserRegistrationComponent } from './_components/user-registration/user-registration.component'; import { LoginGuard } from './_guards/login-guard.service'; import { AuthenticationService } from './_services/authentication.service'; -import { UserService } from './_services/user.service'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatAutocompleteModule } from '@angular/material/autocomplete'; @@ -38,7 +35,7 @@ import { MatAutocompleteModule } from '@angular/material/autocomplete'; MatCheckboxModule ], - declarations: [UserRegistrationComponent, LoginComponent, SurveyLoginComponent], - providers: [AuthenticationService, LoginGuard, UserService] + declarations: [SurveyLoginComponent], + providers: [AuthenticationService, LoginGuard] }) export class AuthModule { }