From ef629e9419739e7ee6883efc52c88cdf6fc4f355 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 6 Dec 2014 14:39:02 +0100 Subject: [PATCH] Loc freeze for sprint Black-7 --- Database/Configuration.cs | 2 +- .../Transmission/NotificationPayload.cs | 7 +- Logic/Logic.csproj | 9 + Logic/Support/Formatting.cs | 64 +++++++ Logic/Swarm/ParticipantTitle.cs | 2 +- Site5/App_Code/ControlV5Base.cs | 51 ++---- Site5/App_GlobalResources/Global.resx | 18 ++ Site5/App_GlobalResources/Pages.Swarm.resx | 21 ++- Site5/Controls/v5/Base/MainMenu.ascx.cs | 15 +- Site5/Pages/v5/Admin/CreateOrganization.aspx | 8 +- .../Pages/v5/Admin/CreateOrganization.aspx.cs | 64 +++---- Site5/Pages/v5/Admin/EditOrganization.aspx | 36 ++-- Site5/Pages/v5/Admin/EditOrganization.aspx.cs | 112 ++++++------ Site5/Pages/v5/Swarm/AddPerson.aspx | 83 +++++---- Site5/Pages/v5/Swarm/AddPerson.aspx.cs | 41 +++-- Site5/Security/Login.aspx | 170 +++++++++--------- Site5/Security/Login.aspx.cs | 115 ++++++------ 17 files changed, 473 insertions(+), 345 deletions(-) diff --git a/Database/Configuration.cs b/Database/Configuration.cs index 7f380d93..2e9055cb 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -14,7 +14,7 @@ namespace Swarmops.Database /// public static int DbVersionExpected { - get { return 5; } + get { return 6; } } diff --git a/Logic/Communications/Transmission/NotificationPayload.cs b/Logic/Communications/Transmission/NotificationPayload.cs index 1a761e02..52e38e62 100644 --- a/Logic/Communications/Transmission/NotificationPayload.cs +++ b/Logic/Communications/Transmission/NotificationPayload.cs @@ -1,6 +1,9 @@ using System; +using System.Globalization; using System.Net; +using Swarmops.Database; using Swarmops.Logic.App_GlobalResources; +using Swarmops.Logic.Support; using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Communications.Transmission @@ -53,9 +56,11 @@ namespace Swarmops.Logic.Communications.Transmission public string ExpandMacros (string input) { - // TODO: Replace all, of course + // Replace a few technical items that would be found in system-level notifications input = input.Replace ("[HostName]", Dns.GetHostName()); + input = input.Replace ("[DbVersion]", SwarmDb.DbVersionExpected.ToString(CultureInfo.InvariantCulture)); + input = input.Replace ("[SwarmopsVersion]", Formatting.SwarmopsVersion); // Loop through supplied strings and replace them in the resource. Not very efficient but who cares diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 2c2a5dcb..a6d7b008 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -90,6 +90,11 @@ True ParticipantTitles.resx + + True + True + Logic.Communications.Transmission.MailPayload.resx + @@ -392,6 +397,10 @@ + + ResXFileCodeGenerator + Logic.Communications.Transmission.MailPayload.Designer.cs + diff --git a/Logic/Support/Formatting.cs b/Logic/Support/Formatting.cs index 74fa380e..229ed516 100644 --- a/Logic/Support/Formatting.cs +++ b/Logic/Support/Formatting.cs @@ -1,13 +1,77 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Text; using System.Text.RegularExpressions; +using System.Web; +using Swarmops.Logic.Cache; using Swarmops.Logic.Security; namespace Swarmops.Logic.Support { public static class Formatting { + private static string _swarmopsVersion; + + public static string SwarmopsVersion + { + get + { + if (string.IsNullOrEmpty (_swarmopsVersion)) + { + if (System.Diagnostics.Debugger.IsAttached) + { + _swarmopsVersion = "Debug Environment"; + return _swarmopsVersion; + } + // Read build number if not loaded, or set to "Private" if none + string buildIdentity = (string)GuidCache.Get("_buildIdentity"); + + if (buildIdentity == null) + { + try + { + if (HttpContext.Current != null) // frontend: use friendly format + { + using ( + StreamReader reader = + File.OpenText (HttpContext.Current.Request.MapPath ("~/BuildIdentity.txt"))) + { + buildIdentity = "Build " + reader.ReadLine(); + } + + using ( + StreamReader reader = + File.OpenText (HttpContext.Current.Request.MapPath ("~/SprintName.txt"))) + { + buildIdentity += " (" + reader.ReadLine() + ")"; + } + } + else // backend: use build ID only + { + using ( + StreamReader reader = + File.OpenText("/usr/share/swarmops/backend/BuildIdentity.txt")) + { + buildIdentity = reader.ReadLine(); + } + } + } + catch (Exception) + { + buildIdentity = "Private Build"; + } + + GuidCache.Set("_buildIdentity", buildIdentity); + _swarmopsVersion = buildIdentity; + } + } + + return _swarmopsVersion; + } + } + public static string CleanNumber (string input) { return LogicServices.CleanNumber (input); diff --git a/Logic/Swarm/ParticipantTitle.cs b/Logic/Swarm/ParticipantTitle.cs index 4f4bb9b5..d7db04da 100644 --- a/Logic/Swarm/ParticipantTitle.cs +++ b/Logic/Swarm/ParticipantTitle.cs @@ -6,7 +6,7 @@ namespace Swarmops.Logic.Swarm { public class Participant { - public static string Localized (ParticipantTitle title, TitleVariant variant) + public static string Localized (ParticipantTitle title, TitleVariant variant = TitleVariant.Generic) { return ParticipantTitles.ResourceManager.GetString ("Title_" + title + "_" + variant); } diff --git a/Site5/App_Code/ControlV5Base.cs b/Site5/App_Code/ControlV5Base.cs index 9a964b4d..a980c44f 100644 --- a/Site5/App_Code/ControlV5Base.cs +++ b/Site5/App_Code/ControlV5Base.cs @@ -13,9 +13,24 @@ using Swarmops.Logic.Swarm; /// public class ControlV5Base : UserControl { - public Authority _authority = null; - public Organization _currentOrganization = null; - public Person _currentUser = null; + private Authority _authority; + private Organization _currentOrganization; + private Person _currentUser; + + protected Organization CurrentOrganization + { + get { return this._currentOrganization; } + } + + protected Person CurrentUser + { + get { return this._currentUser; } + } + + protected Authority CurrentAuthority + { + get { return this._authority; } + } protected override void OnLoad (EventArgs e) { @@ -48,34 +63,4 @@ public class ControlV5Base : UserControl base.OnLoad (e); } - protected string GetBuildIdentity() - { - // Read build number if not loaded, or set to "Private" if none - string buildIdentity = (string) GuidCache.Get ("_buildIdentity"); - - if (buildIdentity == null) - { - try - { - using (StreamReader reader = File.OpenText (HttpContext.Current.Request.MapPath ("~/BuildIdentity.txt")) - ) - { - buildIdentity = "Build " + reader.ReadLine(); - } - - using (StreamReader reader = File.OpenText (HttpContext.Current.Request.MapPath ("~/SprintName.txt"))) - { - buildIdentity += " (" + reader.ReadLine() + ")"; - } - } - catch (Exception) - { - buildIdentity = "Private Build"; - } - - GuidCache.Set ("_buildIdentity", buildIdentity); - } - - return buildIdentity; - } } \ No newline at end of file diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx index 2593d568..afb482ab 100644 --- a/Site5/App_GlobalResources/Global.resx +++ b/Site5/App_GlobalResources/Global.resx @@ -534,4 +534,22 @@ two-year Like "a two-year membership" + + Address + As in physical location + + + City + + + Country + As in the nation-state geographic boundary, not as in the music style + + + Date of Birth + Population data record entry, rather than celebration day ("birthday") + + + Postal Code + \ No newline at end of file diff --git a/Site5/App_GlobalResources/Pages.Swarm.resx b/Site5/App_GlobalResources/Pages.Swarm.resx index 719bfc0f..acf415fd 100644 --- a/Site5/App_GlobalResources/Pages.Swarm.resx +++ b/Site5/App_GlobalResources/Pages.Swarm.resx @@ -129,16 +129,33 @@ A valid street or P.O. box is required. + + Geography detected + This is where you enter new people into the organization. As you register them for a <strong>{0} {1}</strong> lasting until <strong>{2}</strong>, they will receive a welcome message with a randomized login password in mail. The local officers will also be notified of the new person, for an opportunity to send them a welcome message. {0} and {1} can be "one-year" and "Membership", for example. {2} is LongDateString. + + Legal Gender + "Legal" to cut short discussions on 50 different genders for the time being + The person was successfully added to the organization. + + Statistical Data + Header for gender, date of birth + + + Street 1 (or P.O. Box) + + + Street 2 - if applicable + - Add [Regular] - The [Regular] is replaced in code. Singular form gender neutral. + Add {0} + The {0} is replaced in code. Singular form gender neutral of Participant. Use this to find people in the organization. You can search by geography and by name pattern ("Jo S" will match Joel Sander). diff --git a/Site5/Controls/v5/Base/MainMenu.ascx.cs b/Site5/Controls/v5/Base/MainMenu.ascx.cs index 7428d439..354ad078 100644 --- a/Site5/Controls/v5/Base/MainMenu.ascx.cs +++ b/Site5/Controls/v5/Base/MainMenu.ascx.cs @@ -2,7 +2,9 @@ using System.IO; using System.Web.UI; using System.Xml.Serialization; +using Newtonsoft.Json; using Swarmops.Interface.Objects; +using Swarmops.Logic.Swarm; // ReSharper disable once CheckNamespace @@ -12,8 +14,17 @@ namespace Swarmops.Controls.Base { public MainMenuItem[] MainMenuData { get; set; } + private string _regularLocalized; + private string _regularsLocalized; + private string _regularshipLocalized; + protected void Page_Load (object sender, EventArgs e) { + ParticipantTitle regular = CurrentOrganization.RegularLabel; + _regularLocalized = Participant.Localized (regular); + _regularsLocalized = Participant.Localized (regular, TitleVariant.Plural); + _regularshipLocalized = Participant.Localized (regular, TitleVariant.Ship); + // TODO: Put a small cache on this // TODO: Put plugins on it @@ -49,11 +60,13 @@ namespace Swarmops.Controls.Base localizedText = resourceObject.ToString(); } } + localizedText = localizedText.Replace ("[Regular]", _regularLocalized); + // TODO IF APPLICABLE - add other [Regulars] [Regularship] etc. localizedText = Server.HtmlEncode (localizedText); // muy importante if (menuItem.Type == MenuItemType.BuildNumber) { - localizedText = GetBuildIdentity(); + localizedText = Swarmops.Logic.Support.Formatting.SwarmopsVersion; } string iconSize = "40px"; diff --git a/Site5/Pages/v5/Admin/CreateOrganization.aspx b/Site5/Pages/v5/Admin/CreateOrganization.aspx index f5f48461..175f1eff 100644 --- a/Site5/Pages/v5/Admin/CreateOrganization.aspx +++ b/Site5/Pages/v5/Admin/CreateOrganization.aspx @@ -4,8 +4,8 @@ @@ -119,7 +119,7 @@ Enable foreign currency accounts?
Enable Value Added Tax (VAT)?
- diff --git a/Site5/Pages/v5/Admin/EditOrganization.aspx.cs b/Site5/Pages/v5/Admin/EditOrganization.aspx.cs index cb17d473..623a5f17 100644 --- a/Site5/Pages/v5/Admin/EditOrganization.aspx.cs +++ b/Site5/Pages/v5/Admin/EditOrganization.aspx.cs @@ -11,12 +11,12 @@ namespace Swarmops.Frontend.Pages.v5.Admin { public partial class EditOrganization : PageV5Base { - protected void Page_Load(object sender, EventArgs e) + protected void Page_Load (object sender, EventArgs e) { PageIcon = "iconshock-box-cog"; PageTitle = Resources.Pages.Admin.EditOrganization_PageTitle; InfoBoxLiteral = Resources.Pages.Admin.EditOrganization_Info; - PageAccessRequired = new Access(CurrentOrganization, AccessAspect.Administration, AccessType.Write); + PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Administration, AccessType.Write); if (!Page.IsPostBack) { @@ -35,69 +35,69 @@ namespace Swarmops.Frontend.Pages.v5.Admin string participantship = Participant.Localized (CurrentOrganization.RegularLabel, TitleVariant.Ship); this.LabelParticipationEntry.Text = - String.Format(Resources.Pages.Admin.EditOrganization_ParticipationBeginsWhen, participants); + String.Format (Resources.Pages.Admin.EditOrganization_ParticipationBeginsWhen, participants); this.LabelParticipationOrg.Text = - String.Format(Resources.Pages.Admin.EditOrganization_ParticipationBeginsOrg, participants); + String.Format (Resources.Pages.Admin.EditOrganization_ParticipationBeginsOrg, participants); this.LabelParticipationDuration.Text = - String.Format(Resources.Pages.Admin.EditOrganization_ParticipationDuration, participantship); + String.Format (Resources.Pages.Admin.EditOrganization_ParticipationDuration, participantship); this.LabelParticipationChurn.Text = - String.Format(Resources.Pages.Admin.EditOrganization_ParticipationChurn, participantship); + String.Format (Resources.Pages.Admin.EditOrganization_ParticipationChurn, participantship); this.LabelRenewalCost.Text = - String.Format(Resources.Pages.Admin.EditOrganization_RenewalsCost, + String.Format (Resources.Pages.Admin.EditOrganization_RenewalsCost, CurrentOrganization.Currency.DisplayCode); this.LabelParticipationCost.Text = - String.Format(Resources.Pages.Admin.EditOrganization_ParticipationCost, + String.Format (Resources.Pages.Admin.EditOrganization_ParticipationCost, participantship, CurrentOrganization.Currency.DisplayCode); this.LabelRenewalsAffect.Text = Resources.Pages.Admin.EditOrganization_RenewalsAffect; this.LabelRenewalDateEffect.Text = Resources.Pages.Admin.EditOrganization_RenewalDateEffect; this.LabelRenewalReminder.Text = Resources.Pages.Admin.EditOrganization_RenewalReminders; this.LabelMemberNumber.Text = - String.Format(Resources.Pages.Admin.EditOrganization_MemberNumberStyle, participantship); + String.Format (Resources.Pages.Admin.EditOrganization_MemberNumberStyle, participantship); this.DropMembersWhen.Items.Clear(); - this.DropMembersWhen.Items.Add(new ListItem("Application submitted", "Application")); - this.DropMembersWhen.Items.Add(new ListItem("Application approved", "ApplicationApproval")); - this.DropMembersWhen.Items.Add(new ListItem("Application submitted + paid", "ApplicationPayment")); - this.DropMembersWhen.Items.Add(new ListItem("Application paid + approved", "ApplicationPaymentApproval")); - this.DropMembersWhen.Items.Add(new ListItem("Invited and accepted", "InvitationAcceptance")); - this.DropMembersWhen.Items.Add(new ListItem("Invited and paid", "InvitationPayment")); - this.DropMembersWhen.Items.Add(new ListItem("Manual add only", "Manual")); + this.DropMembersWhen.Items.Add (new ListItem ("Application submitted", "Application")); + this.DropMembersWhen.Items.Add (new ListItem ("Application approved", "ApplicationApproval")); + this.DropMembersWhen.Items.Add (new ListItem ("Application submitted + paid", "ApplicationPayment")); + this.DropMembersWhen.Items.Add (new ListItem ("Application paid + approved", "ApplicationPaymentApproval")); + this.DropMembersWhen.Items.Add (new ListItem ("Invited and accepted", "InvitationAcceptance")); + this.DropMembersWhen.Items.Add (new ListItem ("Invited and paid", "InvitationPayment")); + this.DropMembersWhen.Items.Add (new ListItem ("Manual add only", "Manual")); this.DropMembersWhere.Items.Clear(); - this.DropMembersWhere.Items.Add(new ListItem("Root organization only", "Root")); - this.DropMembersWhere.Items.Add(new ListItem("Most local org only", "Local")); - this.DropMembersWhere.Items.Add(new ListItem("Root and most local org", "RootLocal")); - this.DropMembersWhere.Items.Add(new ListItem("All applicable organizations", "All")); + this.DropMembersWhere.Items.Add (new ListItem ("Root organization only", "Root")); + this.DropMembersWhere.Items.Add (new ListItem ("Most local org only", "Local")); + this.DropMembersWhere.Items.Add (new ListItem ("Root and most local org", "RootLocal")); + this.DropMembersWhere.Items.Add (new ListItem ("All applicable organizations", "All")); this.DropMembershipDuration.Items.Clear(); - this.DropMembershipDuration.Items.Add(new ListItem("One month", "OneMonth")); - this.DropMembershipDuration.Items.Add(new ListItem("One year", "OneYear")); - this.DropMembershipDuration.Items.Add(new ListItem("Two years", "TwoYears")); - this.DropMembershipDuration.Items.Add(new ListItem("Five years", "FiveYears")); - this.DropMembershipDuration.Items.Add(new ListItem("Forever", "Forever")); + this.DropMembershipDuration.Items.Add (new ListItem ("One month", "OneMonth")); + this.DropMembershipDuration.Items.Add (new ListItem ("One year", "OneYear")); + this.DropMembershipDuration.Items.Add (new ListItem ("Two years", "TwoYears")); + this.DropMembershipDuration.Items.Add (new ListItem ("Five years", "FiveYears")); + this.DropMembershipDuration.Items.Add (new ListItem ("Forever", "Forever")); this.DropMembershipDuration.SelectedValue = "Year"; this.DropMembersChurn.Items.Clear(); - this.DropMembersChurn.Items.Add(new ListItem("Expiry date reached", "Expiry")); - this.DropMembersChurn.Items.Add(new ListItem("Not paid final reminder", "NotPaid")); - this.DropMembersChurn.Items.Add(new ListItem("Never", "Never")); + this.DropMembersChurn.Items.Add (new ListItem ("Expiry date reached", "Expiry")); + this.DropMembersChurn.Items.Add (new ListItem ("Not paid final reminder", "NotPaid")); + this.DropMembersChurn.Items.Add (new ListItem ("Never", "Never")); this.DropRenewalDateEffect.Items.Clear(); - this.DropRenewalDateEffect.Items.Add(new ListItem("Date of renewal", "RenewalDate")); - this.DropRenewalDateEffect.Items.Add(new ListItem("Previous expiry", "FromExpiry")); + this.DropRenewalDateEffect.Items.Add (new ListItem ("Date of renewal", "RenewalDate")); + this.DropRenewalDateEffect.Items.Add (new ListItem ("Previous expiry", "FromExpiry")); this.DropRenewalsAffect.Items.Clear(); - this.DropRenewalsAffect.Items.Add(new ListItem("All related organizations", "All")); - this.DropRenewalsAffect.Items.Add(new ListItem("One organization at a time", "One")); + this.DropRenewalsAffect.Items.Add (new ListItem ("All related organizations", "All")); + this.DropRenewalsAffect.Items.Add (new ListItem ("One organization at a time", "One")); this.DropRenewalReminder.Items.Clear(); - this.DropRenewalReminder.Items.Add(new ListItem("30, 14, 7, 1 days before", "Standard")); - this.DropRenewalReminder.Items.Add(new ListItem("Never", "Never")); + this.DropRenewalReminder.Items.Add (new ListItem ("30, 14, 7, 1 days before", "Standard")); + this.DropRenewalReminder.Items.Add (new ListItem ("Never", "Never")); this.DropMemberNumber.Items.Clear(); - this.DropMemberNumber.Items.Add(new ListItem("Global for installation", "Global")); - this.DropMemberNumber.Items.Add(new ListItem("Local for each organzation", "Local")); + this.DropMemberNumber.Items.Add (new ListItem ("Global for installation", "Global")); + this.DropMemberNumber.Items.Add (new ListItem ("Local for each organzation", "Local")); } [WebMethod] @@ -130,7 +130,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin [WebMethod] - public static CallResult SwitchToggled(string switchName, bool switchValue) + public static CallResult SwitchToggled (string switchName, bool switchValue) { AuthenticationData authData = GetAuthenticationDataAndCulture(); @@ -158,13 +158,13 @@ namespace Swarmops.Frontend.Pages.v5.Admin FinancialAccount coldAccount = authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold; if (coldAccount == null) { - coldAccount = FinancialAccount.Create(authData.CurrentOrganization, "Bitcoin Assets Cold", + coldAccount = FinancialAccount.Create (authData.CurrentOrganization, "Bitcoin Assets Cold", FinancialAccountType.Asset, null); - FinancialAccount.Create(authData.CurrentOrganization, "Cold Address 1", + FinancialAccount.Create (authData.CurrentOrganization, "Cold Address 1", FinancialAccountType.Asset, coldAccount); - FinancialAccount.Create(authData.CurrentOrganization, "Cold Address 2 (rename these)", + FinancialAccount.Create (authData.CurrentOrganization, "Cold Address 2 (rename these)", FinancialAccountType.Asset, coldAccount); - FinancialAccount.Create(authData.CurrentOrganization, "Cold Address... etc", + FinancialAccount.Create (authData.CurrentOrganization, "Cold Address... etc", FinancialAccountType.Asset, coldAccount); authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold = coldAccount; @@ -174,7 +174,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin } else { - workAccounts.Add(coldAccount); + workAccounts.Add (coldAccount); } break; case "BitcoinHot": @@ -187,7 +187,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin if (hotAccount == null) { authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot = - FinancialAccount.Create(authData.CurrentOrganization, "Bitcoin Wallet Hot", + FinancialAccount.Create (authData.CurrentOrganization, "Bitcoin Wallet Hot", FinancialAccountType.Asset, null); result.DisplayMessage = @@ -195,7 +195,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin } else { - workAccounts.Add(hotAccount); + workAccounts.Add (hotAccount); } break; case "Forex": @@ -212,10 +212,10 @@ namespace Swarmops.Frontend.Pages.v5.Admin } authData.CurrentOrganization.FinancialAccounts.IncomeCurrencyFluctuations = - FinancialAccount.Create(authData.CurrentOrganization, "Forex holding gains", + FinancialAccount.Create (authData.CurrentOrganization, "Forex holding gains", FinancialAccountType.Income, null); authData.CurrentOrganization.FinancialAccounts.CostsCurrencyFluctuations = - FinancialAccount.Create(authData.CurrentOrganization, "Forex holding losses", + FinancialAccount.Create (authData.CurrentOrganization, "Forex holding losses", FinancialAccountType.Cost, null); result.DisplayMessage = @@ -243,8 +243,8 @@ namespace Swarmops.Frontend.Pages.v5.Admin } else { - workAccounts.Add(forexGain); - workAccounts.Add(forexLoss); + workAccounts.Add (forexGain); + workAccounts.Add (forexLoss); } } break; @@ -260,10 +260,10 @@ namespace Swarmops.Frontend.Pages.v5.Admin } authData.CurrentOrganization.FinancialAccounts.AssetsVatInbound = - FinancialAccount.Create(authData.CurrentOrganization, "Inbound VAT", + FinancialAccount.Create (authData.CurrentOrganization, "Inbound VAT", FinancialAccountType.Asset, null); authData.CurrentOrganization.FinancialAccounts.DebtsVatOutbound = - FinancialAccount.Create(authData.CurrentOrganization, "Outbound VAT", + FinancialAccount.Create (authData.CurrentOrganization, "Outbound VAT", FinancialAccountType.Debt, null); result.DisplayMessage = "Inbound and outbound VAT accounts were created."; @@ -275,8 +275,8 @@ namespace Swarmops.Frontend.Pages.v5.Admin throw new InvalidOperationException(); } - workAccounts.Add(vatInbound); - workAccounts.Add(vatOutbound); + workAccounts.Add (vatInbound); + workAccounts.Add (vatOutbound); } break; case "Paypal": @@ -284,21 +284,21 @@ namespace Swarmops.Frontend.Pages.v5.Admin if (assetsPaypal == null) { authData.CurrentOrganization.FinancialAccounts.AssetsPaypal = - FinancialAccount.Create(authData.CurrentOrganization, "Paypal account", + FinancialAccount.Create (authData.CurrentOrganization, "Paypal account", FinancialAccountType.Asset, null); result.DisplayMessage = "An account was created for Paypal account tracking."; } else { - workAccounts.Add(assetsPaypal); + workAccounts.Add (assetsPaypal); } break; default: throw new NotImplementedException(); } - if (workAccounts.Count > 0 && String.IsNullOrEmpty(result.DisplayMessage)) + if (workAccounts.Count > 0 && String.IsNullOrEmpty (result.DisplayMessage)) { if (switchValue) // switch has been turned on { @@ -326,7 +326,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin foreach (FinancialAccount account in workAccounts) { - if (account.GetLastRows(5).Count > 0) + if (account.GetLastRows (5).Count > 0) { transactionsOnAccount = true; } diff --git a/Site5/Pages/v5/Swarm/AddPerson.aspx b/Site5/Pages/v5/Swarm/AddPerson.aspx index 501f90da..4542d065 100644 --- a/Site5/Pages/v5/Swarm/AddPerson.aspx +++ b/Site5/Pages/v5/Swarm/AddPerson.aspx @@ -4,16 +4,16 @@ -

Adding [Regular]

+

​
- ​
+ ​
​
​
 
​
​
-
 
XX–
+
 
XX–
... 
 
​
​
- +
-
+
diff --git a/Site5/Pages/v5/Swarm/AddPerson.aspx.cs b/Site5/Pages/v5/Swarm/AddPerson.aspx.cs index 895f94c1..a07a7e71 100644 --- a/Site5/Pages/v5/Swarm/AddPerson.aspx.cs +++ b/Site5/Pages/v5/Swarm/AddPerson.aspx.cs @@ -1,8 +1,8 @@ using System; +using System.Runtime.Versioning; using System.Web.UI; using System.Web.UI.WebControls; using Resources; -using Swarmops.Logic.Communications; using Swarmops.Logic.Security; using Swarmops.Logic.Structure; using Swarmops.Logic.Swarm; @@ -13,7 +13,7 @@ namespace Swarmops.Frontend.Pages.v5.Swarm { public partial class AddPerson : PageV5Base { - protected void Page_Load(object sender, EventArgs e) + protected void Page_Load (object sender, EventArgs e) { // Override style widths - (this will cause problems with a future responsive design; come back here to fix that) @@ -38,13 +38,13 @@ namespace Swarmops.Frontend.Pages.v5.Swarm foreach (Country country in allCountries) { - string countryLocalName = GeographyNames.ResourceManager.GetString("Country_" + country.Code); - if (string.IsNullOrEmpty(countryLocalName)) + string countryLocalName = GeographyNames.ResourceManager.GetString ("Country_" + country.Code); + if (string.IsNullOrEmpty (countryLocalName)) { countryLocalName = country.Name + "*"; // In English. Asterisk indicates resource missing. } string countryDisplay = country.Code + " " + countryLocalName; - this.DropCountries.Items.Add(new ListItem(countryDisplay, country.Code)); + this.DropCountries.Items.Add (new ListItem (countryDisplay, country.Code)); } if (CurrentOrganization.DefaultCountry != null) @@ -53,9 +53,9 @@ namespace Swarmops.Frontend.Pages.v5.Swarm } this.DropGenders.Items.Clear(); - this.DropGenders.Items.Add(new ListItem(Global.Global_UnknownUndisclosed, "Unknown")); - this.DropGenders.Items.Add(new ListItem(Global.Global_Female, "Female")); - this.DropGenders.Items.Add(new ListItem(Global.Global_Male, "Male")); + this.DropGenders.Items.Add (new ListItem (Global.Global_UnknownUndisclosed, "Unknown")); + this.DropGenders.Items.Add (new ListItem (Global.Global_Female, "Female")); + this.DropGenders.Items.Add (new ListItem (Global.Global_Male, "Male")); } private void Localize() @@ -65,9 +65,25 @@ namespace Swarmops.Frontend.Pages.v5.Swarm this.LiteralErrorName.Text = Resources.Pages.Swarm.AddPerson_ErrorName; this.LiteralErrorStreet.Text = Resources.Pages.Swarm.AddPerson_ErrorStreet; - InfoBoxLiteral = String.Format(Resources.Pages.Swarm.AddPerson_Info, Global.Timespan_OneYear, + this.BoxTitle.Text = PageTitle = String.Format (Resources.Pages.Swarm.AddPerson_Title, + Participant.Localized (CurrentOrganization.RegularLabel)); + InfoBoxLiteral = String.Format (Resources.Pages.Swarm.AddPerson_Info, Global.Timespan_OneYear, Participant.Localized (CurrentOrganization.RegularLabel, TitleVariant.Ship), - DateTime.Today.AddYears(1).ToLongDateString()); + DateTime.Today.AddYears (1).ToLongDateString()); + + this.LabelName.Text = Resources.Global.Global_Name; + this.LabelCountry.Text = Resources.Global.Global_Country; + this.LabelMail.Text = Resources.Global.Global_Mail; + this.LabelPhone.Text = Resources.Global.Global_Phone; + this.LabelHeaderAddresss.Text = Resources.Global.Global_Address.ToUpperInvariant(); + this.LabelStreet1.Text = Resources.Pages.Swarm.AddPerson_Street1PO; + this.LabelStreet2.Text = Resources.Pages.Swarm.AddPerson_Street2; + this.LabelPostalCode.Text = Resources.Global.Global_PostalCode; + this.LabelCity.Text = Resources.Global.Global_City; + this.LabelHeaderStatData.Text = Resources.Pages.Swarm.AddPerson_StatisticalData; + this.LabelDateOfBirth.Text = Resources.Global.Global_DateOfBirth; + this.LabelLegalGender.Text = Resources.Pages.Swarm.AddPerson_LegalGender; + this.TextDateOfBirth.Attributes["placeholder"] = Global.Global_DateFormatShortReadable; this.TextName.Attributes["placeholder"] = "Joe Smith"; @@ -77,10 +93,9 @@ namespace Swarmops.Frontend.Pages.v5.Swarm this.TextPostal.Attributes["placeholder"] = "12345"; } - protected void ButtonSubmit_Click(object sender, EventArgs e) + protected void ButtonSubmit_Click (object sender, EventArgs e) { - string randomPassword = Authentication.CreateRandomPassword(24); - + string randomPassword = Authentication.CreateRandomPassword (24); // Person.Create() diff --git a/Site5/Security/Login.aspx b/Site5/Security/Login.aspx index f75a1377..3ccfada6 100644 --- a/Site5/Security/Login.aspx +++ b/Site5/Security/Login.aspx @@ -25,6 +25,7 @@ @@ -33,111 +34,110 @@ + var bitIdUri = ''; + var bitIdNonce = ''; +
-
|
| 
| 
-
Swarmops Logo
+
|
| 
| 
+
Swarmops Logo
@@ -167,11 +167,11 @@

-
+
- +
  
  
  
  
@@ -180,7 +180,7 @@

Dev's Cheat Button

-
+

Since we're running on localhost, on a nonstandard port, with a debugger attached, and under Windows, this is clearly not a production environment. Since it's unlikely that the outside Internet has access to this machine, which means you can't login with BitID, a cheat button has been provided for you.

Press the button below to log on as Sandbox Administrator.

@@ -192,8 +192,8 @@
- diff --git a/Site5/Security/Login.aspx.cs b/Site5/Security/Login.aspx.cs index 413e4667..ebf566af 100644 --- a/Site5/Security/Login.aspx.cs +++ b/Site5/Security/Login.aspx.cs @@ -8,8 +8,10 @@ using System.Web.Security; using System.Web.Services; using System.Web.UI; using NBitcoin; +using Resources; using Swarmops.Database; using Swarmops.Logic.Cache; +using Swarmops.Logic.Security; using Swarmops.Logic.Support; using Swarmops.Logic.Swarm; @@ -19,13 +21,13 @@ namespace Swarmops.Pages.Security { private static string _buildIdentity; - protected void Page_Load(object sender, EventArgs e) + protected void Page_Load (object sender, EventArgs e) { // Check if this is the first run ever. If so, redirect to Init. if (!SwarmDb.Configuration.IsConfigured()) { - Response.Redirect("/Pages/v5/Init/", true); + Response.Redirect ("/Pages/v5/Init/", true); return; } @@ -50,17 +52,17 @@ namespace Swarmops.Pages.Security signature = Request.Params["signature"] }; - ProcessRespondBitId(credentials, Response); + ProcessRespondBitId (credentials, Response); return; } if (Request.ContentType == "application/json") { BitIdCredentials credentials = - new JavaScriptSerializer().Deserialize( - new StreamReader(Request.InputStream).ReadToEnd()); + new JavaScriptSerializer().Deserialize ( + new StreamReader (Request.InputStream).ReadToEnd()); // TODO: untested but seems to work. Throws? - ProcessRespondBitId(credentials, Response); + ProcessRespondBitId (credentials, Response); return; } } @@ -69,13 +71,13 @@ namespace Swarmops.Pages.Security // If this is the Dev Sandbox, autologin if (Request.Url.Host == "dev.swarmops.com" && - PilotInstallationIds.IsPilot(PilotInstallationIds.DevelopmentSandbox) && + PilotInstallationIds.IsPilot (PilotInstallationIds.DevelopmentSandbox) && Request.QueryString["SuppressAutologin"] != "true") { - Response.AppendCookie(new HttpCookie("DashboardMessage", - HttpUtility.UrlEncode( + Response.AppendCookie (new HttpCookie ("DashboardMessage", + HttpUtility.UrlEncode ( "

You have been logged on as Sandbox Administrator to the Swarmops Development Sandbox.


This machine runs the latest development build, so you may run into diagnostic code and half-finished features. All data here is bogus test data and is reset every night.


In other words, welcome, and play away!

"))); - FormsAuthentication.RedirectFromLoginPage("1,1", true); + FormsAuthentication.RedirectFromLoginPage ("1,1", true); } // Check for SSL and force it @@ -85,9 +87,9 @@ namespace Swarmops.Pages.Security string cloudFlareVisitorScheme = Request.Headers["CF-Visitor"]; bool cloudFlareSsl = false; - if (!string.IsNullOrEmpty(cloudFlareVisitorScheme)) + if (!string.IsNullOrEmpty (cloudFlareVisitorScheme)) { - if (cloudFlareVisitorScheme.Contains("\"scheme\":\"https\"")) + if (cloudFlareVisitorScheme.Contains ("\"scheme\":\"https\"")) { cloudFlareSsl = true; } @@ -97,13 +99,13 @@ namespace Swarmops.Pages.Security // Rewrite if applicable - if (Request.Url.ToString().StartsWith("http://") && !cloudFlareSsl) + if (Request.Url.ToString().StartsWith ("http://") && !cloudFlareSsl) // only check client-side as many server sites de-SSL the connection before reaching the web server { - if (!Request.Url.ToString().StartsWith("http://dev.swarmops.com/") && - !Request.Url.ToString().StartsWith("http://localhost:")) + if (!Request.Url.ToString().StartsWith ("http://dev.swarmops.com/") && + !Request.Url.ToString().StartsWith ("http://localhost:")) { - Response.Redirect(Request.Url.ToString().Replace("http:", "https:")); + Response.Redirect (Request.Url.ToString().Replace ("http:", "https:")); } } @@ -116,35 +118,35 @@ namespace Swarmops.Pages.Security // Generate BitID tokens Guid guid = Guid.NewGuid(); - string guidString = guid.ToString().Replace("-", ""); + string guidString = guid.ToString().Replace ("-", ""); - string nonce = guidString + DateTime.UtcNow.Ticks.ToString("x8"); + string nonce = guidString + DateTime.UtcNow.Ticks.ToString ("x8"); string hostName = Request.Url.Host; string bitIdUri = "bitid://" + hostName + "/Security/Login.aspx?x=" + nonce; - if (Request.Url.ToString().StartsWith("http://") && !cloudFlareSsl) + if (Request.Url.ToString().StartsWith ("http://") && !cloudFlareSsl) { bitIdUri += "&u=1"; } - this.LiteralUri.Text = HttpUtility.UrlEncode(bitIdUri); + this.LiteralUri.Text = HttpUtility.UrlEncode (bitIdUri); this.LiteralNonce.Text = nonce; - GuidCache.Set(bitIdUri + "-Logon", "Unauth"); + GuidCache.Set (bitIdUri + "-Logon", "Unauth"); // TODO: need to NOT USE GOOGLE CHARTS for this but bring home a free QR package this.ImageBitIdQr.ImageUrl = - "https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=" + HttpUtility.UrlEncode(bitIdUri); + "https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=" + HttpUtility.UrlEncode (bitIdUri); } - protected void ProcessRespondBitId(BitIdCredentials credentials, HttpResponse response) + protected void ProcessRespondBitId (BitIdCredentials credentials, HttpResponse response) { - BitcoinAddress testAddress = new BitcoinAddress(credentials.address); - if (testAddress.VerifyMessage(credentials.uri, credentials.signature)) + BitcoinAddress testAddress = new BitcoinAddress (credentials.address); + if (testAddress.VerifyMessage (credentials.uri, credentials.signature)) { // woooooo @@ -152,27 +154,27 @@ namespace Swarmops.Pages.Security { if (CurrentUser != null) { - if ((string) GuidCache.Get(credentials.uri + "-Intent") == "Register") + if ((string) GuidCache.Get (credentials.uri + "-Intent") == "Register") { // the currently logged-on user desires to register this address // so set currentUser bitid CurrentUser.BitIdAddress = credentials.address; // Then go do something else, I guess? Flag somehow to original page // that the op is completed? - GuidCache.Set(credentials.uri + "-Intent", "Complete"); + GuidCache.Set (credentials.uri + "-Intent", "Complete"); } } - if (GuidCache.Get(credentials.uri + "-Logon") as string == "Unauth") + if (GuidCache.Get (credentials.uri + "-Logon") as string == "Unauth") { - Person person = Person.FromBitIdAddress(credentials.address); + Person person = Person.FromBitIdAddress (credentials.address); // TODO: If above throws, show friendly "unknown wallet" message // TODO: Determine last logged-on organization. Right now, log on to Sandbox. - GuidCache.Set(credentials.uri + "-LoggedOn", - person.Identity.ToString(CultureInfo.InvariantCulture) + ",1,,BitId 2FA"); + GuidCache.Set (credentials.uri + "-LoggedOn", + person.Identity.ToString (CultureInfo.InvariantCulture) + ",1,,BitId 2FA"); } } catch (Exception e) @@ -184,8 +186,8 @@ namespace Swarmops.Pages.Security response.StatusCode = 200; response.SetJson(); - response.Write("{\"address\":\"" + credentials.address + "\",\"signature\":\"" + credentials.signature + - "\"}"); + response.Write ("{\"address\":\"" + credentials.address + "\",\"signature\":\"" + credentials.signature + + "\"}"); response.End(); } else @@ -195,30 +197,30 @@ namespace Swarmops.Pages.Security } [WebMethod] - public static bool TestLogin(string uriEncoded, string nonce) + public static bool TestLogin (string uriEncoded, string nonce) { try { - string uri = HttpUtility.UrlDecode(uriEncoded); + string uri = HttpUtility.UrlDecode (uriEncoded); // a little sloppy nonce and uri checking rather than full parsing // TODO: Full URI parse, the above is not enough - if (!uri.Contains(nonce) || !uri.Contains(HttpContext.Current.Request.Url.Host)) + if (!uri.Contains (nonce) || !uri.Contains (HttpContext.Current.Request.Url.Host)) { throw new ArgumentException(); } - string result = (string) GuidCache.Get(uri + "-LoggedOn"); - if (string.IsNullOrEmpty(result)) + string result = (string) GuidCache.Get (uri + "-LoggedOn"); + if (string.IsNullOrEmpty (result)) { return false; } // We have a successful login when we get here - GuidCache.Delete(uri + "-Logon"); - GuidCache.Delete(uri + "-LoggedOn"); - GuidCache.Set(nonce + "-Identity", result); + GuidCache.Delete (uri + "-Logon"); + GuidCache.Delete (uri + "-LoggedOn"); + GuidCache.Set (nonce + "-Identity", result); return true; } @@ -232,22 +234,22 @@ namespace Swarmops.Pages.Security [WebMethod] // ReSharper disable once InconsistentNaming - public static bool TestCredentials(string credentialsLogin, string credentialsPass, string credentials2FA, + public static bool TestCredentials (string credentialsLogin, string credentialsPass, string credentials2FA, string logonUriEncoded) { - if (!string.IsNullOrEmpty(credentialsLogin.Trim()) && !string.IsNullOrEmpty(credentialsPass.Trim())) + if (!string.IsNullOrEmpty (credentialsLogin.Trim()) && !string.IsNullOrEmpty (credentialsPass.Trim())) { - string logonUri = HttpUtility.UrlDecode(logonUriEncoded); + string logonUri = HttpUtility.UrlDecode (logonUriEncoded); try { - Person authenticatedPerson = Swarmops.Logic.Security.Authentication.Authenticate(credentialsLogin, + Person authenticatedPerson = Authentication.Authenticate (credentialsLogin, credentialsPass); // TODO: Determine last logged-on organization. Right now, log on to Sandbox. - GuidCache.Set(logonUri + "-LoggedOn", - authenticatedPerson.Identity.ToString(CultureInfo.InvariantCulture) + ",1,,AuthPlain"); + GuidCache.Set (logonUri + "-LoggedOn", + authenticatedPerson.Identity.ToString (CultureInfo.InvariantCulture) + ",1,,AuthPlain"); return true; } catch (UnauthorizedAccessException) @@ -260,19 +262,19 @@ namespace Swarmops.Pages.Security } - protected override void OnPreInit(EventArgs e) + protected override void OnPreInit (EventArgs e) { - base.OnPreInit(e); + base.OnPreInit (e); } private void Localize() { - this.LabelCurrentOrganizationName.Text = Resources.Global.Global_Organization; + this.LabelCurrentOrganizationName.Text = Global.Global_Organization; this.LabelCurrentUserName.Text = Participant.Localized (ParticipantTitle.Person, TitleVariant.Generic); this.LabelPageTitle.Text = Resources.Pages.Security.Login_PageTitle; - this.LabelPreferences.Text = Resources.Global.Global_NA; - this.LabelSidebarInfoHeader.Text = Resources.Global.Sidebar_Information; - this.LabelSidebarHelpHeader.Text = Resources.Global.Sidebar_Help; + this.LabelPreferences.Text = Global.Global_NA; + this.LabelSidebarInfoHeader.Text = Global.Sidebar_Information; + this.LabelSidebarHelpHeader.Text = Global.Sidebar_Help; this.LabelSidebarInfoContent.Text = Resources.Pages.Security.Login_Info; this.LabelSidebarManualLoginHeader.Text = Resources.Pages.Security.Login_ManualLogin; this.LabelHeader.Text = Resources.Pages.Security.Login_Header; @@ -293,7 +295,8 @@ namespace Swarmops.Pages.Security try { using ( - StreamReader reader = File.OpenText(HttpContext.Current.Request.MapPath("~/BuildIdentity.txt"))) + StreamReader reader = File.OpenText (HttpContext.Current.Request.MapPath ("~/BuildIdentity.txt")) + ) { _buildIdentity = "Build " + reader.ReadLine(); } @@ -308,7 +311,7 @@ namespace Swarmops.Pages.Security } - protected void ButtonLogin_Click(object sender, EventArgs args) + protected void ButtonLogin_Click (object sender, EventArgs args) { // Check the host names and addresses again as a security measure - after all, we can be called from outside our intended script /* @@ -330,7 +333,7 @@ namespace Swarmops.Pages.Security }*/ } - protected void ButtonCheat_Click(object sender, EventArgs e) + protected void ButtonCheat_Click (object sender, EventArgs e) { throw new NotImplementedException(); }