mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
move all models into core
This commit is contained in:
@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class FolderDataModel
|
||||
{
|
||||
public FolderDataModel() { }
|
||||
|
||||
public FolderDataModel(FolderRequestModel folder)
|
||||
{
|
||||
Name = folder.Name;
|
||||
}
|
||||
|
||||
public FolderDataModel(CipherRequestModel cipher)
|
||||
{
|
||||
Name = cipher.Name;
|
||||
}
|
||||
|
||||
public FolderDataModel(Cipher cipher)
|
||||
{
|
||||
if(cipher.Type != Core.Enums.CipherType.Folder)
|
||||
{
|
||||
throw new ArgumentException("Cipher is not correct type.");
|
||||
}
|
||||
|
||||
var data = JsonConvert.DeserializeObject<FolderDataModel>(cipher.Data);
|
||||
|
||||
Name = data.Name;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class LoginDataModel
|
||||
{
|
||||
public LoginDataModel() { }
|
||||
|
||||
public LoginDataModel(LoginRequestModel login)
|
||||
{
|
||||
Name = login.Name;
|
||||
Uri = login.Uri;
|
||||
Username = login.Username;
|
||||
Password = login.Password;
|
||||
Notes = login.Notes;
|
||||
}
|
||||
|
||||
public LoginDataModel(CipherRequestModel cipher)
|
||||
{
|
||||
Name = cipher.Name;
|
||||
Uri = cipher.Uri;
|
||||
Username = cipher.Username;
|
||||
Password = cipher.Password;
|
||||
Notes = cipher.Notes;
|
||||
}
|
||||
|
||||
public LoginDataModel(Cipher cipher)
|
||||
{
|
||||
if(cipher.Type != Core.Enums.CipherType.Login)
|
||||
{
|
||||
throw new ArgumentException("Cipher is not correct type.");
|
||||
}
|
||||
|
||||
var data = JsonConvert.DeserializeObject<LoginDataModel>(cipher.Data);
|
||||
|
||||
Name = data.Name;
|
||||
Uri = data.Uri;
|
||||
Username = data.Username;
|
||||
Password = data.Password;
|
||||
Notes = data.Notes;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class DeleteAccountRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class EmailRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[StringLength(50)]
|
||||
public string NewEmail { get; set; }
|
||||
[Required]
|
||||
[StringLength(300)]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
[StringLength(300)]
|
||||
public string NewMasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
public string Token { get; set; }
|
||||
[Required]
|
||||
public CipherRequestModel[] Ciphers { get; set; }
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class EmailTokenRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[StringLength(50)]
|
||||
public string NewEmail { get; set; }
|
||||
[Required]
|
||||
[StringLength(300)]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ImportRequestModel
|
||||
{
|
||||
private LoginRequestModel[] _logins;
|
||||
|
||||
public FolderRequestModel[] Folders { get; set; }
|
||||
[Obsolete]
|
||||
public LoginRequestModel[] Sites
|
||||
{
|
||||
get { return _logins; }
|
||||
set { _logins = value; }
|
||||
}
|
||||
public LoginRequestModel[] Logins
|
||||
{
|
||||
get { return _logins; }
|
||||
set { _logins = value; }
|
||||
}
|
||||
public KeyValuePair<int, int>[] FolderRelationships { get; set; }
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class KeysRequestModel
|
||||
{
|
||||
public string PublicKey { get; set; }
|
||||
[Required]
|
||||
public string EncryptedPrivateKey { get; set; }
|
||||
|
||||
public User ToUser(User existingUser)
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(PublicKey))
|
||||
{
|
||||
existingUser.PublicKey = PublicKey;
|
||||
}
|
||||
|
||||
existingUser.PrivateKey = EncryptedPrivateKey;
|
||||
return existingUser;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class PasswordHintRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[StringLength(50)]
|
||||
public string Email { get; set; }
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class PasswordRequestModel
|
||||
{
|
||||
[Required]
|
||||
[StringLength(300)]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
[StringLength(300)]
|
||||
public string NewMasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
public CipherRequestModel[] Ciphers { get; set; }
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class RecoverTwoFactorRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[StringLength(50)]
|
||||
public string Email { get; set; }
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
[StringLength(32)]
|
||||
public string RecoveryCode { get; set; }
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class RegenerateTwoFactorRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
public string Token { get; set; }
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class RegisterRequestModel
|
||||
{
|
||||
[StringLength(50)]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[StringLength(50)]
|
||||
public string Email { get; set; }
|
||||
[Required]
|
||||
[StringLength(1000)]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[StringLength(50)]
|
||||
public string MasterPasswordHint { get; set; }
|
||||
public KeysRequestModel Keys { get; set; }
|
||||
|
||||
public User ToUser()
|
||||
{
|
||||
var user = new User
|
||||
{
|
||||
Name = Name,
|
||||
Email = Email,
|
||||
MasterPasswordHint = MasterPasswordHint
|
||||
};
|
||||
|
||||
if(Keys != null)
|
||||
{
|
||||
Keys.ToUser(user);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class SecurityStampRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class UpdateProfileRequestModel
|
||||
{
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
public string Name { get; set; }
|
||||
[StringLength(50)]
|
||||
public string MasterPasswordHint { get; set; }
|
||||
[Required]
|
||||
[RegularExpression("^[a-z]{2}-[A-Z]{2}$")]
|
||||
public string Culture { get; set; }
|
||||
|
||||
public User ToUser(User existingUser)
|
||||
{
|
||||
existingUser.Name = Name;
|
||||
existingUser.MasterPasswordHint = string.IsNullOrWhiteSpace(MasterPasswordHint) ? null : MasterPasswordHint;
|
||||
existingUser.Culture = Culture;
|
||||
|
||||
return existingUser;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class UpdateTwoFactorRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
public bool? Enabled { get; set; }
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
public string Token { get; set; }
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class AuthTokenRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[StringLength(50)]
|
||||
public string Email { get; set; }
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
public DeviceRequestModel Device { get; set; }
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class AuthTokenTwoFactorRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string Code { get; set; }
|
||||
[Required]
|
||||
public string Provider { get; set; }
|
||||
public DeviceRequestModel Device { get; set; }
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Api.Utilities;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class CipherRequestModel
|
||||
{
|
||||
public CipherType Type { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(36)]
|
||||
public string Id { get; set; }
|
||||
[StringLength(36)]
|
||||
public string FolderId { get; set; }
|
||||
[Required]
|
||||
[EncryptedString]
|
||||
[StringLength(300)]
|
||||
public string Name { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(10000)]
|
||||
public string Uri { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(300)]
|
||||
public string Username { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(300)]
|
||||
public string Password { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(10000)]
|
||||
public string Notes { get; set; }
|
||||
|
||||
public virtual Cipher ToCipher(Guid userId)
|
||||
{
|
||||
var cipher = new Cipher
|
||||
{
|
||||
Id = new Guid(Id),
|
||||
UserId = userId,
|
||||
FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId),
|
||||
Type = Type
|
||||
};
|
||||
|
||||
switch(Type)
|
||||
{
|
||||
case CipherType.Folder:
|
||||
cipher.Data = JsonConvert.SerializeObject(new FolderDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
break;
|
||||
case CipherType.Login:
|
||||
cipher.Data = JsonConvert.SerializeObject(new LoginDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
|
||||
}
|
||||
|
||||
return cipher;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class DeviceRequestModel
|
||||
{
|
||||
[Required]
|
||||
public DeviceType? Type { get; set; }
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
public string Identifier { get; set; }
|
||||
[StringLength(255)]
|
||||
public string PushToken { get; set; }
|
||||
|
||||
public Device ToDevice(Guid? userId = null)
|
||||
{
|
||||
return ToDevice(new Device
|
||||
{
|
||||
UserId = userId == null ? default(Guid) : userId.Value
|
||||
});
|
||||
}
|
||||
|
||||
public Device ToDevice(Device existingDevice)
|
||||
{
|
||||
existingDevice.Name = Name;
|
||||
existingDevice.Identifier = Identifier;
|
||||
existingDevice.PushToken = PushToken;
|
||||
existingDevice.Type = Type.Value;
|
||||
|
||||
return existingDevice;
|
||||
}
|
||||
}
|
||||
|
||||
public class DeviceTokenRequestModel
|
||||
{
|
||||
[StringLength(255)]
|
||||
public string PushToken { get; set; }
|
||||
|
||||
public Device ToDevice(Device existingDevice)
|
||||
{
|
||||
existingDevice.PushToken = PushToken;
|
||||
return existingDevice;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Api.Utilities;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class FolderRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EncryptedString]
|
||||
[StringLength(300)]
|
||||
public string Name { get; set; }
|
||||
|
||||
public Cipher ToCipher(Guid userId)
|
||||
{
|
||||
return ToCipher(new Cipher
|
||||
{
|
||||
UserId = userId
|
||||
});
|
||||
}
|
||||
|
||||
public Cipher ToCipher(Cipher existingFolder)
|
||||
{
|
||||
existingFolder.Data = JsonConvert.SerializeObject(new FolderDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
existingFolder.Type = Core.Enums.CipherType.Folder;
|
||||
|
||||
return existingFolder;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Api.Utilities;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class LoginRequestModel
|
||||
{
|
||||
[StringLength(36)]
|
||||
public string FolderId { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
[Required]
|
||||
[EncryptedString]
|
||||
[StringLength(300)]
|
||||
public string Name { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(10000)]
|
||||
public string Uri { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(300)]
|
||||
public string Username { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(300)]
|
||||
public string Password { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(10000)]
|
||||
public string Notes { get; set; }
|
||||
|
||||
public Cipher ToCipher(Guid userId)
|
||||
{
|
||||
return ToCipher(new Cipher
|
||||
{
|
||||
UserId = userId
|
||||
});
|
||||
}
|
||||
|
||||
public Cipher ToCipher(Cipher existingLogin)
|
||||
{
|
||||
existingLogin.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId);
|
||||
existingLogin.Favorite = Favorite;
|
||||
existingLogin.Data = JsonConvert.SerializeObject(new LoginDataModel(this),
|
||||
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
existingLogin.Type = Core.Enums.CipherType.Login;
|
||||
|
||||
return existingLogin;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Business;
|
||||
using System;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class OrganizationCreateRequestModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public PlanType PlanType { get; set; }
|
||||
public string Key { get; set; }
|
||||
|
||||
public virtual OrganizationSignup ToOrganizationSignup(User user)
|
||||
{
|
||||
return new OrganizationSignup
|
||||
{
|
||||
Owner = user,
|
||||
OwnerKey = Key,
|
||||
Name = Name,
|
||||
Plan = PlanType
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class OrganizationUpdateRequestModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual Organization ToOrganization(Organization existingOrganization)
|
||||
{
|
||||
existingOrganization.Name = Name;
|
||||
return existingOrganization;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class OrganizationUserInviteRequestModel
|
||||
{
|
||||
public string Email { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationUserAcceptRequestModel
|
||||
{
|
||||
public string Token { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationUserConfirmRequestModel
|
||||
{
|
||||
public string Key { get; set; }
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Api.Utilities;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class SubvaultCreateRequestModel : SubvaultUpdateRequestModel
|
||||
{
|
||||
public string OrganizationId { get; set; }
|
||||
|
||||
public Subvault ToSubvault()
|
||||
{
|
||||
return ToSubvault(new Subvault
|
||||
{
|
||||
OrganizationId = new Guid(OrganizationId)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class SubvaultUpdateRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EncryptedString]
|
||||
[StringLength(300)]
|
||||
public string Name { get; set; }
|
||||
|
||||
public Subvault ToSubvault(Subvault existingSubvault)
|
||||
{
|
||||
existingSubvault.Name = Name;
|
||||
return existingSubvault;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
using Bit.Core.Models.Table;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class AuthTokenResponseModel : ResponseModel
|
||||
{
|
||||
public AuthTokenResponseModel(string token, User user = null)
|
||||
: base("authToken")
|
||||
{
|
||||
Token = token;
|
||||
Profile = user == null ? null : new ProfileResponseModel(user, null);
|
||||
}
|
||||
|
||||
public string Token { get; set; }
|
||||
public ProfileResponseModel Profile { get; set; }
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class CipherHistoryResponseModel : ResponseModel
|
||||
{
|
||||
public CipherHistoryResponseModel(IEnumerable<Cipher> revisedCiphers, IEnumerable<Guid> deletedIds, Guid userId)
|
||||
: base("cipherHistory")
|
||||
{
|
||||
if(revisedCiphers == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(revisedCiphers));
|
||||
}
|
||||
|
||||
if(deletedIds == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(deletedIds));
|
||||
}
|
||||
|
||||
Revised = revisedCiphers.Select(c => new CipherResponseModel(c, userId));
|
||||
Deleted = deletedIds.Select(id => id.ToString());
|
||||
}
|
||||
|
||||
public IEnumerable<CipherResponseModel> Revised { get; set; }
|
||||
public IEnumerable<string> Deleted { get; set; }
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class CipherResponseModel : ResponseModel
|
||||
{
|
||||
public CipherResponseModel(Cipher cipher, Guid userId, string obj = "cipher")
|
||||
: base(obj)
|
||||
{
|
||||
if(cipher == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cipher));
|
||||
}
|
||||
|
||||
Id = cipher.Id.ToString();
|
||||
FolderId = cipher.FolderId?.ToString();
|
||||
Type = cipher.Type;
|
||||
Favorite = cipher.Favorite;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
|
||||
switch(cipher.Type)
|
||||
{
|
||||
case Core.Enums.CipherType.Folder:
|
||||
Data = new FolderDataModel(cipher);
|
||||
break;
|
||||
case Core.Enums.CipherType.Login:
|
||||
Data = new LoginDataModel(cipher);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string FolderId { get; set; }
|
||||
public Core.Enums.CipherType Type { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
public dynamic Data { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class DeviceResponseModel : ResponseModel
|
||||
{
|
||||
public DeviceResponseModel(Device device)
|
||||
: base("device")
|
||||
{
|
||||
if(device == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(device));
|
||||
}
|
||||
|
||||
Id = device.Id.ToString();
|
||||
Name = device.Name;
|
||||
Type = device.Type;
|
||||
Identifier = device.Identifier;
|
||||
CreationDate = device.CreationDate;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DeviceType Type { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Bit.Core.Enums;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class DomainsResponseModel : ResponseModel
|
||||
{
|
||||
public DomainsResponseModel(User user, bool excluded = true)
|
||||
: base("domains")
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
EquivalentDomains = user.EquivalentDomains != null ?
|
||||
JsonConvert.DeserializeObject<List<List<string>>>(user.EquivalentDomains) : null;
|
||||
|
||||
var excludedGlobalEquivalentDomains = user.ExcludedGlobalEquivalentDomains != null ?
|
||||
JsonConvert.DeserializeObject<List<GlobalEquivalentDomainsType>>(user.ExcludedGlobalEquivalentDomains) :
|
||||
new List<GlobalEquivalentDomainsType>();
|
||||
var globalDomains = new List<GlobalDomains>();
|
||||
var domainsToInclude = excluded ? Core.Utilities.StaticStore.GlobalDomains :
|
||||
Core.Utilities.StaticStore.GlobalDomains.Where(d => !excludedGlobalEquivalentDomains.Contains(d.Key));
|
||||
foreach(var domain in domainsToInclude)
|
||||
{
|
||||
globalDomains.Add(new GlobalDomains(domain.Key, domain.Value, excludedGlobalEquivalentDomains, excluded));
|
||||
}
|
||||
GlobalEquivalentDomains = !globalDomains.Any() ? null : globalDomains;
|
||||
}
|
||||
|
||||
public IEnumerable<IEnumerable<string>> EquivalentDomains { get; set; }
|
||||
public IEnumerable<GlobalDomains> GlobalEquivalentDomains { get; set; }
|
||||
|
||||
|
||||
public class GlobalDomains
|
||||
{
|
||||
public GlobalDomains(
|
||||
GlobalEquivalentDomainsType globalDomain,
|
||||
IEnumerable<string> domains,
|
||||
IEnumerable<GlobalEquivalentDomainsType> excludedDomains,
|
||||
bool excluded)
|
||||
{
|
||||
Type = globalDomain;
|
||||
Domains = domains;
|
||||
Excluded = excluded && (excludedDomains?.Contains(globalDomain) ?? false);
|
||||
}
|
||||
|
||||
public GlobalEquivalentDomainsType Type { get; set; }
|
||||
public IEnumerable<string> Domains { get; set; }
|
||||
public bool Excluded { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace Bit.Api.Models.Response
|
||||
{
|
||||
public class ErrorResponseModel : ResponseModel
|
||||
{
|
||||
public ErrorResponseModel()
|
||||
: base("error")
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(string message)
|
||||
: this()
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public ErrorResponseModel(ModelStateDictionary modelState)
|
||||
: this()
|
||||
{
|
||||
Message = "The model state is invalid.";
|
||||
ValidationErrors = new Dictionary<string, IEnumerable<string>>();
|
||||
|
||||
var keys = modelState.Keys.ToList();
|
||||
var values = modelState.Values.ToList();
|
||||
|
||||
for(var i = 0; i < values.Count; i++)
|
||||
{
|
||||
var value = values[i];
|
||||
|
||||
if(keys.Count <= i)
|
||||
{
|
||||
// Keys not available for some reason.
|
||||
break;
|
||||
}
|
||||
|
||||
var key = keys[i];
|
||||
|
||||
if(value.ValidationState != ModelValidationState.Invalid || value.Errors.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var errors = value.Errors.Select(e => e.ErrorMessage);
|
||||
ValidationErrors.Add(key, errors);
|
||||
}
|
||||
}
|
||||
|
||||
public string Message { get; set; }
|
||||
public Dictionary<string, IEnumerable<string>> ValidationErrors { get; set; }
|
||||
// For use in development environments.
|
||||
public string ExceptionMessage { get; set; }
|
||||
public string ExceptionStackTrace { get; set; }
|
||||
public string InnerExceptionMessage { get; set; }
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class FolderResponseModel : ResponseModel
|
||||
{
|
||||
public FolderResponseModel(Cipher cipher, Guid userId)
|
||||
: base("folder")
|
||||
{
|
||||
if(cipher == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cipher));
|
||||
}
|
||||
|
||||
if(cipher.Type != Core.Enums.CipherType.Folder)
|
||||
{
|
||||
throw new ArgumentException(nameof(cipher.Type));
|
||||
}
|
||||
|
||||
var data = new FolderDataModel(cipher);
|
||||
|
||||
Id = cipher.Id.ToString();
|
||||
Name = data.Name;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class KeysResponseModel : ResponseModel
|
||||
{
|
||||
public KeysResponseModel(User user)
|
||||
: base("keys")
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
PublicKey = user.PublicKey;
|
||||
PrivateKey = user.PrivateKey;
|
||||
}
|
||||
|
||||
public string PublicKey { get; set; }
|
||||
public string PrivateKey { get; set; }
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ListResponseModel<T> : ResponseModel where T : ResponseModel
|
||||
{
|
||||
public ListResponseModel(IEnumerable<T> data)
|
||||
: base("list")
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public IEnumerable<T> Data { get; set; }
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class LoginResponseModel : ResponseModel
|
||||
{
|
||||
public LoginResponseModel(Cipher cipher, Guid userId, string obj = "login")
|
||||
: base(obj)
|
||||
{
|
||||
if(cipher == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cipher));
|
||||
}
|
||||
|
||||
if(cipher.Type != Core.Enums.CipherType.Login)
|
||||
{
|
||||
throw new ArgumentException(nameof(cipher.Type));
|
||||
}
|
||||
|
||||
var data = new LoginDataModel(cipher);
|
||||
|
||||
Id = cipher.Id.ToString();
|
||||
FolderId = cipher.FolderId?.ToString();
|
||||
Favorite = cipher.Favorite;
|
||||
Name = data.Name;
|
||||
Uri = data.Uri;
|
||||
Username = data.Username;
|
||||
Password = data.Password;
|
||||
Notes = data.Notes;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string FolderId { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
|
||||
// Expandables
|
||||
public FolderResponseModel Folder { get; set; }
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class OrganizationResponseModel : ResponseModel
|
||||
{
|
||||
public OrganizationResponseModel(Organization organization, string obj = "organization")
|
||||
: base(obj)
|
||||
{
|
||||
if(organization == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organization));
|
||||
}
|
||||
|
||||
Id = organization.Id.ToString();
|
||||
Name = organization.Name;
|
||||
Plan = organization.Plan;
|
||||
PlanType = organization.PlanType;
|
||||
PlanTrial = organization.PlanTrial;
|
||||
MaxUsers = organization.MaxUsers;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Plan { get; set; }
|
||||
public Core.Enums.PlanType PlanType { get; set; }
|
||||
public bool PlanTrial { get; set; }
|
||||
public short MaxUsers { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationExtendedResponseModel : OrganizationResponseModel
|
||||
{
|
||||
public OrganizationExtendedResponseModel(Organization organization, OrganizationUser organizationUser)
|
||||
: base(organization, "organizationExtended")
|
||||
{
|
||||
if(organizationUser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organizationUser));
|
||||
}
|
||||
|
||||
Key = organizationUser.Key;
|
||||
}
|
||||
|
||||
public string Key { get; set; }
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class OrganizationUserResponseModel : ResponseModel
|
||||
{
|
||||
public OrganizationUserResponseModel(OrganizationUserUserDetails organizationUser, string obj = "organizationUser")
|
||||
: base(obj)
|
||||
{
|
||||
if(organizationUser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organizationUser));
|
||||
}
|
||||
|
||||
Id = organizationUser.Id.ToString();
|
||||
UserId = organizationUser.UserId?.ToString();
|
||||
Name = organizationUser.Name;
|
||||
Email = organizationUser.Email;
|
||||
Type = organizationUser.Type;
|
||||
Status = organizationUser.Status;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public OrganizationUserType Type { get; set; }
|
||||
public OrganizationUserStatusType Status { get; set; }
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ProfileOrganizationResponseModel : ResponseModel
|
||||
{
|
||||
public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails organization)
|
||||
: base("profileOrganization")
|
||||
{
|
||||
Id = organization.OrganizationId.ToString();
|
||||
Name = organization.Name;
|
||||
Key = organization.Key;
|
||||
Status = organization.Status;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Key { get; set; }
|
||||
public OrganizationUserStatusType Status { get; set; }
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ProfileResponseModel : ResponseModel
|
||||
{
|
||||
public ProfileResponseModel(User user, IEnumerable<OrganizationUserOrganizationDetails> organizationsUserDetails)
|
||||
: base("profile")
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
Id = user.Id.ToString();
|
||||
Name = user.Name;
|
||||
Email = user.Email;
|
||||
MasterPasswordHint = string.IsNullOrWhiteSpace(user.MasterPasswordHint) ? null : user.MasterPasswordHint;
|
||||
Culture = user.Culture;
|
||||
TwoFactorEnabled = user.TwoFactorEnabled;
|
||||
Organizations = organizationsUserDetails?.Select(o => new ProfileOrganizationResponseModel(o));
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string MasterPasswordHint { get; set; }
|
||||
public string Culture { get; set; }
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
public IEnumerable<ProfileOrganizationResponseModel> Organizations { get; set; }
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public abstract class ResponseModel
|
||||
{
|
||||
public ResponseModel(string obj)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(obj))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
Object = obj;
|
||||
}
|
||||
|
||||
public string Object { get; private set; }
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class SubvaultResponseModel : ResponseModel
|
||||
{
|
||||
public SubvaultResponseModel(Subvault subvault)
|
||||
: base("subvault")
|
||||
{
|
||||
if(subvault == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(subvault));
|
||||
}
|
||||
|
||||
Id = subvault.Id.ToString();
|
||||
OrganizationId = subvault.OrganizationId.ToString();
|
||||
Name = subvault.Name;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class TwoFactorResponseModel : ResponseModel
|
||||
{
|
||||
public TwoFactorResponseModel(User user)
|
||||
: base("twoFactor")
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
TwoFactorEnabled = user.TwoFactorEnabled;
|
||||
AuthenticatorKey = user.AuthenticatorKey;
|
||||
TwoFactorProvider = user.TwoFactorProvider;
|
||||
TwoFactorRecoveryCode = user.TwoFactorRecoveryCode;
|
||||
}
|
||||
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
public TwoFactorProviderType? TwoFactorProvider { get; set; }
|
||||
public string AuthenticatorKey { get; set; }
|
||||
public string TwoFactorRecoveryCode { get; set; }
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class UserKeyResponseModel : ResponseModel
|
||||
{
|
||||
public UserKeyResponseModel(Guid id, string key)
|
||||
: base("userKey")
|
||||
{
|
||||
UserId = id.ToString();
|
||||
PublicKey = key;
|
||||
}
|
||||
|
||||
public string UserId { get; set; }
|
||||
public string PublicKey { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user