-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change password functionality in Identity APIs added (#7)
* added changepassword endpoint * improved readme * right align tables on readme * syntax sugar
- Loading branch information
1 parent
043c17b
commit 901d9a5
Showing
8 changed files
with
203 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/identity/OpenIddict.UI.Identity.Api/Account/ChangePasswordViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace tomware.OpenIddict.UI.Identity.Api | ||
{ | ||
public class ChangePasswordViewModel | ||
{ | ||
[Required] | ||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] | ||
[DataType(DataType.Password)] | ||
public string CurrentPassword { get; set; } | ||
|
||
[Required] | ||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] | ||
[DataType(DataType.Password)] | ||
public string NewPassword { get; set; } | ||
|
||
[Required] | ||
[Compare("NewPassword", ErrorMessage = "The password and confirmation password do not match.")] | ||
public string ConfirmPassword { get; set; } | ||
|
||
[Required] | ||
public string UserName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,38 @@ public async Task Register_UserRegistered() | |
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task ChangePassword_PasswordChanged() | ||
{ | ||
// Arrange | ||
var email = "[email protected]"; | ||
await DeleteUser(email); | ||
|
||
await PostAsync("/api/accounts/register", new RegisterUserViewModel | ||
{ | ||
UserName = "username", | ||
Email = email, | ||
Password = "Pass123$", | ||
ConfirmPassword = "Pass123$" | ||
}); | ||
|
||
var user = await FindUserByEmail(email); | ||
Assert.NotNull(user); | ||
|
||
// Act | ||
var response = await PostAsync($"/api/accounts/changepassword", new ChangePasswordViewModel | ||
{ | ||
UserName = user.UserName, | ||
CurrentPassword = "Pass123$", | ||
NewPassword = "Pass1234$", | ||
ConfirmPassword = "Pass1234$" | ||
}); | ||
|
||
// Assert | ||
Assert.NotNull(response); | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAsync_UserReceived() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters