From c64e3a73df5f793957173e604f8e60625245bfb9 Mon Sep 17 00:00:00 2001 From: Falkvinge Date: Fri, 25 Nov 2016 17:54:33 +0100 Subject: [PATCH] More BitID work --- Site/Automation/SwarmFunctions.aspx.cs | 40 ++++++++++++++++++++++++++ Site/Master-v5.master | 18 ++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Site/Automation/SwarmFunctions.aspx.cs b/Site/Automation/SwarmFunctions.aspx.cs index ab2011c3..acbf6c26 100644 --- a/Site/Automation/SwarmFunctions.aspx.cs +++ b/Site/Automation/SwarmFunctions.aspx.cs @@ -495,5 +495,45 @@ namespace Swarmops.Frontend.Automation } } + public static AjaxCallResult RemoveBitId(int personId, string password) + { + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + if (personId == 0) // self + { + personId = authData.CurrentUser.Identity; + + if (!ValidatePassword(personId, password)) + { + // oldPassword field isn't correct + + // TODO: LOG THIS, THIS SHOULD NOT HAPPEN (UI FILTERING THIS CASE) + + // TODO: ALSO NOTIFY SECURITY OFFICERS + + // TODO: THROTTLE AND BLACKLIST? + + return new AjaxCallResult + { + Success = false, + DisplayMessage = Resources.Global.Master_EditPersonNewPassword_CannotChange_SecurityError + }; + } + + authData.CurrentUser.BitIdAddress = string.Empty; + + return new AjaxCallResult {Success = true}; + } + else + { + // Validate rights to remove BitId + // Log, notify, and chainnotify + + throw new NotImplementedException(); + } + + + } + } } \ No newline at end of file diff --git a/Site/Master-v5.master b/Site/Master-v5.master index 12c5cc0a..d55bcbf9 100644 --- a/Site/Master-v5.master +++ b/Site/Master-v5.master @@ -527,10 +527,21 @@ alertify.confirm(SwarmopsJS.unescape('<%=this.Localized_MasterPersonEdit_ConfirmRemove2FAOwn%>'), function (response) { if (response) { - // TODO: Enter password as a security measure (or check against entered) - alert("Success!"); + var jsonData = + { + password: <%=this.MasterEditPersonCurrentPassword.ClientID%>_value() + } + SwarmopsJS.ajaxCall("/Automation/SwarmFunctions.aspx/RemoveBitId", jsonData, function(result) { + if (result.Success) { + // Success: UX feedback is slider in "off" position + } else { + alertify.error(result.DisplayMessage); + <%= this.MasterEditPerson2FA.ClientID %>_initialize(true); + } + + }); } else { - <%= this.MasterEditPerson2FAProvisioning.ClientID %>_initialize(true); + <%= this.MasterEditPerson2FA.ClientID %>_initialize(true); alertify.log(SwarmopsJS.unescape('<%=this.Localized_MasterPersonEdit_Cancelled2FARemoval%>')); } }); @@ -650,6 +661,7 @@ function onBitIdRegisterRecheck() { SwarmopsJS.ajaxCall("/Automation/SwarmFunctions.aspx/TestBitIdRegister", {}, function(result) { + alertify.log(result.Success); if (result.Success) { _master_bitIdRecheckTimer = null; <%=this.ModalMasterEnableBitId%>_close();