change password api #26

Merged
naeem.ullah merged 1 commits from mazdak/UX-1852 into dev-pending-01-01-2026 4 weeks ago

@ -1,8 +1,14 @@
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, forwardRef, Input, Output } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
@Component({ @Component({
selector: 'app-password-hide-show', selector: 'app-password-hide-show',
imports: [], imports: [],
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => PasswordHideShowComponent),
multi: true
}],
templateUrl: './password-hide-show.component.html', templateUrl: './password-hide-show.component.html',
styleUrl: './password-hide-show.component.scss' styleUrl: './password-hide-show.component.scss'
}) })

@ -3,7 +3,7 @@
<div class="inner-pg-sp"> <div class="inner-pg-sp">
<div class="container-fluid"> <div class="container-fluid">
<div *ngIf="isFirstLogin" class="auth-page d-flex align-items-center"> <div *ngIf="isFirstLogin && firstTimeLoginForm" class="auth-page d-flex align-items-center">
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-6 col-lg-5 col-xl-4"> <div class="col-md-6 col-lg-5 col-xl-4">
@ -15,7 +15,7 @@
<h5 class="mb-0 text-dark">{{'changePassword' | translate}}</h5> <h5 class="mb-0 text-dark">{{'changePassword' | translate}}</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<form> <form [formGroup]="firstTimeLoginForm">
<!-- New Password --> <!-- New Password -->
<div class="mb-3"> <div class="mb-3">
@ -23,7 +23,7 @@
{{"newPasswordStatic" | translate}}<span class="mandatory">*</span> {{"newPasswordStatic" | translate}}<span class="mandatory">*</span>
</label> </label>
<div class="input-group auth-pass-inputgroup"> <div class="input-group auth-pass-inputgroup">
<input type="{{passwordType1}}" class="form-control" id="newPassword" <input type="{{passwordType1}}" class="form-control" formControlName="newPassword" id="newPassword"
placeholder="{{'enterNewPassword' | translate}}" appNoWhitespaces> placeholder="{{'enterNewPassword' | translate}}" appNoWhitespaces>
<app-password-hide-show #psh1 [showPassword]="true" <app-password-hide-show #psh1 [showPassword]="true"
(onEyeClick)="togglePasswordType1()"> (onEyeClick)="togglePasswordType1()">
@ -37,7 +37,7 @@
{{"confirmPassword" | translate}}<span class="mandatory">*</span> {{"confirmPassword" | translate}}<span class="mandatory">*</span>
</label> </label>
<div class="input-group auth-pass-inputgroup"> <div class="input-group auth-pass-inputgroup">
<input type="{{passwordType2}}" class="form-control" id="confirmPassword" <input type="{{passwordType2}}" class="form-control" formControlName="confirmPassword" id="confirmPassword"
placeholder="{{'confirmPassword' | translate}}" appNoWhitespaces> placeholder="{{'confirmPassword' | translate}}" appNoWhitespaces>
<app-password-hide-show #psh2 [showPassword]="true" <app-password-hide-show #psh2 [showPassword]="true"
(onEyeClick)="togglePasswordType2()"> (onEyeClick)="togglePasswordType2()">
@ -47,7 +47,7 @@
<!-- Submit Button --> <!-- Submit Button -->
<div class="mt-3 d-grid"> <div class="mt-3 d-grid">
<button class="btn btn-primary waves-effect waves-light" type="button"> <button class="btn btn-primary waves-effect waves-light" (click)="onSubmit()" type="button">
{{'save' | translate}} {{'save' | translate}}
</button> </button>
</div> </div>
@ -60,7 +60,7 @@
</div> </div>
</div> </div>
<div *ngIf="!isFirstLogin" class="full-width-page"> <div *ngIf="!isFirstLogin && changePasswordForm" class="full-width-page">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<div class="d-sm-flex align-items-center justify-content-between navbar-header p-0"> <div class="d-sm-flex align-items-center justify-content-between navbar-header p-0">
@ -115,16 +115,16 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="d-flex align-items-start gap-2"> <div class="d-flex align-items-start gap-2">
<label for="enterNewPassword" <label for="newPassword"
class="text-nowrap mt-2"> class="text-nowrap mt-2">
{{ 'enterNewPassword' | translate }}<span {{ 'enterNewPassword' | translate }}<span
class="mandatory">*</span> class="mandatory">*</span>
</label> </label>
<div class="password-wrapper position-relative w-100"> <div class="password-wrapper position-relative w-100">
<input id="enterNewPassword" <input id="newPassword"
class="form-control" class="form-control"
formControlName="enterNewPassword" formControlName="newPassword"
type="{{passwordType1}}" type="{{passwordType1}}"
maxlength="500" maxlength="500"
placeholder="{{ 'enterNewPassword' | translate }}" appNoWhitespaces placeholder="{{ 'enterNewPassword' | translate }}" appNoWhitespaces

