1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

backwards compat issues with change email/password

This commit is contained in:
Kyle Spearrin
2017-04-28 16:49:40 -04:00
parent 8d37f1c946
commit 23467b7771
5 changed files with 95 additions and 11 deletions

View File

@ -76,15 +76,32 @@ namespace Bit.Api.Controllers
[HttpPut("email")]
[HttpPost("email")]
public async Task PutEmail([FromBody]EmailRequestModel model)
public async Task PutEmail([FromBody]EmailRequestModel_Old model)
{
var user = await _userService.GetUserByPrincipalAsync(User);
// NOTE: It is assumed that the eventual repository call will make sure the updated
// ciphers belong to user making this call. Therefore, no check is done here.
var ciphers = model.Data.Ciphers.Select(c => c.ToCipher(user.Id));
var folders = model.Data.Folders.Select(c => c.ToFolder(user.Id));
//var ciphers = model.Data.Ciphers.Select(c => c.ToCipher(user.Id));
//var folders = model.Data.Folders.Select(c => c.ToFolder(user.Id));
//var result = await _userService.ChangeEmailAsync(
// user,
// model.MasterPasswordHash,
// model.NewEmail,
// model.NewMasterPasswordHash,
// model.Token,
// ciphers,
// folders,
// model.Data.PrivateKey);
//
// NOTE: Temporary backwards compat. Remove the below and uncomment the above whenever web vault v1.10.0 is released
//
var ciphers = model.Ciphers.Where(c => c.Type == CipherType.Login).Select(c => c.ToCipher(user.Id));
var folders = model.Ciphers.Where(c => c.Type == CipherType.Folder).Select(c => c.ToFolder(user.Id));
var result = await _userService.ChangeEmailAsync(
user,
model.MasterPasswordHash,
@ -93,7 +110,7 @@ namespace Bit.Api.Controllers
model.Token,
ciphers,
folders,
model.Data.PrivateKey);
null);
if(result.Succeeded)
{
@ -111,22 +128,37 @@ namespace Bit.Api.Controllers
[HttpPut("password")]
[HttpPost("password")]
public async Task PutPassword([FromBody]PasswordRequestModel model)
public async Task PutPassword([FromBody]PasswordRequestModel_Old model)
{
var user = await _userService.GetUserByPrincipalAsync(User);
// NOTE: It is assumed that the eventual repository call will make sure the updated
// ciphers belong to user making this call. Therefore, no check is done here.
var ciphers = model.Data.Ciphers.Select(c => c.ToCipher(user.Id));
var folders = model.Data.Folders.Select(c => c.ToFolder(user.Id));
//var ciphers = model.Data.Ciphers.Select(c => c.ToCipher(user.Id));
//var folders = model.Data.Folders.Select(c => c.ToFolder(user.Id));
//var result = await _userService.ChangePasswordAsync(
// user,
// model.MasterPasswordHash,
// model.NewMasterPasswordHash,
// ciphers,
// folders,
// model.Data.PrivateKey);
//
// NOTE: Temporary backwards compat. Remove the below and uncomment the above whenever web vault v1.10.0 is released
//
var ciphers = model.Ciphers.Where(c => c.Type == CipherType.Login).Select(c => c.ToCipher(user.Id));
var folders = model.Ciphers.Where(c => c.Type == CipherType.Folder).Select(c => c.ToFolder(user.Id));
var result = await _userService.ChangePasswordAsync(
user,
model.MasterPasswordHash,
model.NewMasterPasswordHash,
ciphers,
folders,
model.Data.PrivateKey);
null);
if(result.Succeeded)
{