More work on editing personal data

This commit is contained in:
Rick Falkvinge
2016-10-15 22:54:04 +02:00
parent 1262e03a6e
commit 170c4b1abf
4 changed files with 38 additions and 4 deletions
+9
View File
@@ -1491,6 +1491,15 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to This doesn&apos;t look like a valid phone number, but we&apos;re storing it as written here..
/// </summary>
internal static string Master_EditPersonWarning_Phone {
get {
return ResourceManager.GetString("Master_EditPersonWarning_Phone", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You are currently logged into &lt;strong&gt;{0}&lt;/strong&gt;. Would you like to switch to another organization?.
/// </summary>
+4
View File
@@ -755,4 +755,8 @@
<data name="Master_EditPersonResetPasswordLabel" xml:space="preserve">
<value>Mail a password-reset link</value>
</data>
<data name="Master_EditPersonWarning_Phone" xml:space="preserve">
<value>This doesn't look like a valid phone number, but we're storing it as written here.</value>
<comment>Trigges as a notice if phone misses a regexp.</comment>
</data>
</root>
+21 -3
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Services;
using System.Web.UI;
@@ -263,6 +264,11 @@ namespace Swarmops.Frontend.Automation
[WebMethod]
public static AjaxInputCallResult SetPersonEditorData(int personId, string field, string newValue)
{
if (newValue == null || field == null)
{
throw new ArgumentNullException();
}
AuthenticationData authData = GetAuthenticationDataAndCulture();
bool self = false;
@@ -279,7 +285,7 @@ namespace Swarmops.Frontend.Automation
return new AjaxInputCallResult
{
Success = false,
DisplayMessage = JavascriptEscape(Resources.Global.Global_FieldCannotBeEmpty),
DisplayMessage = Resources.Global.Global_FieldCannotBeEmpty,
FailReason = AjaxInputCallResult.ErrorInvalidFormat,
NewValue = GetPersonValue (personId, field)
};
@@ -301,6 +307,8 @@ namespace Swarmops.Frontend.Automation
}
string oldValue;
string displayMessage = string.Empty;
newValue = newValue.Trim().Replace (" ", " ");
switch (field)
{
@@ -315,8 +323,17 @@ namespace Swarmops.Frontend.Automation
case "Phone":
oldValue = affectedPerson.Phone;
affectedPerson.Phone = newValue;
if (!Regex.IsMatch (newValue, @"^[0-9 \(\)\-\+]+$"))
{
// using characters not typically seen in a phone number? Warn
displayMessage = Resources.Global.Master_EditPersonWarning_Phone;
}
break;
case "TwitterId":
if (newValue.StartsWith ("@"))
{
newValue = newValue.Substring (1);
}
oldValue = affectedPerson.TwitterId;
affectedPerson.TwitterId = newValue;
break;
@@ -329,7 +346,7 @@ namespace Swarmops.Frontend.Automation
ActingPersonId = authData.CurrentUser.PersonId,
AffectedPersonId = affectedPerson.PersonId,
Field = field,
IpAddress = HttpContext.Current.Request.UserHostAddress,
IpAddress = SupportFunctions.GetMostLikelyRemoteIPAddress(),
OldValue = oldValue,
NewValue = newValue
});
@@ -342,7 +359,8 @@ namespace Swarmops.Frontend.Automation
return new AjaxInputCallResult
{
Success = true,
NewValue = newValue
NewValue = newValue,
DisplayMessage = displayMessage
};
}
+4 -1
View File
@@ -420,10 +420,13 @@
console.log(result);
if (result.Success) {
window[controlName + "_updateSuccessAnimate"](result.NewValue);
if (result.DisplayMessage != '') {
alertify.log(result.DisplayMessage);
}
} else {
window[controlName + "_updateFailAnimate"](result.NewValue);
if (result.DisplayMessage != '') {
alertify.error(SwarmopsJS.unescape(result.DisplayMessage));
alertify.error(result.DisplayMessage);
}
}
},