From 61df1a4ac2f1e9e3729efbd48cd1c7f256b6596e Mon Sep 17 00:00:00 2001 From: Mazdak Gibran <141390141+mazdakgibran@users.noreply.github.com> Date: Mon, 5 Jan 2026 11:24:24 +0500 Subject: [PATCH 1/2] creating payload for reset and change password creating payload for reset and change password before the apis are ready --- .../change-password.component.html | 21 +++-- .../change-password.component.ts | 81 ++++++++++++------- .../reset-password.component.html | 59 +++++++------- .../reset-password.component.ts | 81 ++++++++++++++++--- src/app/utils/uri-enums.ts | 4 +- src/assets/data/app.uri.json | 10 +++ src/assets/i18n/Arabic.json | 2 + src/assets/i18n/English.json | 2 + 8 files changed, 188 insertions(+), 72 deletions(-) diff --git a/src/app/user-management/change-password/change-password.component.html b/src/app/user-management/change-password/change-password.component.html index a194aec..644826d 100644 --- a/src/app/user-management/change-password/change-password.component.html +++ b/src/app/user-management/change-password/change-password.component.html @@ -88,7 +88,7 @@
-
+
@@ -100,14 +100,16 @@
- +
+ {{ 'fieldRequired' | translate }} +
@@ -122,6 +124,7 @@ +
+ {{ newPasswordError$ | translate }} +
@@ -145,6 +151,7 @@ +
+ {{ confirmPasswordError$ | translate }} +
@@ -163,7 +173,8 @@
diff --git a/src/app/user-management/change-password/change-password.component.ts b/src/app/user-management/change-password/change-password.component.ts index fb7f0bd..595a91a 100644 --- a/src/app/user-management/change-password/change-password.component.ts +++ b/src/app/user-management/change-password/change-password.component.ts @@ -1,10 +1,13 @@ import { CommonModule } from '@angular/common'; -import { Component, ViewChild } from '@angular/core'; -import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { AbstractControl, FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule, ValidationErrors, Validators } from '@angular/forms'; import { TranslateModule } from '@ngx-translate/core'; import { PasswordHideShowComponent } from '../../shared/components/password-hide-show/password-hide-show.component'; import { StorageService } from '../../shared/services/storage.service'; import { Router } from '@angular/router'; +import { URIService } from '../../app.uri'; +import { HttpURIService } from '../../app.http.uri.service'; +import { URIKey } from '../../utils/uri-enums'; @Component({ selector: 'app-change-password', @@ -13,15 +16,12 @@ import { Router } from '@angular/router'; styleUrl: './change-password.component.scss' }) -export class ChangePasswordComponent{ +export class ChangePasswordComponent implements OnInit{ isFirstLogin = false; - loginForm!: FormGroup; + changePasswordForm!: FormGroup; currentLanguage = new FormControl(); httpService: any; - constructor(private storageService: StorageService, private router: Router){} -onLangChange() { -throw new Error('Method not implemented.'); -} + passwordType: string = 'password'; passwordType1: string = 'password'; passwordType2: string = 'password'; @@ -29,6 +29,7 @@ passwordType2: string = 'password'; @ViewChild('psh') passwordHideShow?: PasswordHideShowComponent; @ViewChild('psh1') passwordHideShow1 ?: PasswordHideShowComponent; @ViewChild('psh2') passwordHideShow2 ?: PasswordHideShowComponent; +constructor(private fb: FormBuilder, private uriService: URIService, private httpURIService: HttpURIService){} togglePasswordType() { this.passwordType = this.passwordHideShow?.showPassword ? 'password' : 'text'; @@ -40,31 +41,53 @@ passwordType2: string = 'password'; this.passwordType2 = this.passwordHideShow2?.showPassword ? 'password' : 'text'; } - ngOnInit(): void { - // Call the method to check if first-time login - this.checkIfFirstTimeChangePasswordOrNot(); + passwordMatchValidator(group: AbstractControl): ValidationErrors | null { + const newPassword = group.get('enterNewPassword')?.value; + const confirmPassword = group.get('confirmPassword')?.value; + return newPassword === confirmPassword ? null : { passwordMismatch: true }; + } + + ngOnInit(): void { + this.changePasswordForm = this.fb.group({ + oldPassword: ['', Validators.required], + enterNewPassword: ['',[ Validators.required, Validators.minLength(6)]], + confirmPassword: ['', [Validators.required, Validators.minLength(6)]] + }, + { + validators: this.passwordMatchValidator + } + ) + } + get newPasswordError$() { + const control = this.changePasswordForm.get('newPassword'); + if (!control || !control.touched) return null; + + if (control.hasError('required')) return 'fieldRequired'; + if (control.hasError('minlength')) return 'passwordTooShort'; + return null; + } + + get confirmPasswordError$() { + const control = this.changePasswordForm.get('confirmPassword'); + if (!control || !control.touched) return null; + + if (control.hasError('required')) return 'fieldRequired'; + if (control.hasError('minlength')) return 'passwordTooShort'; + if (this.changePasswordForm.hasError('passwordMismatch')) return 'passwordsDoNotMatch'; + + return null; } - checkIfFirstTimeChangePasswordOrNot() { - const fromMenu = history.state?.['fromMenu']; + onSubmit(){ + if(this.changePasswordForm.invalid){return} - if (fromMenu) { - this.isFirstLogin = false; - } else { - try { - const currentUser: any = JSON.parse(this.storageService.getItem('user') || '{}'); - - // Check if user exists and has isFirstLogin flag - if (currentUser?.user?.isFirstLogin) { - this.isFirstLogin = true; - } else { - this.isFirstLogin = false; - } - } catch (error) { - console.error('Error parsing user data:', error); - this.isFirstLogin = false; - } + const payload = { + oldPassword: this.changePasswordForm.value.oldPassword, + newPassword: this.changePasswordForm.value.enterNewPassword } + + this.httpURIService.requestPOST(URIKey.CHANGE_PASSWORD_URI, payload) + .subscribe(); } } diff --git a/src/app/user-management/reset-password/reset-password.component.html b/src/app/user-management/reset-password/reset-password.component.html index 077c8bc..0c3ccaf 100644 --- a/src/app/user-management/reset-password/reset-password.component.html +++ b/src/app/user-management/reset-password/reset-password.component.html @@ -22,27 +22,30 @@ {{'resetPassword' | translate}}
- +
-
@@ -53,9 +56,10 @@ {{ 'enterNewPassword' | translate }}* -
- +
+
- + +
+
+ {{ newPasswordError | translate }}
- +
@@ -77,22 +84,20 @@ {{ 'confirmPassword' | translate }}* -
+
+
- +
+
+ {{ confirmPasswordError | translate }} +
+
@@ -103,14 +108,12 @@
-
-
- - +
diff --git a/src/app/user-management/reset-password/reset-password.component.ts b/src/app/user-management/reset-password/reset-password.component.ts index a0272d2..fb412d5 100644 --- a/src/app/user-management/reset-password/reset-password.component.ts +++ b/src/app/user-management/reset-password/reset-password.component.ts @@ -1,26 +1,89 @@ -import { Component, ViewChild } from '@angular/core'; +import { Component, ViewChild, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators, AbstractControl, ValidationErrors, ReactiveFormsModule } from '@angular/forms'; import { TranslateModule } from '@ngx-translate/core'; +import { CommonModule } from '@angular/common'; import { PasswordHideShowComponent } from '../../shared/components/password-hide-show/password-hide-show.component'; +import { URIKey } from '../../utils/uri-enums'; +import { URIService } from '../../app.uri'; +import { HttpURIService } from '../../app.http.uri.service'; @Component({ selector: 'app-reset-password', - imports: [TranslateModule, PasswordHideShowComponent], + imports: [TranslateModule, PasswordHideShowComponent, CommonModule, ReactiveFormsModule], templateUrl: './reset-password.component.html', styleUrl: './reset-password.component.scss' }) -export class ResetPasswordComponent { -passwordType1: string = 'password'; -passwordType2: string = 'password'; +export class ResetPasswordComponent implements OnInit{ + resetPasswordForm!: FormGroup + passwordType1: string = 'password'; + passwordType2: string = 'password'; + @ViewChild('psh1') passwordHideShow1?: PasswordHideShowComponent; + @ViewChild('psh2') passwordHideShow2?: PasswordHideShowComponent; + + constructor(private fb: FormBuilder, private uriService: URIService, private httpURIService: HttpURIService){} -@ViewChild('psh1') passwordHideShow1 ?: PasswordHideShowComponent; -@ViewChild('psh2') passwordHideShow2 ?: PasswordHideShowComponent; - + ngOnInit(): void { + this.resetPasswordForm = this.fb.group({ + userId: ['', Validators.required], + newPassword: ['', [Validators.required, Validators.minLength(6)]], + confirmPassword: ['', [Validators.required, Validators.minLength(6)]] + }, + { + validators: this.passwordMatchValidator + } + ); + this.resetPasswordForm.get('newPassword')?.valueChanges.subscribe(()=>{ + this.resetPasswordForm.get('confirmPassword')?.updateValueAndValidity(); + }); + + } togglePasswordType1() { this.passwordType1 = this.passwordHideShow1?.showPassword ? 'password' : 'text'; } - togglePasswordType2() { + togglePasswordType2() { this.passwordType2 = this.passwordHideShow2?.showPassword ? 'password' : 'text'; } + passwordMatchValidator(group: AbstractControl): ValidationErrors | null { + const newPassword = group.get('newPassword')?.value; + const confirmPassword = group.get('confirmPassword')?.value; + + return newPassword === confirmPassword ? null : { passwordMismatch: true }; + } + + get newPasswordError() { + const control = this.resetPasswordForm.get('newPassword'); + if (!control || !control.touched) return null; + + if (control.hasError('required')) return 'fieldRequired'; + if (control.hasError('minlength')) return 'passwordTooShort'; + return null; + } + + get confirmPasswordError() { + const control = this.resetPasswordForm.get('confirmPassword'); + if (!control || !control.touched) return null; + + if (control.hasError('required')) return 'fieldRequired'; + if (control.hasError('minlength')) return 'passwordTooShort'; + if (this.resetPasswordForm.hasError('passwordMismatch')) return 'passwordsDoNotMatch'; + + return null; + } + + onSubmit() { + if (this.resetPasswordForm.invalid) return; + + const payload = { + userId: this.resetPasswordForm.value.userId, + newPassword: this.resetPasswordForm.value.newPassword + }; + this.httpURIService.requestPOST(URIKey.RESET_PASSWORD_URI, payload) + .subscribe(); + + } + + } + diff --git a/src/app/utils/uri-enums.ts b/src/app/utils/uri-enums.ts index c0feff2..2d1957c 100644 --- a/src/app/utils/uri-enums.ts +++ b/src/app/utils/uri-enums.ts @@ -8,5 +8,7 @@ export enum URIKey { DELETE_USER = 'DELETE_USER', USER_SAVE_PERMISSION = "USER_SAVE_PERMISSION", USER_GET_PERMISSIONS = "USER_GET_PERMISSIONS", - GET_ALL_USER_URI = "GET_ALL_USER_URI" + GET_ALL_USER_URI = "GET_ALL_USER_URI", + RESET_PASSWORD_URI = "RESET_PASSWORD_URI", + CHANGE_PASSWORD_URI = "CHANGE_PASSWORD_URI" } \ No newline at end of file diff --git a/src/assets/data/app.uri.json b/src/assets/data/app.uri.json index 65e93ab..6dbded8 100644 --- a/src/assets/data/app.uri.json +++ b/src/assets/data/app.uri.json @@ -46,6 +46,16 @@ "Id" : "ENTITY_USER_GET_PERMISSIONS", "URI": "/user/getPermissions", "UUID": "USER_GET_PERMISSIONS" + }, + { + "Id" : "ENTITY_RESET_PASSWORD_URI", + "URI": "/user/reset-password", + "UUID": "RESET_PASSWORD_URI" + }, + { + "Id" : "ENTITY_CHANGE_PASSWORD_URI", + "URI": "/user/change-password", + "UUID": "CHANGE_PASSWORD_URI" } ] } diff --git a/src/assets/i18n/Arabic.json b/src/assets/i18n/Arabic.json index 397f143..921b18e 100644 --- a/src/assets/i18n/Arabic.json +++ b/src/assets/i18n/Arabic.json @@ -7,6 +7,8 @@ "defaultPassword": "كلمة المرور الافتراضية", "rememberMe":"تذكرنى", "forgotPassword":"هل نسيت كلمة السر؟", + "passwordTooShort": "كلمة المرور قصيرة جدًا.", + "passwordsDoNotMatch": "كلمتا المرور غير متطابقتين.", "login":"تسجيل الدخول", "dashboardTitle":"لوحة القيادة", "passwordChangeRequired": "تغيير كلمة المرور مطلوب", diff --git a/src/assets/i18n/English.json b/src/assets/i18n/English.json index 6434080..0ee620c 100644 --- a/src/assets/i18n/English.json +++ b/src/assets/i18n/English.json @@ -136,6 +136,8 @@ "passwordPatternNotMatched":"Password Pattern Not Matched", "successDeleted":"Successfully Deleted", "passwordNotSame":"Password Cannot be same as Old Password", + "passwordTooShort": "Password is too short.", + "passwordsDoNotMatch": "Passwords do not match.", "SuccessSave":"Successfully Saved", "SuccessFind":"Successfully Find", "customerAlreadyUnblocked": "Customer Already UnBlocked", -- 2.32.0 From ba5ca98da9722ff8568676d33e0ee40304b4cd01 Mon Sep 17 00:00:00 2001 From: Mazdak Gibran <141390141+mazdakgibran@users.noreply.github.com> Date: Mon, 5 Jan 2026 12:22:04 +0500 Subject: [PATCH 2/2] removed unused imports --- .../change-password/change-password.component.ts | 5 +---- .../reset-password/reset-password.component.ts | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/app/user-management/change-password/change-password.component.ts b/src/app/user-management/change-password/change-password.component.ts index 595a91a..423cdd4 100644 --- a/src/app/user-management/change-password/change-password.component.ts +++ b/src/app/user-management/change-password/change-password.component.ts @@ -3,9 +3,6 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { AbstractControl, FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule, ValidationErrors, Validators } from '@angular/forms'; import { TranslateModule } from '@ngx-translate/core'; import { PasswordHideShowComponent } from '../../shared/components/password-hide-show/password-hide-show.component'; -import { StorageService } from '../../shared/services/storage.service'; -import { Router } from '@angular/router'; -import { URIService } from '../../app.uri'; import { HttpURIService } from '../../app.http.uri.service'; import { URIKey } from '../../utils/uri-enums'; @@ -29,7 +26,7 @@ passwordType2: string = 'password'; @ViewChild('psh') passwordHideShow?: PasswordHideShowComponent; @ViewChild('psh1') passwordHideShow1 ?: PasswordHideShowComponent; @ViewChild('psh2') passwordHideShow2 ?: PasswordHideShowComponent; -constructor(private fb: FormBuilder, private uriService: URIService, private httpURIService: HttpURIService){} +constructor(private fb: FormBuilder, private httpURIService: HttpURIService){} togglePasswordType() { this.passwordType = this.passwordHideShow?.showPassword ? 'password' : 'text'; diff --git a/src/app/user-management/reset-password/reset-password.component.ts b/src/app/user-management/reset-password/reset-password.component.ts index fb412d5..c810314 100644 --- a/src/app/user-management/reset-password/reset-password.component.ts +++ b/src/app/user-management/reset-password/reset-password.component.ts @@ -4,7 +4,6 @@ import { TranslateModule } from '@ngx-translate/core'; import { CommonModule } from '@angular/common'; import { PasswordHideShowComponent } from '../../shared/components/password-hide-show/password-hide-show.component'; import { URIKey } from '../../utils/uri-enums'; -import { URIService } from '../../app.uri'; import { HttpURIService } from '../../app.http.uri.service'; @Component({ @@ -21,7 +20,7 @@ export class ResetPasswordComponent implements OnInit{ @ViewChild('psh1') passwordHideShow1?: PasswordHideShowComponent; @ViewChild('psh2') passwordHideShow2?: PasswordHideShowComponent; - constructor(private fb: FormBuilder, private uriService: URIService, private httpURIService: HttpURIService){} + constructor(private fb: FormBuilder, private httpURIService: HttpURIService){} ngOnInit(): void { this.resetPasswordForm = this.fb.group({ -- 2.32.0