@ -16,6 +16,7 @@ import { StorageService } from '../../shared/services/storage.service';
export class ChangePasswordComponent implements OnInit{ export class ChangePasswordComponent implements OnInit{
isFirstLogin = false; isFirstLogin = false;
firstTimeLoginForm!: FormGroup;
changePasswordForm!: FormGroup; changePasswordForm!: FormGroup;
currentLanguage = new FormControl(); currentLanguage = new FormControl();
httpService: any; httpService: any;
@ -40,7 +41,7 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
} }
passwordMatchValidator(group: AbstractControl): ValidationErrors | null { passwordMatchValidator(group: AbstractControl): ValidationErrors | null {
const newPassword = group.get('enterNewPassword')?.value; const newPassword = group.get('newPassword')?.value;
const confirmPassword = group.get('confirmPassword')?.value; const confirmPassword = group.get('confirmPassword')?.value;
return newPassword === confirmPassword ? null : { passwordMismatch: true }; return newPassword === confirmPassword ? null : { passwordMismatch: true };
} }
@ -48,18 +49,19 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
ngOnInit(): void { ngOnInit(): void {
this.checkIfFirstTimeChangePasswordOrNot(); this.checkIfFirstTimeChangePasswordOrNot();
if (!this.isFirstLogin) { if (this.isFirstLogin) {
this.initChangePasswordForm(); this.firstTimeLoginForm = this.fb.group({
} newPassword: ['', [Validators.required, Validators.minLength(6)]],
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
}, { validators: this.passwordMatchValidator });
} else {
this.changePasswordForm = this.fb.group({ this.changePasswordForm = this.fb.group({
oldPassword: ['', Validators.required], oldPassword: ['', Validators.required],
enterNewPassword: ['',[ Validators.required, Validators.minLength(6)]], newPassword: ['', [Validators.required, Validators.minLength(6)]],
confirmPassword: ['', [Validators.required, Validators.minLength(6)]] confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
}, }, { validators: this.passwordMatchValidator });
{
validators: this.passwordMatchValidator
} }
)
} }
checkIfFirstTimeChangePasswordOrNot(): void { checkIfFirstTimeChangePasswordOrNot(): void {
@ -113,14 +115,18 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
return null; return null;
} }
getFormPayload() {
const form = this.isFirstLogin ? this.firstTimeLoginForm : this.changePasswordForm;
onSubmit(){ return {
if(this.changePasswordForm.invalid){return} oldPassword: form.get('oldPassword')?.value || null,
// confirmPassword: form.get('confirmPassword')?.value || null,
const payload = { newPassword: form.get('newPassword')?.value,
oldPassword: this.changePasswordForm.value.oldPassword, userId: this.storageService.getItem('USER_ID')
newPassword: this.changePasswordForm.value.enterNewPassword };
} }
onSubmit(){
const payload = this.getFormPayload();
this.httpURIService.requestPOST(URIKey.CHANGE_PASSWORD_URI, payload) this.httpURIService.requestPOST(URIKey.CHANGE_PASSWORD_URI, payload)
.subscribe(); .subscribe();

@ -54,7 +54,7 @@
}, },
{ {
"Id" : "ENTITY_CHANGE_PASSWORD_URI", "Id" : "ENTITY_CHANGE_PASSWORD_URI",
"URI": "/user/change-password", "URI": "/authentication/change-password",
"UUID": "CHANGE_PASSWORD_URI" "UUID": "CHANGE_PASSWORD_URI"
}, },
{ {

Loading…
Cancel
Save