1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 17:12:49 -05:00

move all models into core

This commit is contained in:
Kyle Spearrin
2017-03-08 21:55:08 -05:00
parent bd0c960e9f
commit 8bcd4e0463
60 changed files with 64 additions and 64 deletions

View File

@ -1,10 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Api.Models
{
public class DeleteAccountRequestModel
{
[Required]
public string MasterPasswordHash { get; set; }
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Api.Models
{
public class PasswordHintRequestModel
{
[Required]
[EmailAddress]
[StringLength(50)]
public string Email { get; set; }
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Api.Models
{
public class SecurityStampRequestModel
{
[Required]
public string MasterPasswordHash { get; set; }
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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