From 7075d8396d3290d2e329587ab4ac8369f3c43fad Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 22 Mar 2018 17:33:22 -0400 Subject: [PATCH] some helper functions for users and orgs --- .../Controllers/OrganizationsController.cs | 9 +- src/Admin/Controllers/UsersController.cs | 9 +- src/Admin/Models/OrganizationEditModel.cs | 9 +- src/Admin/Models/UserEditModel.cs | 9 +- src/Admin/Views/Organizations/Edit.cshtml | 99 +++++++++++++++++-- src/Admin/Views/Shared/_Layout.cshtml | 10 ++ src/Admin/Views/Users/Edit.cshtml | 82 +++++++++++++-- src/Core/Enums/GatewayType.cs | 9 +- src/Core/Enums/PlanType.cs | 11 ++- 9 files changed, 227 insertions(+), 20 deletions(-) diff --git a/src/Admin/Controllers/OrganizationsController.cs b/src/Admin/Controllers/OrganizationsController.cs index eca13470fd..8646659b97 100644 --- a/src/Admin/Controllers/OrganizationsController.cs +++ b/src/Admin/Controllers/OrganizationsController.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Bit.Admin.Models; using System.Collections.Generic; using Bit.Core.Models.Table; +using Bit.Core; namespace Bit.Admin.Controllers { @@ -13,10 +14,14 @@ namespace Bit.Admin.Controllers public class OrganizationsController : Controller { private readonly IOrganizationRepository _organizationRepository; + private readonly GlobalSettings _globalSettings; - public OrganizationsController(IOrganizationRepository organizationRepository) + public OrganizationsController( + IOrganizationRepository organizationRepository, + GlobalSettings globalSettings) { _organizationRepository = organizationRepository; + _globalSettings = globalSettings; } public async Task Index(string name = null, string userEmail = null, bool? paid = null, @@ -53,7 +58,7 @@ namespace Bit.Admin.Controllers return RedirectToAction("Index"); } - return View(new OrganizationEditModel(organization)); + return View(new OrganizationEditModel(organization, _globalSettings)); } [HttpPost] diff --git a/src/Admin/Controllers/UsersController.cs b/src/Admin/Controllers/UsersController.cs index 694d732498..49f7c2749c 100644 --- a/src/Admin/Controllers/UsersController.cs +++ b/src/Admin/Controllers/UsersController.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Bit.Admin.Models; using System.Collections.Generic; using Bit.Core.Models.Table; +using Bit.Core; namespace Bit.Admin.Controllers { @@ -13,10 +14,14 @@ namespace Bit.Admin.Controllers public class UsersController : Controller { private readonly IUserRepository _userRepository; + private readonly GlobalSettings _globalSettings; - public UsersController(IUserRepository userRepository) + public UsersController( + IUserRepository userRepository, + GlobalSettings globalSettings) { _userRepository = userRepository; + _globalSettings = globalSettings; } public async Task Index(string email, int page = 1, int count = 25) @@ -50,7 +55,7 @@ namespace Bit.Admin.Controllers return RedirectToAction("Index"); } - return View(new UserEditModel(user)); + return View(new UserEditModel(user, _globalSettings)); } [HttpPost] diff --git a/src/Admin/Models/OrganizationEditModel.cs b/src/Admin/Models/OrganizationEditModel.cs index b0a5bee9e8..10f19346d5 100644 --- a/src/Admin/Models/OrganizationEditModel.cs +++ b/src/Admin/Models/OrganizationEditModel.cs @@ -1,6 +1,8 @@ using System; using System.ComponentModel.DataAnnotations; +using Bit.Core; using Bit.Core.Models.Table; +using Bit.Core.Utilities; namespace Bit.Admin.Models { @@ -8,9 +10,11 @@ namespace Bit.Admin.Models { public OrganizationEditModel() { } - public OrganizationEditModel(Organization org) + public OrganizationEditModel(Organization org, GlobalSettings globalSettings) { Organization = org; + BraintreeMerchantId = globalSettings.Braintree.MerchantId; + Name = org.Name; BusinessName = org.BusinessName; BusinessAddress1 = org.BusinessAddress1; @@ -39,6 +43,9 @@ namespace Bit.Admin.Models } public Organization Organization { get; set; } + public string RandomLicenseKey => CoreHelpers.SecureRandomString(20); + public string FourteenDayExpirationDate => DateTime.Now.AddDays(14).ToString("yyyy-MM-ddTHH:mm"); + public string BraintreeMerchantId { get; set; } [Required] [Display(Name = "Name")] diff --git a/src/Admin/Models/UserEditModel.cs b/src/Admin/Models/UserEditModel.cs index 3d688fb678..76ac508b3e 100644 --- a/src/Admin/Models/UserEditModel.cs +++ b/src/Admin/Models/UserEditModel.cs @@ -1,6 +1,8 @@ using System; using System.ComponentModel.DataAnnotations; +using Bit.Core; using Bit.Core.Models.Table; +using Bit.Core.Utilities; namespace Bit.Admin.Models { @@ -8,9 +10,11 @@ namespace Bit.Admin.Models { public UserEditModel() { } - public UserEditModel(User user) + public UserEditModel(User user, GlobalSettings globalSettings) { User = user; + BraintreeMerchantId = globalSettings.Braintree.MerchantId; + Name = user.Name; Email = user.Email; EmailVerified = user.EmailVerified; @@ -24,6 +28,9 @@ namespace Bit.Admin.Models } public User User { get; set; } + public string RandomLicenseKey => CoreHelpers.SecureRandomString(20); + public string OneYearExpirationDate => DateTime.Now.AddYears(1).ToString("yyyy-MM-ddTHH:mm"); + public string BraintreeMerchantId { get; set; } [Display(Name = "Name")] public string Name { get; set; } diff --git a/src/Admin/Views/Organizations/Edit.cshtml b/src/Admin/Views/Organizations/Edit.cshtml index 97430033d5..d23e4a938c 100644 --- a/src/Admin/Views/Organizations/Edit.cshtml +++ b/src/Admin/Views/Organizations/Edit.cshtml @@ -3,6 +3,74 @@ ViewData["Title"] = "Organization Edit: " + Model.Organization.Name; } +@section Scripts { + +} +

Edit Organization @Model.Organization.Name

@@ -414,21 +482,40 @@
- +
+ +
+ +
+
- +
+ +
+ +
+
- - Delete - +
+ + + Delete + +
diff --git a/src/Admin/Views/Shared/_Layout.cshtml b/src/Admin/Views/Shared/_Layout.cshtml index d0950f24fe..3598d0b338 100644 --- a/src/Admin/Views/Shared/_Layout.cshtml +++ b/src/Admin/Views/Shared/_Layout.cshtml @@ -50,6 +50,16 @@ © 2015-@DateTime.Now.Year 8bit Solutions LLC + + + + diff --git a/src/Admin/Views/Users/Edit.cshtml b/src/Admin/Views/Users/Edit.cshtml index d7ff5c0d93..8300fdd7be 100644 --- a/src/Admin/Views/Users/Edit.cshtml +++ b/src/Admin/Views/Users/Edit.cshtml @@ -3,6 +3,57 @@ ViewData["Title"] = "User Edit: " + Model.User.Email; } +@section Scripts { + +} +

Edit User @Model.User.Email

@@ -69,21 +120,40 @@
- +
+ +
+ +
+
- +
+ +
+ +
+
- - Delete - +
+ + + Delete + +
diff --git a/src/Core/Enums/GatewayType.cs b/src/Core/Enums/GatewayType.cs index 021e150f64..5a9dcdbd76 100644 --- a/src/Core/Enums/GatewayType.cs +++ b/src/Core/Enums/GatewayType.cs @@ -1,11 +1,18 @@ -namespace Bit.Core.Enums +using System.ComponentModel.DataAnnotations; + +namespace Bit.Core.Enums { public enum GatewayType : byte { + [Display(Name = "Stripe")] Stripe = 0, + [Display(Name = "Braintree")] Braintree = 1, + [Display(Name = "Apple App Store")] AppStore = 2, + [Display(Name = "Google Play Store")] PlayStore = 3, + [Display(Name = "Coinbase")] Coinbase = 4 } } diff --git a/src/Core/Enums/PlanType.cs b/src/Core/Enums/PlanType.cs index 4381ec511a..df02b8bf71 100644 --- a/src/Core/Enums/PlanType.cs +++ b/src/Core/Enums/PlanType.cs @@ -1,13 +1,22 @@ -namespace Bit.Core.Enums +using System.ComponentModel.DataAnnotations; + +namespace Bit.Core.Enums { public enum PlanType : byte { + [Display(Name = "Free")] Free = 0, + [Display(Name = "Families")] FamiliesAnnually = 1, + [Display(Name = "Teams (Monthly)")] TeamsMonthly = 2, + [Display(Name = "Teams (Annually)")] TeamsAnnually = 3, + [Display(Name = "Enterprise (Monthly)")] EnterpriseMonthly = 4, + [Display(Name = "Enterprise (Annually)")] EnterpriseAnnually = 5, + [Display(Name = "Custom")] Custom = 6 } }