-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added next level feature of also unlocking the page by password user
- Loading branch information
1 parent
2d7ede6
commit 7181091
Showing
10 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
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,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { UnlockService } from './unlock.service'; | ||
|
||
describe('UnlockService', () => { | ||
let service: UnlockService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(UnlockService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
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 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class UnlockService { | ||
|
||
private unlockRequest = new Subject<void>(); | ||
|
||
unlockRequest$ = this.unlockRequest.asObservable(); | ||
|
||
requestUnlock() { | ||
this.unlockRequest.next(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.unlock{ | ||
/* center it horizontally */ | ||
margin: 0 auto; | ||
|
||
} |
8 changes: 5 additions & 3 deletions
8
src/app/password-input-dialog/password-input-dialog.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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<h2 mat-dialog-title>Enter Password</h2> | ||
<mat-dialog-content> | ||
<mat-dialog-content style="display: flex; flex-direction: column; align-items: center;"> | ||
<mat-form-field> | ||
<input matInput [(ngModel)]="password" placeholder="Password" type="password"> | ||
<input matInput [(ngModel)]="password" [type]="passwordFieldType" placeholder="Password"> | ||
<mat-icon matSuffix matTooltip="Toggle Password Visibility" (click)="togglePasswordVisibility()">{{ showPasswordIcon }}</mat-icon> | ||
</mat-form-field> | ||
<mat-icon class="unlock" matTooltip="Unlock the Page" *ngIf="locked" (click)="unlock()" [mat-dialog-close]="'cancel'">lock_open</mat-icon> | ||
</mat-dialog-content> | ||
<mat-dialog-actions> | ||
<button mat-button [mat-dialog-close]="password" color="primary">Submit</button> | ||
<button mat-button [mat-dialog-close]="'cancel'"color="warn">Cancel</button> | ||
<button mat-button [mat-dialog-close]="'cancel'" color="warn">Cancel</button> | ||
</mat-dialog-actions> |
24 changes: 21 additions & 3 deletions
24
src/app/password-input-dialog/password-input-dialog.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 |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import { Component } from '@angular/core'; | ||
import { MatDialogRef } from '@angular/material/dialog'; | ||
import { Component, Input , Inject} from '@angular/core'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { UnlockService } from '../UnlockService/unlock.service'; | ||
@Component({ | ||
selector: 'app-password-input-dialog', | ||
templateUrl: './password-input-dialog.component.html', | ||
styleUrls: ['./password-input-dialog.component.css'] | ||
}) | ||
export class PasswordInputDialogComponent { | ||
// @Input() | ||
password: string = ''; | ||
passwordFieldType: string = 'password'; | ||
showPasswordIcon: string = 'visibility'; | ||
// @Input() | ||
locked : boolean = false; | ||
constructor(public dialogRef: MatDialogRef<PasswordInputDialogComponent>, @Inject(MAT_DIALOG_DATA) public data : {locked : boolean,password : string},private passwordService: UnlockService) { | ||
this.locked = data.locked; | ||
this.password = data.password; | ||
} | ||
|
||
constructor(public dialogRef: MatDialogRef<PasswordInputDialogComponent>) {} | ||
togglePasswordVisibility() { | ||
this.passwordFieldType = this.passwordFieldType === 'password' ? 'text' : 'password'; | ||
this.showPasswordIcon = this.showPasswordIcon === 'visibility' ? 'visibility_off' : 'visibility'; | ||
} | ||
unlock() { | ||
// Call the unlock request when the "unlock" icon is clicked | ||
this.passwordService.requestUnlock(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<app-navigation></app-navigation> | ||
<app-navigation [locked]="true"></app-navigation> | ||
|
||
<p>redirection works!</p> |