mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
admin login apis
This commit is contained in:
@ -9,6 +9,8 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class LoginRequestModel
|
||||
{
|
||||
[StringLength(36)]
|
||||
public string OrganizationId { get; set; }
|
||||
[StringLength(36)]
|
||||
public string FolderId { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
@ -33,7 +35,21 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
return ToCipherDetails(new CipherDetails
|
||||
{
|
||||
UserId = userId
|
||||
UserId = string.IsNullOrWhiteSpace(OrganizationId) ? (Guid?)userId : null,
|
||||
OrganizationId = string.IsNullOrWhiteSpace(OrganizationId) ? (Guid?)null : new Guid(OrganizationId)
|
||||
});
|
||||
}
|
||||
|
||||
public Cipher ToOrganizationCipher()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(OrganizationId))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(OrganizationId));
|
||||
}
|
||||
|
||||
return ToCipher(new Cipher
|
||||
{
|
||||
OrganizationId = new Guid(OrganizationId)
|
||||
});
|
||||
}
|
||||
|
||||
@ -48,6 +64,15 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
return existingLogin;
|
||||
}
|
||||
|
||||
public Cipher ToCipher(Cipher existingLogin)
|
||||
{
|
||||
existingLogin.Data = JsonConvert.SerializeObject(new LoginDataModel(this),
|
||||
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
existingLogin.Type = Enums.CipherType.Login;
|
||||
|
||||
return existingLogin;
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginWithIdRequestModel : LoginRequestModel
|
||||
|
@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using Core.Models.Data;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class LoginResponseModel : ResponseModel
|
||||
{
|
||||
public LoginResponseModel(CipherDetails cipher, string obj = "login")
|
||||
public LoginResponseModel(Cipher cipher, string obj = "login")
|
||||
: base(obj)
|
||||
{
|
||||
if(cipher == null)
|
||||
@ -22,8 +23,6 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
Id = cipher.Id.ToString();
|
||||
OrganizationId = cipher.OrganizationId?.ToString();
|
||||
FolderId = cipher.FolderId?.ToString();
|
||||
Favorite = cipher.Favorite;
|
||||
Name = data.Name;
|
||||
Uri = data.Uri;
|
||||
Username = data.Username;
|
||||
@ -32,6 +31,13 @@ namespace Bit.Core.Models.Api
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
}
|
||||
|
||||
public LoginResponseModel(CipherDetails cipher, string obj = "login")
|
||||
: this(cipher as Cipher, obj)
|
||||
{
|
||||
FolderId = cipher.FolderId?.ToString();
|
||||
Favorite = cipher.Favorite;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public string FolderId { get; set; }
|
||||
|
Reference in New Issue
Block a user