1
0
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:
Kyle Spearrin
2017-01-09 22:20:34 -05:00
parent 90607f6d93
commit 7abde8c771
18 changed files with 138 additions and 29 deletions

View File

@ -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);

View File

@ -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

View 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;
}
}
}

View 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; }
}
}

View File

@ -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; }
}