-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #318 from e-picsa/ft-password-reset
Feat Enable Password Reset
- Loading branch information
Showing
11 changed files
with
225 additions
and
37 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
apps/picsa-apps/dashboard/src/app/modules/climate/components/api-status/api-status.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...apps/dashboard/src/app/modules/profile/pages/password-reset/password-reset.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="page-content"> | ||
<h2>Password Reset</h2> | ||
<p>Please enter the new password.</p> | ||
<form [formGroup]="form"> | ||
<mat-form-field> | ||
<mat-label>Password</mat-label> | ||
<input type="password" matInput autocomplete="picsa-password" formControlName="password" /> | ||
</mat-form-field> | ||
<mat-form-field> | ||
<mat-label>Confirm Password</mat-label> | ||
<input type="password" matInput autocomplete="picsa-password" formControlName="confirmPassword" /> | ||
</mat-form-field> | ||
<button mat-button [disabled]="!form.valid || form.disabled" (click)="handlePasswordReset()">Reset Password</button> | ||
</form> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
...apps/dashboard/src/app/modules/profile/pages/password-reset/password-reset.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
mat-form-field { | ||
display: block; | ||
max-width: 30rem; | ||
} | ||
input.mat-mdc-input-element.mdc-text-field__input { | ||
font-size: 16px; | ||
height: 48px; | ||
} |
22 changes: 22 additions & 0 deletions
22
...s/dashboard/src/app/modules/profile/pages/password-reset/password-reset.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { PasswordResetComponent } from './password-reset.component'; | ||
|
||
describe('PasswordResetComponent', () => { | ||
let component: PasswordResetComponent; | ||
let fixture: ComponentFixture<PasswordResetComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [PasswordResetComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(PasswordResetComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
71 changes: 71 additions & 0 deletions
71
...a-apps/dashboard/src/app/modules/profile/pages/password-reset/password-reset.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { | ||
FormControl, | ||
FormGroup, | ||
FormGroupDirective, | ||
FormsModule, | ||
NgForm, | ||
ReactiveFormsModule, | ||
Validators, | ||
} from '@angular/forms'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { ErrorStateMatcher } from '@angular/material/core'; | ||
import { MatDialogModule } from '@angular/material/dialog'; | ||
import { MatFormFieldModule } from '@angular/material/form-field'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { Router } from '@angular/router'; | ||
import { PicsaNotificationService } from '@picsa/shared/services/core/notification.service'; | ||
import { SupabaseAuthService } from '@picsa/shared/services/core/supabase/services/supabase-auth.service'; | ||
|
||
export class showErrorAfterInteraction implements ErrorStateMatcher { | ||
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { | ||
const isSubmitted = form && form.submitted; | ||
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'dashboard-password-reset.', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
MatButtonModule, | ||
MatDialogModule, | ||
MatFormFieldModule, | ||
MatInputModule, | ||
ReactiveFormsModule, | ||
], | ||
templateUrl: './password-reset.component.html', | ||
styleUrl: './password-reset.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class PasswordResetComponent { | ||
public form = new FormGroup<{ password: FormControl; confirmPassword?: FormControl }>({ | ||
confirmPassword: new FormControl('', [Validators.required]), | ||
password: new FormControl('', Validators.required), | ||
}); | ||
|
||
constructor( | ||
private router: Router, | ||
private supabaseAuthService: SupabaseAuthService, | ||
private notificationService: PicsaNotificationService | ||
) {} | ||
|
||
public async handlePasswordReset() { | ||
if (this.form.value.password !== this.form.value.confirmPassword) { | ||
this.notificationService.showErrorNotification('Make sure your passwords match'); | ||
return; | ||
} | ||
this.form.disable(); | ||
const { error } = await this.supabaseAuthService.resetResetUserPassword(this.form.value.password); | ||
if (error) { | ||
this.form.enable(); | ||
throw new Error(error.message); | ||
} else { | ||
this.notificationService.showSuccessNotification('Password reset successful'); | ||
this.router.navigate(['/login']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters