mirror of
https://github.com/bitwarden/server.git
synced 2025-05-21 11:34:31 -05:00
Update API endpoint to use RegisterResponseModel (#2282)
This commit is contained in:
parent
26fc67eec6
commit
d0c793c951
@ -35,6 +35,7 @@ public class AccountsController : Controller
|
|||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
private readonly ISendRepository _sendRepository;
|
private readonly ISendRepository _sendRepository;
|
||||||
private readonly ISendService _sendService;
|
private readonly ISendService _sendService;
|
||||||
|
private readonly ICaptchaValidationService _captchaValidationService;
|
||||||
|
|
||||||
public AccountsController(
|
public AccountsController(
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
@ -47,7 +48,8 @@ public class AccountsController : Controller
|
|||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
ISendRepository sendRepository,
|
ISendRepository sendRepository,
|
||||||
ISendService sendService)
|
ISendService sendService,
|
||||||
|
ICaptchaValidationService captchaValidationService)
|
||||||
{
|
{
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
_folderRepository = folderRepository;
|
_folderRepository = folderRepository;
|
||||||
@ -60,11 +62,13 @@ public class AccountsController : Controller
|
|||||||
_userService = userService;
|
_userService = userService;
|
||||||
_sendRepository = sendRepository;
|
_sendRepository = sendRepository;
|
||||||
_sendService = sendService;
|
_sendService = sendService;
|
||||||
|
_captchaValidationService = captchaValidationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region DEPRECATED (Moved to Identity Service)
|
#region DEPRECATED (Moved to Identity Service)
|
||||||
|
|
||||||
[Obsolete("2022-01-12 Moved to Identity, left for backwards compatability with older clients")]
|
// This method is still used by self hosted intalls
|
||||||
|
[Obsolete("2022-01-12 Moved to Identity, left for backwards compatability with older clients.")]
|
||||||
[HttpPost("prelogin")]
|
[HttpPost("prelogin")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<PreloginResponseModel> PostPrelogin([FromBody] PreloginRequestModel model)
|
public async Task<PreloginResponseModel> PostPrelogin([FromBody] PreloginRequestModel model)
|
||||||
@ -81,17 +85,20 @@ public class AccountsController : Controller
|
|||||||
return new PreloginResponseModel(kdfInformation);
|
return new PreloginResponseModel(kdfInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("2022-01-12 Moved to Identity, left for backwards compatability with older clients")]
|
// This method is still used by self hosted intalls
|
||||||
|
[Obsolete("2022-01-12 Moved to Identity, left for backwards compatability with older clients.")]
|
||||||
[HttpPost("register")]
|
[HttpPost("register")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[CaptchaProtected]
|
[CaptchaProtected]
|
||||||
public async Task PostRegister([FromBody] RegisterRequestModel model)
|
public async Task<RegisterResponseModel> PostRegister([FromBody] RegisterRequestModel model)
|
||||||
{
|
{
|
||||||
var result = await _userService.RegisterUserAsync(model.ToUser(), model.MasterPasswordHash,
|
var user = model.ToUser();
|
||||||
|
var result = await _userService.RegisterUserAsync(user, model.MasterPasswordHash,
|
||||||
model.Token, model.OrganizationUserId);
|
model.Token, model.OrganizationUserId);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
return;
|
var captchaBypassToken = _captchaValidationService.GenerateCaptchaBypassToken(user);
|
||||||
|
return new RegisterResponseModel(captchaBypassToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var error in result.Errors.Where(e => e.Code != "DuplicateUserName"))
|
foreach (var error in result.Errors.Where(e => e.Code != "DuplicateUserName"))
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace Bit.Core.Models.Api.Response.Accounts;
|
||||||
|
|
||||||
|
public interface ICaptchaProtectedResponseModel
|
||||||
|
{
|
||||||
|
public string CaptchaBypassToken { get; set; }
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
using Bit.Core.Models.Api;
|
namespace Bit.Core.Models.Api.Response.Accounts;
|
||||||
|
|
||||||
namespace Bit.Identity.Models;
|
|
||||||
|
|
||||||
public class RegisterResponseModel : ResponseModel, ICaptchaProtectedResponseModel
|
public class RegisterResponseModel : ResponseModel, ICaptchaProtectedResponseModel
|
||||||
{
|
{
|
@ -6,7 +6,6 @@ using Bit.Core.Models.Data;
|
|||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using Bit.Identity.Models;
|
|
||||||
using Bit.SharedWeb.Utilities;
|
using Bit.SharedWeb.Utilities;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ public class AccountsController : Controller
|
|||||||
_captchaValidationService = captchaValidationService;
|
_captchaValidationService = captchaValidationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moved from API, If you modify this endpoint, please update API as well.
|
// Moved from API, If you modify this endpoint, please update API as well. Self hosted installs still use the API endpoints.
|
||||||
[HttpPost("register")]
|
[HttpPost("register")]
|
||||||
[CaptchaProtected]
|
[CaptchaProtected]
|
||||||
public async Task<RegisterResponseModel> PostRegister([FromBody] RegisterRequestModel model)
|
public async Task<RegisterResponseModel> PostRegister([FromBody] RegisterRequestModel model)
|
||||||
@ -56,7 +55,7 @@ public class AccountsController : Controller
|
|||||||
throw new BadRequestException(ModelState);
|
throw new BadRequestException(ModelState);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moved from API, If you modify this endpoint, please update API as well.
|
// Moved from API, If you modify this endpoint, please update API as well. Self hosted installs still use the API endpoints.
|
||||||
[HttpPost("prelogin")]
|
[HttpPost("prelogin")]
|
||||||
public async Task<PreloginResponseModel> PostPrelogin([FromBody] PreloginRequestModel model)
|
public async Task<PreloginResponseModel> PostPrelogin([FromBody] PreloginRequestModel model)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
public interface ICaptchaProtectedResponseModel
|
|
||||||
{
|
|
||||||
public string CaptchaBypassToken { get; set; }
|
|
||||||
}
|
|
@ -30,6 +30,7 @@ public class AccountsControllerTests : IDisposable
|
|||||||
private readonly ISendRepository _sendRepository;
|
private readonly ISendRepository _sendRepository;
|
||||||
private readonly ISendService _sendService;
|
private readonly ISendService _sendService;
|
||||||
private readonly IProviderUserRepository _providerUserRepository;
|
private readonly IProviderUserRepository _providerUserRepository;
|
||||||
|
private readonly ICaptchaValidationService _captchaValidationService;
|
||||||
|
|
||||||
public AccountsControllerTests()
|
public AccountsControllerTests()
|
||||||
{
|
{
|
||||||
@ -44,6 +45,7 @@ public class AccountsControllerTests : IDisposable
|
|||||||
_globalSettings = new GlobalSettings();
|
_globalSettings = new GlobalSettings();
|
||||||
_sendRepository = Substitute.For<ISendRepository>();
|
_sendRepository = Substitute.For<ISendRepository>();
|
||||||
_sendService = Substitute.For<ISendService>();
|
_sendService = Substitute.For<ISendService>();
|
||||||
|
_captchaValidationService = Substitute.For<ICaptchaValidationService>();
|
||||||
_sut = new AccountsController(
|
_sut = new AccountsController(
|
||||||
_globalSettings,
|
_globalSettings,
|
||||||
_cipherRepository,
|
_cipherRepository,
|
||||||
@ -55,7 +57,8 @@ public class AccountsControllerTests : IDisposable
|
|||||||
_userRepository,
|
_userRepository,
|
||||||
_userService,
|
_userService,
|
||||||
_sendRepository,
|
_sendRepository,
|
||||||
_sendService
|
_sendService,
|
||||||
|
_captchaValidationService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user