switchable password visibility
This commit is contained in:
parent
1f460dc0a4
commit
d7b07202ec
10 changed files with 156 additions and 80 deletions
|
|
@ -66,21 +66,28 @@
|
||||||
(ngSubmit)="onSubmit(taskForm, password)"
|
(ngSubmit)="onSubmit(taskForm, password)"
|
||||||
onsubmit="return false"
|
onsubmit="return false"
|
||||||
>
|
>
|
||||||
<input
|
<div class="password-field">
|
||||||
type="password"
|
<input
|
||||||
id="password"
|
[type]="authService.passwordFieldType"
|
||||||
name="password"
|
id="password"
|
||||||
#password="ngModel"
|
name="password"
|
||||||
placeholder="Enter a password"
|
#password="ngModel"
|
||||||
autocomplete="new-password"
|
placeholder="Enter a password"
|
||||||
[(ngModel)]="authData.password"
|
autocomplete="new-password"
|
||||||
pattern="[^<>]*"
|
[(ngModel)]="authData.password"
|
||||||
minlength="6"
|
pattern="[^<>]*"
|
||||||
[class.error-border]="
|
minlength="6"
|
||||||
password.invalid && password.touched && authData.password.length < 6
|
[class.error-border]="
|
||||||
"
|
password.invalid && password.touched && authData.password.length < 6
|
||||||
required
|
"
|
||||||
/>
|
required
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
class="passwordEye"
|
||||||
|
(click)="authService.togglePasswordVisibility()"
|
||||||
|
[src]="authService.passwordIcon"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (!password.valid && password.touched && authData.password.length <
|
@if (!password.valid && password.touched && authData.password.length <
|
||||||
1) {
|
1) {
|
||||||
|
|
@ -90,22 +97,29 @@
|
||||||
<p>Password is too short, min 6 characters</p>
|
<p>Password is too short, min 6 characters</p>
|
||||||
} }
|
} }
|
||||||
</div>
|
</div>
|
||||||
<input
|
<div class="password-field">
|
||||||
type="password"
|
<input
|
||||||
id="passwordConfirm"
|
[type]="authService.passwordFieldType"
|
||||||
name="passwordConfirm"
|
id="passwordConfirm"
|
||||||
#passwordConfirm="ngModel"
|
name="passwordConfirm"
|
||||||
placeholder="Confirm password"
|
#passwordConfirm="ngModel"
|
||||||
autocomplete="new-password"
|
placeholder="Confirm password"
|
||||||
[(ngModel)]="authData.passwordConfirm"
|
autocomplete="new-password"
|
||||||
pattern="[^<>]*"
|
[(ngModel)]="authData.passwordConfirm"
|
||||||
minlength="6"
|
pattern="[^<>]*"
|
||||||
[class.error-border]="
|
minlength="6"
|
||||||
authData.password !== authData.passwordConfirm &&
|
[class.error-border]="
|
||||||
passwordConfirm.touched
|
authData.password !== authData.passwordConfirm &&
|
||||||
"
|
passwordConfirm.touched
|
||||||
required
|
"
|
||||||
/>
|
required
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
class="passwordEye"
|
||||||
|
(click)="authService.togglePasswordVisibility()"
|
||||||
|
[src]="authService.passwordIcon"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (authData.password !== authData.passwordConfirm &&
|
@if (authData.password !== authData.passwordConfirm &&
|
||||||
passwordConfirm.touched) {
|
passwordConfirm.touched) {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ export class ForgotPasswordComponent {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private authService: AuthService,
|
public authService: AuthService,
|
||||||
public errorService: ErrorService
|
public errorService: ErrorService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,21 +31,29 @@
|
||||||
<p>This is not a valid email format</p>
|
<p>This is not a valid email format</p>
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
<input
|
<div class="password-field">
|
||||||
type="password"
|
<input
|
||||||
id="password"
|
[type]="authService.passwordFieldType"
|
||||||
name="password"
|
id="password"
|
||||||
#password="ngModel"
|
name="password"
|
||||||
placeholder="Enter a password"
|
class="password-input"
|
||||||
autocomplete="new-password"
|
#password="ngModel"
|
||||||
[(ngModel)]="authData.password"
|
placeholder="Enter a password"
|
||||||
pattern="[^<>]*"
|
autocomplete="new-password"
|
||||||
minlength="6"
|
[(ngModel)]="authData.password"
|
||||||
[class.error-border]="
|
pattern="[^<>]*"
|
||||||
password.invalid && password.touched && authData.password.length < 6
|
minlength="6"
|
||||||
"
|
[class.error-border]="
|
||||||
required
|
password.invalid && password.touched && authData.password.length < 6
|
||||||
/>
|
"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
class="passwordEye"
|
||||||
|
(click)="authService.togglePasswordVisibility()"
|
||||||
|
[src]="authService.passwordIcon"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (!password.valid && password.touched && authData.password.length <
|
@if (!password.valid && password.touched && authData.password.length <
|
||||||
1) {
|
1) {
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,10 @@ export class LoginComponent {
|
||||||
send: false,
|
send: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
showPassword: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
public authService: AuthService,
|
||||||
public errorService: ErrorService,
|
public errorService: ErrorService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
|
||||||
|
|
@ -40,21 +40,28 @@
|
||||||
<p>This is not a valid email format</p>
|
<p>This is not a valid email format</p>
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
<input
|
<div class="password-field">
|
||||||
type="password"
|
<input
|
||||||
id="password"
|
[type]="authService.passwordFieldType"
|
||||||
name="password"
|
id="password"
|
||||||
#password="ngModel"
|
name="password"
|
||||||
placeholder="Enter a password"
|
#password="ngModel"
|
||||||
autocomplete="new-password"
|
placeholder="Enter a password"
|
||||||
[(ngModel)]="authData.password"
|
autocomplete="new-password"
|
||||||
pattern="[^<>]*"
|
[(ngModel)]="authData.password"
|
||||||
minlength="6"
|
pattern="[^<>]*"
|
||||||
[class.error-border]="
|
minlength="6"
|
||||||
password.invalid && password.touched && authData.password.length < 6
|
[class.error-border]="
|
||||||
"
|
password.invalid && password.touched && authData.password.length < 6
|
||||||
required
|
"
|
||||||
/>
|
required
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
class="passwordEye"
|
||||||
|
(click)="authService.togglePasswordVisibility()"
|
||||||
|
[src]="authService.passwordIcon"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (!password.valid && password.touched && authData.password.length <
|
@if (!password.valid && password.touched && authData.password.length <
|
||||||
1) {
|
1) {
|
||||||
|
|
@ -64,22 +71,29 @@
|
||||||
<p>Password is too short, min 6 characters</p>
|
<p>Password is too short, min 6 characters</p>
|
||||||
} }
|
} }
|
||||||
</div>
|
</div>
|
||||||
<input
|
<div class="password-field">
|
||||||
type="password"
|
<input
|
||||||
id="passwordConfirm"
|
[type]="authService.passwordFieldType"
|
||||||
name="passwordConfirm"
|
id="passwordConfirm"
|
||||||
#passwordConfirm="ngModel"
|
name="passwordConfirm"
|
||||||
placeholder="Confirm password"
|
#passwordConfirm="ngModel"
|
||||||
autocomplete="new-password"
|
placeholder="Confirm password"
|
||||||
[(ngModel)]="authData.passwordConfirm"
|
autocomplete="new-password"
|
||||||
pattern="[^<>]*"
|
[(ngModel)]="authData.passwordConfirm"
|
||||||
minlength="6"
|
pattern="[^<>]*"
|
||||||
[class.error-border]="
|
minlength="6"
|
||||||
authData.password !== authData.passwordConfirm &&
|
[class.error-border]="
|
||||||
passwordConfirm.touched
|
authData.password !== authData.passwordConfirm &&
|
||||||
"
|
passwordConfirm.touched
|
||||||
required
|
"
|
||||||
/>
|
required
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
class="passwordEye"
|
||||||
|
(click)="authService.togglePasswordVisibility()"
|
||||||
|
[src]="authService.passwordIcon"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (authData.password !== authData.passwordConfirm &&
|
@if (authData.password !== authData.passwordConfirm &&
|
||||||
passwordConfirm.touched) {
|
passwordConfirm.touched) {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export class RegisterComponent {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private authService: AuthService,
|
public authService: AuthService,
|
||||||
public errorService: ErrorService,
|
public errorService: ErrorService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,24 @@ import { environment } from '../environments/environment.development';
|
||||||
})
|
})
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
errorMsg: string | null = null;
|
errorMsg: string | null = null;
|
||||||
|
passwordFieldType: string = 'password';
|
||||||
|
passwordIcon: string = './../../../assets/img/close-eye.svg';
|
||||||
|
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
togglePasswordVisibility() {
|
||||||
|
this.passwordFieldType =
|
||||||
|
this.passwordFieldType === 'password' ? 'text' : 'password';
|
||||||
|
this.toggleIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleIcon() {
|
||||||
|
this.passwordIcon =
|
||||||
|
this.passwordIcon === './../../../assets/img/close-eye.svg'
|
||||||
|
? './../../../assets/img/open-eye.svg'
|
||||||
|
: './../../../assets/img/close-eye.svg';
|
||||||
|
}
|
||||||
|
|
||||||
async register(body: any) {
|
async register(body: any) {
|
||||||
await lastValueFrom(
|
await lastValueFrom(
|
||||||
this.http.post(`${environment.baseUrl}/auth/register/`, body)
|
this.http.post(`${environment.baseUrl}/auth/register/`, body)
|
||||||
|
|
|
||||||
1
frontend/src/assets/img/close-eye.svg
Normal file
1
frontend/src/assets/img/close-eye.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#434343"><path d="m644-428-58-58q9-47-27-88t-93-32l-58-58q17-8 34.5-12t37.5-4q75 0 127.5 52.5T660-500q0 20-4 37.5T644-428Zm128 126-58-56q38-29 67.5-63.5T832-500q-50-101-143.5-160.5T480-720q-29 0-57 4t-55 12l-62-62q41-17 84-25.5t90-8.5q151 0 269 83.5T920-500q-23 59-60.5 109.5T772-302Zm20 246L624-222q-35 11-70.5 16.5T480-200q-151 0-269-83.5T40-500q21-53 53-98.5t73-81.5L56-792l56-56 736 736-56 56ZM222-624q-29 26-53 57t-41 67q50 101 143.5 160.5T480-280q20 0 39-2.5t39-5.5l-36-38q-11 3-21 4.5t-21 1.5q-75 0-127.5-52.5T300-500q0-11 1.5-21t4.5-21l-84-82Zm319 93Zm-151 75Z"/></svg>
|
||||||
|
After Width: | Height: | Size: 675 B |
1
frontend/src/assets/img/open-eye.svg
Normal file
1
frontend/src/assets/img/open-eye.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#434343"><path d="M480-320q75 0 127.5-52.5T660-500q0-75-52.5-127.5T480-680q-75 0-127.5 52.5T300-500q0 75 52.5 127.5T480-320Zm0-72q-45 0-76.5-31.5T372-500q0-45 31.5-76.5T480-608q45 0 76.5 31.5T588-500q0 45-31.5 76.5T480-392Zm0 192q-146 0-266-81.5T40-500q54-137 174-218.5T480-800q146 0 266 81.5T920-500q-54 137-174 218.5T480-200Zm0-300Zm0 220q113 0 207.5-59.5T832-500q-50-101-144.5-160.5T480-720q-113 0-207.5 59.5T128-500q50 101 144.5 160.5T480-280Z"/></svg>
|
||||||
|
After Width: | Height: | Size: 554 B |
|
|
@ -45,6 +45,23 @@ form {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show / Hide Password
|
||||||
|
|
||||||
|
.password-field {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.passwordEye {
|
||||||
|
position: absolute;
|
||||||
|
right: 48px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
cursor: pointer;
|
||||||
|
filter: brightness(0) saturate(100%) invert(16%) sepia(77%) saturate(7494%)
|
||||||
|
hue-rotate(241deg) brightness(93%) contrast(88%);
|
||||||
|
}
|
||||||
|
|
||||||
/*------------- RESPONSIVE -------------*/
|
/*------------- RESPONSIVE -------------*/
|
||||||
|
|
||||||
@media screen and (max-width: 600px) {
|
@media screen and (max-width: 600px) {
|
||||||
|
|
@ -53,4 +70,8 @@ form {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.passwordEye {
|
||||||
|
right: 18px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue