Skip to content

Commit 4d70aa9

Browse files
committed
Add time zone validation to PreferencesViewModel
This prevents users from being setting an invalid time zone through the account preferences page. In practice this is only likely to occur if the user has deliberately tampered with the select options, but is still worth checking to prevent invalid data being stored in the database.
1 parent 1c56c98 commit 4d70aa9

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/Buttercup.Web/Models/Account/PreferencesViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using Buttercup.Application.Validation;
23
using Buttercup.EntityModel;
34

45
namespace Buttercup.Web.Models.Account;
@@ -12,5 +13,6 @@ public PreferencesViewModel()
1213
public PreferencesViewModel(User user) => this.TimeZone = user.TimeZone;
1314

1415
[Required(ErrorMessage = "Error_RequiredField")]
16+
[TimeZone]
1517
public string TimeZone { get; init; } = string.Empty;
1618
}

src/Buttercup.Web/Models/Account/PreferencesViewModel.fr.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
<data name="Error_RequiredField">
44
<value>Ce champ est requis</value>
55
</data>
6+
<data name="Error_InvalidTimeZone">
7+
<value>Le fuseau horaire sélectionné n’est pas pris en charge</value>
8+
</data>
69
</root>

src/Buttercup.Web/Models/Account/PreferencesViewModel.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
<data name="Error_RequiredField">
44
<value>This field is required</value>
55
</data>
6+
<data name="Error_InvalidTimeZone">
7+
<value>Selected time zone is not supported</value>
8+
</data>
69
</root>

0 commit comments

Comments
 (0)