2015-12-08 22:57:38 -05:00
|
|
|
|
using System;
|
|
|
|
|
|
using Bit.Core.Enums;
|
2016-05-21 17:16:22 -04:00
|
|
|
|
using Bit.Core.Utilities;
|
2017-06-07 14:14:34 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2015-12-08 22:57:38 -05:00
|
|
|
|
|
2017-03-08 21:45:08 -05:00
|
|
|
|
namespace Bit.Core.Models.Table
|
2015-12-08 22:57:38 -05:00
|
|
|
|
{
|
2016-05-21 17:16:22 -04:00
|
|
|
|
public class User : IDataObject<Guid>
|
2015-12-08 22:57:38 -05:00
|
|
|
|
{
|
2017-06-07 14:14:34 -04:00
|
|
|
|
private Dictionary<TwoFactorProviderType, TwoFactorProvider> _twoFactorProviders;
|
|
|
|
|
|
|
2016-05-21 17:16:22 -04:00
|
|
|
|
public Guid Id { get; set; }
|
2015-12-08 22:57:38 -05:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
public string Email { get; set; }
|
2016-02-21 00:50:53 -05:00
|
|
|
|
public bool EmailVerified { get; set; }
|
2015-12-08 22:57:38 -05:00
|
|
|
|
public string MasterPassword { get; set; }
|
|
|
|
|
|
public string MasterPasswordHint { get; set; }
|
2016-01-07 23:01:01 -05:00
|
|
|
|
public string Culture { get; set; } = "en-US";
|
2015-12-08 22:57:38 -05:00
|
|
|
|
public string SecurityStamp { get; set; }
|
|
|
|
|
|
public bool TwoFactorEnabled { get; set; }
|
2017-01-09 22:20:34 -05:00
|
|
|
|
public TwoFactorProviderType? TwoFactorProvider { get; set; }
|
2015-12-08 22:57:38 -05:00
|
|
|
|
public string AuthenticatorKey { get; set; }
|
2017-06-06 17:15:19 -04:00
|
|
|
|
public string TwoFactorProviders { get; set; }
|
2016-11-14 21:13:53 -05:00
|
|
|
|
public string TwoFactorRecoveryCode { get; set; }
|
2017-01-09 22:20:34 -05:00
|
|
|
|
public string EquivalentDomains { get; set; }
|
|
|
|
|
|
public string ExcludedGlobalEquivalentDomains { get; set; }
|
2017-01-14 10:02:37 -05:00
|
|
|
|
public DateTime AccountRevisionDate { get; internal set; } = DateTime.UtcNow;
|
2017-05-31 09:54:32 -04:00
|
|
|
|
public string Key { get; set; }
|
2017-02-11 23:00:55 -05:00
|
|
|
|
public string PublicKey { get; set; }
|
|
|
|
|
|
public string PrivateKey { get; set; }
|
2015-12-08 22:57:38 -05:00
|
|
|
|
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
2016-02-20 23:25:44 -05:00
|
|
|
|
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
2016-05-21 17:16:22 -04:00
|
|
|
|
|
|
|
|
|
|
public void SetNewId()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = CoreHelpers.GenerateComb();
|
|
|
|
|
|
}
|
2017-06-07 14:14:34 -04:00
|
|
|
|
|
|
|
|
|
|
public Dictionary<TwoFactorProviderType, TwoFactorProvider> GetTwoFactorProviders()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(TwoFactorProviders))
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_twoFactorProviders == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_twoFactorProviders =
|
|
|
|
|
|
JsonConvert.DeserializeObject<Dictionary<TwoFactorProviderType, TwoFactorProvider>>(TwoFactorProviders);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _twoFactorProviders;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(JsonSerializationException)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetTwoFactorProviders(Dictionary<TwoFactorProviderType, TwoFactorProvider> providers)
|
|
|
|
|
|
{
|
|
|
|
|
|
TwoFactorProviders = JsonConvert.SerializeObject(providers, new JsonSerializerSettings
|
|
|
|
|
|
{
|
|
|
|
|
|
ContractResolver = new EnumKeyResolver<byte>()
|
|
|
|
|
|
});
|
|
|
|
|
|
_twoFactorProviders = providers;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool TwoFactorProviderIsEnabled(TwoFactorProviderType provider)
|
|
|
|
|
|
{
|
|
|
|
|
|
var providers = GetTwoFactorProviders();
|
|
|
|
|
|
if(providers == null || !providers.ContainsKey(provider))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return providers[provider].Enabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool TwoFactorIsEnabled(TwoFactorProviderType provider)
|
|
|
|
|
|
{
|
|
|
|
|
|
return TwoFactorEnabled && TwoFactorProviderIsEnabled(provider);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool TwoFactorIsEnabled()
|
|
|
|
|
|
{
|
|
|
|
|
|
return TwoFactorEnabled && TwoFactorProvider.HasValue && TwoFactorProviderIsEnabled(TwoFactorProvider.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TwoFactorProvider GetTwoFactorProvider(TwoFactorProviderType provider)
|
|
|
|
|
|
{
|
|
|
|
|
|
var providers = GetTwoFactorProviders();
|
|
|
|
|
|
if(providers == null || !providers.ContainsKey(provider))
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return providers[provider];
|
|
|
|
|
|
}
|
2015-12-08 22:57:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|