mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-21 11:35:34 +01:00
Disable API call if the expiration date is in the past (#5831)
* Disable API call if the expiration date is in the past * Updates suggested by Thomas * fixes * suggested change from thomas * removing unused service
This commit is contained in:
parent
c0810c96cc
commit
5d8be1182a
@ -711,6 +711,9 @@
|
|||||||
"unexpectedError": {
|
"unexpectedError": {
|
||||||
"message": "An unexpected error has occurred."
|
"message": "An unexpected error has occurred."
|
||||||
},
|
},
|
||||||
|
"expirationDateError" : {
|
||||||
|
"message":"Please select an expiration date that is in the future."
|
||||||
|
},
|
||||||
"emailAddress": {
|
"emailAddress": {
|
||||||
"message": "Email address"
|
"message": "Email address"
|
||||||
},
|
},
|
||||||
|
@ -51,6 +51,7 @@ export class AccessTokenCreateDialogComponent implements OnInit {
|
|||||||
if (this.formGroup.invalid) {
|
if (this.formGroup.invalid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const accessTokenView = new AccessTokenView();
|
const accessTokenView = new AccessTokenView();
|
||||||
accessTokenView.name = this.formGroup.value.name;
|
accessTokenView.name = this.formGroup.value.name;
|
||||||
accessTokenView.expireAt = this.formGroup.value.expirationDateControl;
|
accessTokenView.expireAt = this.formGroup.value.expirationDateControl;
|
||||||
|
@ -9,10 +9,13 @@ import {
|
|||||||
NG_VALUE_ACCESSOR,
|
NG_VALUE_ACCESSOR,
|
||||||
ValidationErrors,
|
ValidationErrors,
|
||||||
Validator,
|
Validator,
|
||||||
|
ValidatorFn,
|
||||||
Validators,
|
Validators,
|
||||||
} from "@angular/forms";
|
} from "@angular/forms";
|
||||||
import { Subject, takeUntil } from "rxjs";
|
import { Subject, takeUntil } from "rxjs";
|
||||||
|
|
||||||
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "sm-expiration-options",
|
selector: "sm-expiration-options",
|
||||||
templateUrl: "./expiration-options.component.html",
|
templateUrl: "./expiration-options.component.html",
|
||||||
@ -46,10 +49,10 @@ export class ExpirationOptionsComponent
|
|||||||
|
|
||||||
protected form = new FormGroup({
|
protected form = new FormGroup({
|
||||||
expires: new FormControl("never", [Validators.required]),
|
expires: new FormControl("never", [Validators.required]),
|
||||||
expireDateTime: new FormControl("", [Validators.required]),
|
expireDateTime: new FormControl("", [Validators.required, this.expiresInFutureValidator()]),
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(private datePipe: DatePipe) {}
|
constructor(private datePipe: DatePipe, private i18nService: I18nService) {}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.form.valueChanges.pipe(takeUntil(this.destroy$)).subscribe(() => {
|
this.form.valueChanges.pipe(takeUntil(this.destroy$)).subscribe(() => {
|
||||||
@ -74,7 +77,7 @@ export class ExpirationOptionsComponent
|
|||||||
|
|
||||||
validate(control: AbstractControl<any, any>): ValidationErrors {
|
validate(control: AbstractControl<any, any>): ValidationErrors {
|
||||||
if (
|
if (
|
||||||
(this.form.value.expires == "custom" && this.form.value.expireDateTime) ||
|
(this.form.value.expires == "custom" && !this.form.invalid) ||
|
||||||
this.form.value.expires !== "custom"
|
this.form.value.expires !== "custom"
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
@ -111,4 +114,20 @@ export class ExpirationOptionsComponent
|
|||||||
currentDate.setDate(currentDate.getDate() + Number(this.form.value.expires));
|
currentDate.setDate(currentDate.getDate() + Number(this.form.value.expires));
|
||||||
return currentDate;
|
return currentDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expiresInFutureValidator(): ValidatorFn {
|
||||||
|
return (control: AbstractControl): ValidationErrors | null => {
|
||||||
|
const enteredDate = new Date(control.value);
|
||||||
|
|
||||||
|
if (enteredDate > new Date()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
ValidationError: {
|
||||||
|
message: this.i18nService.t("expirationDateError"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user