Feature 11034: Forgot Password in OSM
[osm/NG-UI.git] / src / app / utilities / change-password / ChangePasswordComponent.ts
1 /*
2  Copyright 2020 TATA ELXSI
3
4  Licensed under the Apache License, Version 2.0 (the 'License');
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15
16  Author: SANDHYA JS (sandhya.j@tataelxsi.co.in)
17 */
18 /**
19  * @file change password component
20  */
21 import { Component, Injector, OnInit } from '@angular/core';
22 import { Router } from '@angular/router';
23 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24 import { TranslateService } from '@ngx-translate/core';
25 import { AddEditUserComponent } from 'AddEditUserComponent';
26 import { MODALCLOSERESPONSEDATA } from 'CommonModel';
27 import { SharedService } from 'SharedService';
28
29 /**
30  * Creating component
31  * @Component takes ChangePasswordComponent.html as template url
32  */
33 @Component({
34     templateUrl: './ChangePasswordComponent.html',
35     styleUrls: ['./ChangePasswordComponent.scss']
36 })
37 /** Exporting a class @exports ChangePasswordComponent */
38 export class ChangePasswordComponent implements OnInit {
39     /** To inject services @public */
40     public injector: Injector;
41
42     /** handle translate @public */
43     public translateService: TranslateService;
44
45     /** Contains edit type data @public */
46     public editType: string = 'changePassword';
47
48     /** Contains all methods related to shared @private */
49     private sharedService: SharedService;
50
51     /** Instance of the modal service @private */
52     private modalService: NgbModal;
53
54     /** Holds the instance of router class @private */
55     private router: Router;
56     constructor(injector: Injector) {
57         this.injector = injector;
58         this.translateService = this.injector.get(TranslateService);
59         this.sharedService = this.injector.get(SharedService);
60         this.modalService = this.injector.get(NgbModal);
61         this.router = this.injector.get(Router);
62     }
63
64     /** Lifecyle Hooks the trigger before component is instantiate @public */
65     public ngOnInit(): void {
66         // eslint-disable-next-line security/detect-non-literal-fs-filename
67         const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static', keyboard: false });
68         modalRef.componentInstance.userID = sessionStorage.getItem('user_id');
69         if (this.editType === 'changePassword') {
70             modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
71         }
72         if (this.router.url === '/forgotpassword') {
73             this.editType = 'forgotPassword';
74             modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.FORGOT');
75         }
76         if (this.router.url.startsWith('/forgotpassword/changepassword/')) {
77             this.editType = 'change_password';
78             modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
79         }
80         modalRef.componentInstance.userType = this.editType;
81         modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
82             if (result) {
83                 this.sharedService.callData();
84             }
85         }).catch((err: Error): void => { // catch error
86         });
87     }
88 }