From bd46b9f314d6cf1cd7dea5f9bbf446602e62005f Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Mon, 2 Sep 2024 19:44:09 -0500 Subject: [PATCH 1/3] Add new resources --- .../Common/Resources/Messages.Designer.cs | 27 ++++++++++++------- .../Common/Resources/Messages.resx | 9 ++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Application/Common/Resources/Messages.Designer.cs b/src/Application/Common/Resources/Messages.Designer.cs index 6fd51518..b91d50cd 100644 --- a/src/Application/Common/Resources/Messages.Designer.cs +++ b/src/Application/Common/Resources/Messages.Designer.cs @@ -69,15 +69,6 @@ internal static string AddPoints { } } - /// - /// Looks up a localized string similar to {OldName} changed their name to {NewName}. - /// - internal static string ChangeName { - get { - return ResourceManager.GetString("ChangeName", resourceCulture); - } - } - /// /// Looks up a localized string similar to You have successfully registered. Password: {Password}. /// @@ -213,6 +204,15 @@ internal static string NameCannotBeEmpty { } } + /// + /// Looks up a localized string similar to {OldName} changed their name to {NewName}. + /// + internal static string NameSuccessfullyChanged { + get { + return ResourceManager.GetString("NameSuccessfullyChanged", resourceCulture); + } + } + /// /// Looks up a localized string similar to You moved up to {Name} rank, congratulations!. /// @@ -240,6 +240,15 @@ internal static string PasswordLength { } } + /// + /// Looks up a localized string similar to Password successfully changed. New password: {NewPassword}. + /// + internal static string PasswordSuccessfullyChanged { + get { + return ResourceManager.GetString("PasswordSuccessfullyChanged", resourceCulture); + } + } + /// /// Looks up a localized string similar to That player name already exists. /// diff --git a/src/Application/Common/Resources/Messages.resx b/src/Application/Common/Resources/Messages.resx index f83b37e2..e22c2b7f 100644 --- a/src/Application/Common/Resources/Messages.resx +++ b/src/Application/Common/Resources/Messages.resx @@ -120,9 +120,6 @@ Points must be between 1 to 100 - - {OldName} changed their name to {NewName} - You have successfully registered. Password: {Password} @@ -168,6 +165,9 @@ Name cannot be empty + + {OldName} changed their name to {NewName} + You moved up to {Name} rank, congratulations! @@ -177,6 +177,9 @@ Password must be between 5 and 20 characters + + Password successfully changed. New password: {NewPassword} + That player name already exists From 73a8b98648c7fc9438749dc8a7382f320ae68b25 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Mon, 2 Sep 2024 19:46:26 -0500 Subject: [PATCH 2/3] refactor: Rename to NameSuccessfullyChanged --- src/Application/Players/Accounts/Systems/ChangeNameSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/Players/Accounts/Systems/ChangeNameSystem.cs b/src/Application/Players/Accounts/Systems/ChangeNameSystem.cs index 6c29654e..ef2cc185 100644 --- a/src/Application/Players/Accounts/Systems/ChangeNameSystem.cs +++ b/src/Application/Players/Accounts/Systems/ChangeNameSystem.cs @@ -22,7 +22,7 @@ public void ChangeName(Player player, string newName) return; } - var message = Smart.Format(Messages.ChangeName, new { OldName = oldName, NewName = newName }); + var message = Smart.Format(Messages.NameSuccessfullyChanged, new { OldName = oldName, NewName = newName }); worldService.SendClientMessage(Color.Yellow, message); player.Name = newName; playerRepository.UpdateName(playerInfo); From e24a4bd533a84f0ee74901aeb39f6b59f5b45fa3 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Mon, 2 Sep 2024 19:47:31 -0500 Subject: [PATCH 3/3] feat: Allow the player to change their password --- .../Accounts/Systems/ChangePasswordSystem.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Application/Players/Accounts/Systems/ChangePasswordSystem.cs diff --git a/src/Application/Players/Accounts/Systems/ChangePasswordSystem.cs b/src/Application/Players/Accounts/Systems/ChangePasswordSystem.cs new file mode 100644 index 00000000..9389da3f --- /dev/null +++ b/src/Application/Players/Accounts/Systems/ChangePasswordSystem.cs @@ -0,0 +1,42 @@ +namespace CTF.Application.Players.Accounts.Systems; + +public class ChangePasswordSystem( + IPlayerRepository playerRepository, + IDialogService dialogService) : ISystem +{ + private readonly InputDialog _passwordDialog = new() + { + IsPassword = true, + Caption = "Change Password", + Content = "Enter your new password", + Button1 = "Accept", + Button2 = "Close" + }; + + [PlayerCommand("changepass")] + public async void ShowPasswordDialog(Player player) + { + InputDialogResponse response = await dialogService.ShowAsync(player, _passwordDialog); + if (response.Response == DialogResponse.RightButtonOrCancel) + return; + + var enteredPassword = response.InputText; + ChangePassword(player, enteredPassword); + } + + private void ChangePassword(Player player, string enteredPassword) + { + PlayerInfo playerInfo = player.GetComponent().PlayerInfo; + Result result = playerInfo.SetPassword(enteredPassword); + if (result.IsFailed) + { + player.SendClientMessage(Color.Red, result.Message); + ShowPasswordDialog(player); + return; + } + + var message = Smart.Format(Messages.PasswordSuccessfullyChanged, new { NewPassword = enteredPassword }); + player.SendClientMessage(Color.Yellow, message); + playerRepository.UpdatePassword(playerInfo); + } +}