Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow the player to change their password #52

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/Application/Common/Resources/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/Application/Common/Resources/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@
<data name="AddPoints" xml:space="preserve">
<value>Points must be between 1 to 100</value>
</data>
<data name="ChangeName" xml:space="preserve">
<value>{OldName} changed their name to {NewName}</value>
</data>
<data name="CreatePlayerAccount" xml:space="preserve">
<value>You have successfully registered. Password: {Password}</value>
</data>
Expand Down Expand Up @@ -168,6 +165,9 @@
<data name="NameCannotBeEmpty" xml:space="preserve">
<value>Name cannot be empty</value>
</data>
<data name="NameSuccessfullyChanged" xml:space="preserve">
<value>{OldName} changed their name to {NewName}</value>
</data>
<data name="NextRank" xml:space="preserve">
<value>You moved up to {Name} rank, congratulations!</value>
</data>
Expand All @@ -177,6 +177,9 @@
<data name="PasswordLength" xml:space="preserve">
<value>Password must be between 5 and 20 characters</value>
</data>
<data name="PasswordSuccessfullyChanged" xml:space="preserve">
<value>Password successfully changed. New password: {NewPassword}</value>
</data>
<data name="PlayerNameAlreadyExists" xml:space="preserve">
<value>That player name already exists</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 42 additions & 0 deletions src/Application/Players/Accounts/Systems/ChangePasswordSystem.cs
Original file line number Diff line number Diff line change
@@ -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<AccountComponent>().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);
}
}
Loading