1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-22 21:51:22 +01:00

remove user twofactorenabled property

This commit is contained in:
Kyle Spearrin 2017-06-19 22:25:19 -04:00
parent 3b5b24531b
commit 2eaaecd95c
9 changed files with 25 additions and 43 deletions

View File

@ -14,7 +14,7 @@ namespace Bit.Core.Identity
{
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Duo);
var canGenerate = user.TwoFactorIsEnabled(TwoFactorProviderType.Duo)
var canGenerate = user.TwoFactorProviderIsEnabled(TwoFactorProviderType.Duo)
&& user.TwoFactorProvider.HasValue
&& user.TwoFactorProvider.Value == TwoFactorProviderType.Duo
&& !string.IsNullOrWhiteSpace(provider?.MetaData["UserId"]);

View File

@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Bit.Core.Models.Table;
using Bit.Core.Repositories;
using Bit.Core.Services;
namespace Bit.Core.Identity
{
@ -162,7 +158,7 @@ namespace Bit.Core.Identity
public Task SetTwoFactorEnabledAsync(User user, bool enabled, CancellationToken cancellationToken)
{
user.TwoFactorEnabled = enabled;
// Do nothing...
return Task.FromResult(0);
}

View File

@ -3,6 +3,7 @@ using Bit.Core.Enums;
using Bit.Core.Utilities;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Linq;
namespace Bit.Core.Models.Table
{
@ -18,7 +19,6 @@ namespace Bit.Core.Models.Table
public string MasterPasswordHint { get; set; }
public string Culture { get; set; } = "en-US";
public string SecurityStamp { get; set; }
public bool TwoFactorEnabled { get; set; }
public TwoFactorProviderType? TwoFactorProvider { get; set; }
public string TwoFactorProviders { get; set; }
public string TwoFactorRecoveryCode { get; set; }
@ -79,14 +79,15 @@ namespace Bit.Core.Models.Table
return providers[provider].Enabled;
}
public bool TwoFactorIsEnabled(TwoFactorProviderType provider)
{
return TwoFactorEnabled && TwoFactorProviderIsEnabled(provider);
}
public bool TwoFactorIsEnabled()
{
return TwoFactorEnabled && TwoFactorProvider.HasValue && TwoFactorProviderIsEnabled(TwoFactorProvider.Value);
var providers = GetTwoFactorProviders();
if(providers == null)
{
return false;
}
return providers.Any(p => p.Value?.Enabled ?? false);
}
public TwoFactorProvider GetTwoFactorProvider(TwoFactorProviderType provider)

View File

@ -415,7 +415,8 @@ namespace Bit.Core.Services
return false;
}
user.TwoFactorEnabled = false;
user.TwoFactorProviders = null;
user.TwoFactorProvider = null;
user.TwoFactorRecoveryCode = null;
await SaveUserAsync(user);

View File

@ -7,7 +7,6 @@
@MasterPasswordHint NVARCHAR(50),
@Culture NVARCHAR(10),
@SecurityStamp NVARCHAR(50),
@TwoFactorEnabled BIT,
@TwoFactorProvider TINYINT,
@TwoFactorProviders NVARCHAR(MAX),
@TwoFactorRecoveryCode NVARCHAR(32),
@ -33,7 +32,6 @@ BEGIN
[MasterPasswordHint],
[Culture],
[SecurityStamp],
[TwoFactorEnabled],
[TwoFactorProvider],
[TwoFactorProviders],
[TwoFactorRecoveryCode],
@ -56,7 +54,6 @@ BEGIN
@MasterPasswordHint,
@Culture,
@SecurityStamp,
@TwoFactorEnabled,
@TwoFactorProvider,
@TwoFactorProviders,
@TwoFactorRecoveryCode,

View File

@ -7,7 +7,6 @@
@MasterPasswordHint NVARCHAR(50),
@Culture NVARCHAR(10),
@SecurityStamp NVARCHAR(50),
@TwoFactorEnabled BIT,
@TwoFactorProvider TINYINT,
@TwoFactorProviders NVARCHAR(MAX),
@TwoFactorRecoveryCode NVARCHAR(32),
@ -33,7 +32,6 @@ BEGIN
[MasterPasswordHint] = @MasterPasswordHint,
[Culture] = @Culture,
[SecurityStamp] = @SecurityStamp,
[TwoFactorEnabled] = @TwoFactorEnabled,
[TwoFactorProvider] = @TwoFactorProvider,
[TwoFactorProviders] = @TwoFactorProviders,
[TwoFactorRecoveryCode] = @TwoFactorRecoveryCode,

View File

@ -7,7 +7,6 @@
[MasterPasswordHint] NVARCHAR (50) NULL,
[Culture] NVARCHAR (10) NOT NULL,
[SecurityStamp] NVARCHAR (50) NOT NULL,
[TwoFactorEnabled] BIT NOT NULL,
[TwoFactorProvider] TINYINT NULL,
[TwoFactorProviders] NVARCHAR (MAX) NULL,
[TwoFactorRecoveryCode] NVARCHAR (32) NULL,

View File

@ -1,23 +0,0 @@
alter table [user] add [TwoFactorProviders] NVARCHAR (MAX) NULL
go
update [user]
set twofactorproviders = '{"0":{"Enabled":'+ (case when twofactorenabled = 1 then 'true' else 'false' end) +',"Remember":true,"MetaData":{"Key":"'+ authenticatorkey +'"}}}'
where twofactorprovider is not null and twofactorprovider = 0
and authenticatorkey is not null
go
alter table [user] drop column authenticatorkey
go
drop view [userview]
go
CREATE VIEW [dbo].[UserView]
AS
SELECT
*
FROM
[dbo].[User]
go

View File

@ -0,0 +1,13 @@
alter table [user] drop column twofactorenabled
go
drop view [dbo].[UserView]
go
CREATE VIEW [dbo].[UserView]
AS
SELECT
*
FROM
[dbo].[User]
GO