-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathreset-password.component.ts
More file actions
189 lines (171 loc) · 5.5 KB
/
Copy pathreset-password.component.ts
File metadata and controls
189 lines (171 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { ConfirmationService } from '../core/services/confirmation.service';
import { AuthService } from '../core/services';
import { SessionStorageService } from 'Common-UI/src/registrar/services/session-storage.service';
@Component({
selector: 'app-reset-password',
templateUrl: './reset-password.component.html',
styleUrls: ['./reset-password.component.css'],
})
export class ResetPasswordComponent {
constructor(
private router: Router,
private authService: AuthService,
private confirmationService: ConfirmationService,
readonly sessionstorage: SessionStorageService,
) {}
public response: any;
public error: any;
showQuestions = false;
hideOnGettingQuestions = true;
securityQuestions: any;
answer: any = undefined;
userID: any;
dynamictype: any = 'password';
public questionId: any[] = [];
public questions: any[] = [];
public userAnswers: any[] = [];
userFinalAnswers: any[] = [];
wrong_answer_msg: any = '';
getQuestions(username: any) {
this.sessionstorage.setItem('userName', username);
this.authService.getUserSecurityQuestionsAnswer(username).subscribe(
(response: any) => {
if (response !== undefined && response !== null)
this.handleSuccess(response.data);
},
(error: any) => (this.error = <any>error),
);
}
handleSuccess(data: any) {
console.log(data);
if (
data !== undefined &&
data !== null &&
data.forgetPassword !== 'user Not Found'
) {
if (data.SecurityQuesAns.length > 0) {
this.securityQuestions = data.SecurityQuesAns;
this.showQuestions = true;
this.hideOnGettingQuestions = false;
this.splitQuestionAndQuestionID();
} else {
this.logout();
this.confirmationService.alert(
'Questions are not set for this user',
'error',
);
}
} else {
this.logout();
}
}
showPWD() {
this.dynamictype = 'text';
}
hidePWD() {
this.dynamictype = 'password';
}
splitQuestionAndQuestionID() {
console.log('Q n A', this.securityQuestions);
for (let i = 0; i < this.securityQuestions.length; i++) {
this.questions.push(this.securityQuestions[i].question);
this.questionId.push(this.securityQuestions[i].questionId);
}
console.log('questions', this.questions);
console.log('questionID', this.questionId);
this.showMyQuestion();
}
bufferQuestionId: any;
bufferQuestion: any;
counter = 0;
showMyQuestion() {
console.log('this is question' + (this.counter + 1));
this.bufferQuestion = this.questions[this.counter];
this.bufferQuestionId = this.questionId[this.counter];
}
nextQuestion() {
if (this.counter < 3) {
const reqObj = {
questionId: this.questionId[this.counter],
answer: this.answer,
};
this.userFinalAnswers.push(reqObj);
this.wrong_answer_msg = '';
this.counter = this.counter + 1;
if (this.counter < 3) {
this.showMyQuestion();
this.answer = undefined;
} else {
this.checking();
}
}
console.log('user Final Answers are:', this.userFinalAnswers);
}
checking() {
this.authService
.validateSecurityQuestionAndAnswer(
this.userFinalAnswers,
this.sessionstorage.getItem('userName'),
)
.subscribe(
(response) => {
if (response !== undefined && response !== null) {
if (response.statusCode === 200) {
this.counter = 0;
this.router.navigate(['/set-password']);
this.authService.transactionId = response.data.transactionId;
} else {
this.showQuestions = true;
this.counter = 0;
this.confirmationService.alert(response.errorMessage, 'error');
this.getQuestions(this.sessionstorage.getItem('userName'));
this.router.navigate(['/reset-password']);
this.splitQuestionAndQuestionID();
}
}
},
(error) => {
this.showQuestions = true;
this.counter = 0;
this.confirmationService.alert(error.errorMessage, 'error');
this.router.navigate(['/reset-password']);
this.splitQuestionAndQuestionID();
},
);
this.answer = undefined;
this.userFinalAnswers = [];
}
logout() {
this.authService.logout().subscribe((res) => {
this.router.navigate(['/login']).then((result) => {
if (result) {
this.sessionstorage.clear();
sessionStorage.clear();
}
});
});
}
}