Feature 10914: Enforce Password change on First login
[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 { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
23 import { TranslateService } from '@ngx-translate/core';
24 import { AddEditUserComponent } from 'AddEditUserComponent';
25 import { MODALCLOSERESPONSEDATA } from 'CommonModel';
26 import { SharedService } from 'SharedService';
27
28 /**
29  * Creating component
30  * @Component takes ChangePasswordComponent.html as template url
31  */
32 @Component({
33     templateUrl: './ChangePasswordComponent.html',
34     styleUrls: ['./ChangePasswordComponent.scss']
35 })
36 /** Exporting a class @exports ChangePasswordComponent */
37 export class ChangePasswordComponent implements OnInit {
38     /** To inject services @public */
39     public injector: Injector;
40
41     /** handle translate @public */
42     public translateService: TranslateService;
43
44     /** Contains edit type data @public */
45     public editType: string = 'changePassword';
46
47     /** Contains all methods related to shared @private */
48     private sharedService: SharedService;
49
50     /** Instance of the modal service @private */
51     private modalService: NgbModal;
52
53     constructor(injector: Injector) {
54         this.injector = injector;
55         this.translateService = this.injector.get(TranslateService);
56         this.sharedService = this.injector.get(SharedService);
57         this.modalService = this.injector.get(NgbModal);
58     }
59
60     /** Lifecyle Hooks the trigger before component is instantiate @public */
61     public ngOnInit(): void {
62         const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static', keyboard: false });
63         modalRef.componentInstance.userID = localStorage.getItem('user_id');
64         if (this.editType === 'changePassword') {
65             modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
66         }
67         modalRef.componentInstance.userType = this.editType;
68         modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
69             if (result) {
70                 this.sharedService.callData();
71             }
72         }).catch((err: Error): void => { // catch error
73         });
74     }
75
76 }