Skip to content

Commit

Permalink
Implemented update password
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Jul 8, 2024
1 parent 874e693 commit 2e20bda
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/PinguApps.Appwrite.Client/Clients/AccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,19 @@ public async Task<AppwriteResult<User>> UpdateName(UpdateNameRequest request)
return e.GetExceptionResponse<User>();
}
}

/// <inheritdoc/>
public async Task<AppwriteResult<User>> UpdatePassword(UpdatePasswordRequest request)
{
try
{
var result = await _accountApi.UpdatePassword(Session, request);

return result.GetApiResponse();
}
catch (Exception e)
{
return e.GetExceptionResponse<User>();
}
}
}
8 changes: 8 additions & 0 deletions src/PinguApps.Appwrite.Client/Clients/IAccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ public interface IAccountClient
/// <param name="request">The request content</param>
/// <returns>The user</returns>
Task<AppwriteResult<User>> UpdateName(UpdateNameRequest request);

/// <summary>
/// Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth, Team Invites and Magic URL, oldPassword is optional
/// <para><see href="https://appwrite.io/docs/references/1.5.x/server-rest/account#updatePassword">Appwrite Docs</see></para>
/// </summary>
/// <param name="request">The request content</param>
/// <returns>The user</returns>
Task<AppwriteResult<User>> UpdatePassword(UpdatePasswordRequest request);
}
3 changes: 3 additions & 0 deletions src/PinguApps.Appwrite.Client/Internals/IAccountApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public interface IAccountApi : IBaseApi

[Patch("/account/name")]
Task<IApiResponse<User>> UpdateName([Header("x-appwrite-session")] string? session, UpdateNameRequest name);

[Patch("/account/password")]
Task<IApiResponse<User>> UpdatePassword([Header("x-appwrite-session")] string? session, UpdatePasswordRequest name);
}
7 changes: 4 additions & 3 deletions src/PinguApps.Appwrite.Playground/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ public async Task Run(string[] args)
{
_client.SetSession(_session);

var request = new UpdateNameRequest
var request = new UpdatePasswordRequest
{
Name = "newName"
OldPassword = "MyNewPassword",
NewPassword = "MyNewPassword123"
};

var result = await _client.Account.UpdateName(request);
var result = await _client.Account.UpdatePassword(request);

result.Result.Switch(
account => Console.WriteLine(account.Email),
Expand Down
21 changes: 21 additions & 0 deletions src/PinguApps.Appwrite.Shared/Requests/UpdatePasswordRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json.Serialization;

namespace PinguApps.Appwrite.Shared.Requests;

/// <summary>
/// The request for updating a users password
/// </summary>
public class UpdatePasswordRequest
{
/// <summary>
/// New user password. Must be at least 8 chars
/// </summary>
[JsonPropertyName("password")]
public string NewPassword { get; set; } = string.Empty;

/// <summary>
/// Current user password. Must be at least 8 chars
/// </summary>
[JsonPropertyName("oldPassword")]
public string? OldPassword { get; set; }
}

0 comments on commit 2e20bda

Please sign in to comment.