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({
selector: 'app-password-hide-show',
imports: [],
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => PasswordHideShowComponent),
multi: true
}],
templateUrl: './password-hide-show.component.html',
styleUrl: './password-hide-show.component.scss'
})

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

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

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

Loading…
Cancel
Save