-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added functionality to verify user invite tokens and create the initial password * Add response types * Fail ValidateCredentialsAsync when user is not approved * Enable user as part of initial password creating using validation token * Adds documentation to badrequest and changed nocontent to ok, to align with other APIs * Fixed tests and added a new one --------- Co-authored-by: nikolajlauridsen <nikolajlauridsen@protonmail.ch>
- Loading branch information
1 parent
8bccab3
commit 59df743
Showing
12 changed files
with
185 additions
and
4 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/Umbraco.Cms.Api.Management/Controllers/User/CreateInitialPasswordUserController.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,33 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.User; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.User; | ||
|
||
[ApiVersion("1.0")] | ||
public class CreateInitialPasswordUserController : UserControllerBase | ||
{ | ||
private readonly IUserService _userService; | ||
|
||
public CreateInitialPasswordUserController(IUserService userService) => _userService = userService; | ||
|
||
[AllowAnonymous] | ||
[HttpPost("invite/create-password")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> CreateInitialPassword(CreateInitialPasswordUserRequestModel model) | ||
{ | ||
Attempt<PasswordChangedModel, UserOperationStatus> response = await _userService.CreateInitialPasswordAsync(model.UserId, model.Token, model.Password); | ||
|
||
return response.Success | ||
? Ok() | ||
: UserOperationStatusResult(response.Status, response.Result); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/Umbraco.Cms.Api.Management/Controllers/User/VerifyInviteUsersController.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,32 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.User; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.User; | ||
|
||
[ApiVersion("1.0")] | ||
public class VerifyInviteUserController : UserControllerBase | ||
{ | ||
private readonly IUserService _userService; | ||
|
||
public VerifyInviteUserController(IUserService userService) => _userService = userService; | ||
|
||
[AllowAnonymous] | ||
[HttpPost("invite/verify")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> Invite(VerifyInviteUserRequestModel model) | ||
{ | ||
Attempt<UserOperationStatus> result = await _userService.VerifyInviteAsync(model.UserId, model.Token); | ||
|
||
return result.Success | ||
? Ok() | ||
: UserOperationStatusResult(result.Result); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Umbraco.Cms.Api.Management/ViewModels/User/CreateInitialPasswordUserRequestModel.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,6 @@ | ||
namespace Umbraco.Cms.Api.Management.ViewModels.User; | ||
|
||
public class CreateInitialPasswordUserRequestModel : VerifyInviteUserRequestModel | ||
{ | ||
public string Password { get; set; } = string.Empty; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Umbraco.Cms.Api.Management/ViewModels/User/VerifyInviteUserRequestModel.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,8 @@ | ||
namespace Umbraco.Cms.Api.Management.ViewModels.User; | ||
|
||
public class VerifyInviteUserRequestModel | ||
{ | ||
public Guid UserId { get; set; } = Guid.Empty; | ||
|
||
public string Token { get; set; } = string.Empty; | ||
} |
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
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