mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
equivalent domains APIs and data models
This commit is contained in:
@ -157,6 +157,13 @@ namespace Bit.Api.Controllers
|
||||
return Task.FromResult(response);
|
||||
}
|
||||
|
||||
[HttpGet("domains")]
|
||||
public Task<DomainsResponseModel> GetDomains()
|
||||
{
|
||||
var response = new DomainsResponseModel(_currentContext.User);
|
||||
return Task.FromResult(response);
|
||||
}
|
||||
|
||||
[HttpPut("profile")]
|
||||
[HttpPost("profile")]
|
||||
public async Task<ProfileResponseModel> PutProfile([FromBody]UpdateProfileRequestModel model)
|
||||
@ -165,10 +172,20 @@ namespace Bit.Api.Controllers
|
||||
|
||||
var response = new ProfileResponseModel(_currentContext.User);
|
||||
return response;
|
||||
}
|
||||
|
||||
[HttpPut("domains")]
|
||||
[HttpPost("domains")]
|
||||
public async Task<DomainsResponseModel> PutDomains([FromBody]UpdateDomainsRequestModel model)
|
||||
{
|
||||
await _userService.SaveUserAsync(model.ToUser(_currentContext.User));
|
||||
|
||||
var response = new DomainsResponseModel(_currentContext.User);
|
||||
return response;
|
||||
}
|
||||
|
||||
[HttpGet("two-factor")]
|
||||
public async Task<TwoFactorResponseModel> GetTwoFactor(string masterPasswordHash, TwoFactorProvider provider)
|
||||
public async Task<TwoFactorResponseModel> GetTwoFactor(string masterPasswordHash, TwoFactorProviderType provider)
|
||||
{
|
||||
var user = _currentContext.User;
|
||||
if(!await _userManager.CheckPasswordAsync(user, masterPasswordHash))
|
||||
@ -200,7 +217,7 @@ namespace Bit.Api.Controllers
|
||||
throw new BadRequestException("Token", "Invalid token.");
|
||||
}
|
||||
|
||||
user.TwoFactorProvider = TwoFactorProvider.Authenticator;
|
||||
user.TwoFactorProvider = TwoFactorProviderType.Authenticator;
|
||||
user.TwoFactorEnabled = model.Enabled.Value;
|
||||
user.TwoFactorRecoveryCode = user.TwoFactorEnabled ? Guid.NewGuid().ToString("N") : null;
|
||||
await _userService.SaveUserAsync(user);
|
||||
|
@ -14,7 +14,7 @@ using Bit.Core.Services;
|
||||
namespace Bit.Api.Controllers
|
||||
{
|
||||
[Route("logins")]
|
||||
// sites route is deprecated
|
||||
// "sites" route is deprecated
|
||||
[Route("sites")]
|
||||
[Authorize("Application")]
|
||||
public class LoginsController : Controller
|
||||
|
21
src/Api/Models/Request/Accounts/UpdateDomainsRequestModel.cs
Normal file
21
src/Api/Models/Request/Accounts/UpdateDomainsRequestModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Bit.Core.Domains;
|
||||
using System.Collections.Generic;
|
||||
using Bit.Core.Enums;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class UpdateDomainsRequestModel
|
||||
{
|
||||
public IEnumerable<IEnumerable<string>> EquivalentDomains { get; set; }
|
||||
public IEnumerable<GlobalEquivalentDomainsType> ExcludedGlobalEquivalentDomains { get; set; }
|
||||
|
||||
public User ToUser(User existingUser)
|
||||
{
|
||||
existingUser.EquivalentDomains = EquivalentDomains != null ? JsonConvert.SerializeObject(EquivalentDomains) : null;
|
||||
existingUser.ExcludedGlobalEquivalentDomains = ExcludedGlobalEquivalentDomains != null ?
|
||||
JsonConvert.SerializeObject(ExcludedGlobalEquivalentDomains) : null;
|
||||
return existingUser;
|
||||
}
|
||||
}
|
||||
}
|
30
src/Api/Models/Response/DomainsResponseModel.cs
Normal file
30
src/Api/Models/Response/DomainsResponseModel.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Bit.Core.Domains;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class DomainsResponseModel : ResponseModel
|
||||
{
|
||||
public DomainsResponseModel(User user)
|
||||
: base("domains")
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
EquivalentDomains = user.EquivalentDomains != null ?
|
||||
JsonConvert.DeserializeObject<List<List<string>>>(user.EquivalentDomains) : null;
|
||||
GlobalEquivalentDomains = Core.Utilities.EquivalentDomains.Global;
|
||||
ExcludedGlobalEquivalentDomains = user.ExcludedGlobalEquivalentDomains != null ?
|
||||
JsonConvert.DeserializeObject<List<GlobalEquivalentDomainsType>>(user.ExcludedGlobalEquivalentDomains) : null;
|
||||
}
|
||||
|
||||
public IEnumerable<IEnumerable<string>> EquivalentDomains { get; set; }
|
||||
public IDictionary<GlobalEquivalentDomainsType, IEnumerable<string>> GlobalEquivalentDomains { get; set; }
|
||||
public IEnumerable<GlobalEquivalentDomainsType> ExcludedGlobalEquivalentDomains { get; set; }
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ namespace Bit.Api.Models
|
||||
}
|
||||
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
public TwoFactorProvider? TwoFactorProvider { get; set; }
|
||||
public TwoFactorProviderType? TwoFactorProvider { get; set; }
|
||||
public string AuthenticatorKey { get; set; }
|
||||
public string TwoFactorRecoveryCode { get; set; }
|
||||
}
|
||||
|
Reference in New Issue
Block a user