Implemented user password self-change
This commit is contained in:
@@ -329,7 +329,7 @@ namespace Swarmops.Common.Enums
|
||||
BitcoinPayoutAddress,
|
||||
|
||||
/// <summary>
|
||||
/// When the bitcoin address was set (to enable quarantine)
|
||||
/// When the bitcoin address was set (to enable payout quarantine)
|
||||
/// </summary>
|
||||
BitcoinPayoutAddressTimeSet,
|
||||
|
||||
@@ -381,6 +381,21 @@ namespace Swarmops.Common.Enums
|
||||
/// <summary>
|
||||
/// When (if) the org pays taxes, what number to put on the payment to identify the sender
|
||||
/// </summary>
|
||||
OrgTaxPaymentOcr
|
||||
OrgTaxPaymentOcr,
|
||||
|
||||
/// <summary>
|
||||
/// Prohibit any financial payouts or withdrawals before this time (UTC).
|
||||
/// </summary>
|
||||
QuarantineWithdrawalsUntil,
|
||||
|
||||
/// <summary>
|
||||
/// Prohibit any login before this time (UTC).
|
||||
/// </summary>
|
||||
QuarantineLoginsUntil,
|
||||
|
||||
/// <summary>
|
||||
/// Prohibit all active sessions until this time (UTC).
|
||||
/// </summary>
|
||||
QuarantineSessionsUntil
|
||||
}
|
||||
}
|
||||
@@ -409,6 +409,8 @@
|
||||
<Compile Include="Swarm\PaymentCode.cs" />
|
||||
<Compile Include="Swarm\People.cs" />
|
||||
<Compile Include="Swarm\Person.cs" />
|
||||
<Compile Include="Swarm\PersonQuarantine.cs" />
|
||||
<Compile Include="Swarm\PersonQuarantines.cs" />
|
||||
<Compile Include="Swarm\PersonRole.cs" />
|
||||
<Compile Include="Swarm\Position.cs" />
|
||||
<Compile Include="Swarm\PositionAssignment.cs" />
|
||||
|
||||
@@ -1181,6 +1181,15 @@ namespace Swarmops.Logic.Swarm
|
||||
return Volunteer.Create (this);
|
||||
}
|
||||
|
||||
|
||||
public PersonQuarantines Quarantines
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PersonQuarantines(this);
|
||||
}
|
||||
}
|
||||
|
||||
// A couple of special cases
|
||||
|
||||
public const int OpenLedgersIdentity = -1;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public class PersonQuarantine
|
||||
{
|
||||
internal PersonQuarantine(Person person, ObjectOptionalDataType quarantineType) // internal: can only be constructed in assembly
|
||||
{
|
||||
this._person = person;
|
||||
this._quarantineType = quarantineType;
|
||||
}
|
||||
|
||||
public DateTime UntilWhen
|
||||
{
|
||||
get
|
||||
{
|
||||
string quarantineString = ObjectOptionalData.ForObject(this._person).GetOptionalDataString(this._quarantineType);
|
||||
|
||||
if (quarantineString.Length > 0)
|
||||
{
|
||||
return DateTime.ParseExact(quarantineString, "yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTime.MinValue; // no quarantine active
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
get { return (this.UntilWhen > DateTime.UtcNow); }
|
||||
}
|
||||
|
||||
public void QuarantineFor(TimeSpan span)
|
||||
{
|
||||
DateTime now = DateTime.UtcNow;
|
||||
DateTime quarantineUntil = now + span;
|
||||
|
||||
ObjectOptionalData.ForObject(this._person).SetOptionalDataString(this._quarantineType, quarantineUntil.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
private Person _person;
|
||||
private ObjectOptionalDataType _quarantineType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Common.Enums;
|
||||
|
||||
namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public class PersonQuarantines
|
||||
{
|
||||
internal PersonQuarantines(Person person) // internal: can only be constructed in assembly
|
||||
{
|
||||
this._person = person;
|
||||
}
|
||||
|
||||
public PersonQuarantine Withdrawal
|
||||
{
|
||||
get { return new PersonQuarantine(this._person, ObjectOptionalDataType.QuarantineWithdrawalsUntil); }
|
||||
}
|
||||
|
||||
public PersonQuarantine Login
|
||||
{
|
||||
get { return new PersonQuarantine(this._person, ObjectOptionalDataType.QuarantineLoginsUntil); }
|
||||
}
|
||||
|
||||
public PersonQuarantine Sessions
|
||||
{
|
||||
get { return new PersonQuarantine(this._person, ObjectOptionalDataType.QuarantineSessionsUntil); }
|
||||
}
|
||||
|
||||
private Person _person;
|
||||
}
|
||||
}
|
||||
+27
@@ -1554,6 +1554,33 @@ namespace Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unable to set new password: The old password is incorrect..
|
||||
/// </summary>
|
||||
internal static string Master_EditPersonNewPassword_CannotChange_SecurityError {
|
||||
get {
|
||||
return ResourceManager.GetString("Master_EditPersonNewPassword_CannotChange_SecurityError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unable to set new password: The new password is too weak. Use a stronger password..
|
||||
/// </summary>
|
||||
internal static string Master_EditPersonNewPassword_CannotChange_TooWeak {
|
||||
get {
|
||||
return ResourceManager.GetString("Master_EditPersonNewPassword_CannotChange_TooWeak", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to <strong>PASSWORD CHANGED</strong><br/><br/>You have successfully changed your password. As a security measure, all withdrawals are now in quarantine for the next 48 hours.<br/><br/>If you can, please enable BitID two-factor authentication..
|
||||
/// </summary>
|
||||
internal static string Master_EditPersonNewPassword_Changed {
|
||||
get {
|
||||
return ResourceManager.GetString("Master_EditPersonNewPassword_Changed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Reset password.
|
||||
/// </summary>
|
||||
|
||||
@@ -816,4 +816,13 @@
|
||||
<data name="Timespan_Selection_TwoWeeks" xml:space="preserve">
|
||||
<value>Two weeks</value>
|
||||
</data>
|
||||
<data name="Master_EditPersonNewPassword_CannotChange_SecurityError" xml:space="preserve">
|
||||
<value>Unable to set new password: The old password is incorrect.</value>
|
||||
</data>
|
||||
<data name="Master_EditPersonNewPassword_CannotChange_TooWeak" xml:space="preserve">
|
||||
<value>Unable to set new password: The new password is too weak. Use a stronger password.</value>
|
||||
</data>
|
||||
<data name="Master_EditPersonNewPassword_Changed" xml:space="preserve">
|
||||
<value><strong>PASSWORD CHANGED</strong><br/><br/>You have successfully changed your password. As a security measure, all withdrawals are now in quarantine for the next 48 hours.<br/><br/>If you can, please enable BitID two-factor authentication.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -405,5 +405,59 @@ namespace Swarmops.Frontend.Automation
|
||||
|
||||
return authData.CurrentUser.ValidatePassword(password);
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public static AjaxCallResult ChangePassword(int personId, string oldPassword, string newPassword)
|
||||
{
|
||||
if (!ValidatePassword(personId, oldPassword))
|
||||
{
|
||||
// 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
|
||||
};
|
||||
}
|
||||
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
|
||||
if (authData.CurrentUser.Identity != personId)
|
||||
{
|
||||
// TODO: Same thing with this case
|
||||
|
||||
return new AjaxCallResult
|
||||
{
|
||||
Success = false,
|
||||
DisplayMessage = Resources.Global.Master_EditPersonNewPassword_CannotChange_SecurityError
|
||||
};
|
||||
}
|
||||
|
||||
if (newPassword.Length < 6) // TODO: Make per-installation and per-organization policy for this
|
||||
{
|
||||
return new AjaxCallResult
|
||||
{
|
||||
Success = false,
|
||||
DisplayMessage = Resources.Global.Master_EditPersonNewPassword_CannotChange_TooWeak
|
||||
};
|
||||
}
|
||||
|
||||
authData.CurrentUser.SetPassword(newPassword);
|
||||
// TODO: LOG
|
||||
// TODO: NOTIFY
|
||||
authData.CurrentUser.Quarantines.Withdrawal.QuarantineFor(new TimeSpan(2, 0, 0, 0)); // Quarantine for two days
|
||||
|
||||
return new AjaxCallResult
|
||||
{
|
||||
Success = true,
|
||||
DisplayMessage = Resources.Global.Master_EditPersonNewPassword_Changed
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,6 +161,10 @@
|
||||
$('#<%=this.TextInput.ClientID%>').val(newValue);
|
||||
}
|
||||
|
||||
function <%=this.ClientID%>_val() {
|
||||
return $('#<%=this.TextInput.ClientID%>').val();
|
||||
}
|
||||
|
||||
function <%=this.ClientID%>_initialize(initValue) {
|
||||
_initVal_<%=this.TextInput.ClientID%> = initValue;
|
||||
<%=this.ClientID%>_setValue(initValue);
|
||||
|
||||
+41
-2
@@ -250,8 +250,8 @@
|
||||
<div class="entryFields">
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonCurrentPassword" runat="server" Mode="Password" OnKeyDown="masterPersonEditorOnSecurityPasswordKeyDown" OnChanging="masterPersonEditorOnSecurityPasswordChanging" Cookie="CurrentPassword" AjaxCallbackUrl="" />​<br/>
|
||||
<div class="divMasterPersonEditSecurityRolldown" style="display:none"><Swarmops5:AjaxToggleSlider ID="MasterEditPerson2FA" runat="server" OnChange="masterPersonEditorOnFieldChange" Cookie="2FA" AjaxCallbackUrl="" />​<br/>
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonNewPassword1" runat="server" Mode="Password" OnChange="masterPersonEditorOnFieldChange" Cookie="Phone" AjaxCallbackUrl="" />​<br/>
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonNewPassword2" runat="server" Mode="Password" OnChange="masterPersonEditorOnFieldChange" Cookie="TwitterId" AjaxCallbackUrl="" />
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonNewPassword1" runat="server" Mode="Password" OnChanging="masterPersonEditorOnSecurityNewPasswordChanging" Cookie="Password1" AjaxCallbackUrl="" />​<br/>
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonNewPassword2" runat="server" Mode="Password" OnChanging="masterPersonEditorOnSecurityNewPasswordChanging" Cookie="Password2" AjaxCallbackUrl="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="entryLabels">
|
||||
@@ -394,6 +394,45 @@
|
||||
});
|
||||
}
|
||||
|
||||
function masterPersonEditorOnSecurityNewPasswordChanging(newValue, cookie, controlName) {
|
||||
if (cookie == "Password2") {
|
||||
// only validate as result of second field. May result in bad UX if somebody fills in fields in wrong order.
|
||||
|
||||
if (newValue == <%=this.MasterEditPersonNewPassword1%>_val() && newValue.length >= 6) // short minimum, but policy settings could override
|
||||
{
|
||||
// Newpasswords match, attempt to change the password
|
||||
<%=this.MasterEditPersonNewPassword1%>_updateProgressAnimate();
|
||||
<%=this.MasterEditPersonNewPassword2%>_updateProgressAnimate();
|
||||
|
||||
var jsonData = {
|
||||
personId: _master_PersonEditedId,
|
||||
oldPassword: <%=this.MasterEditPersonCurrentPassword%>_val(),
|
||||
newPassword: newValue
|
||||
};
|
||||
|
||||
SwarmopsJS.ajaxCall("/Automation/SwarmFunctions.aspx/ChangePassword", jsonData, function(result) {
|
||||
if (result.Success) // if password was changed
|
||||
{
|
||||
if (result.DisplayMessage.length > 0) {
|
||||
alertify.dialog(result.DisplayMessage);
|
||||
}
|
||||
<%=this.MasterEditPersonNewPassword1%>_updateSuccessAnimate();
|
||||
<%=this.MasterEditPersonNewPassword2%>_updateSuccessAnimate();
|
||||
<%=this.MasterEditPersonNewPassword1%>_clear();
|
||||
<%=this.MasterEditPersonNewPassword2%>_clear();
|
||||
<%=this.MasterEditPersonCurrentPassword%>_initialize(newValue); // move new password to current
|
||||
<%=this.MasterEditPersonCurrentPassword%>_updateSuccessAnimate();
|
||||
} else {
|
||||
alertify.error(result.DisplayMessage);
|
||||
|
||||
<%=this.MasterEditPersonNewPassword1%>_updateFailAnimate();
|
||||
<%=this.MasterEditPersonNewPassword2%>_updateFailAnimate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function masterBeginEditPerson(personId) {
|
||||
_master_PersonEditedId = personId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user