diff --git a/Web/Controllers/ControllerBase.cs b/Web/Controllers/ControllerBase.cs index 1a4898f..376fb2e 100644 --- a/Web/Controllers/ControllerBase.cs +++ b/Web/Controllers/ControllerBase.cs @@ -60,7 +60,10 @@ namespace MileageTraker.Web.Controllers protected string ResetPassword(User user) { - var passwordResetToken = Algorithms.GenerateToken(); + // don't make a new one if they already have an active token + var passwordResetToken = + user.PasswordResetToken ?? Algorithms.GenerateToken(); + var url = LinkForUrlAction( Url.Action("NewPassword", "Account", new NewPasswordViewModel diff --git a/Web/Controllers/UserController.cs b/Web/Controllers/UserController.cs index a705132..f74bbef 100644 --- a/Web/Controllers/UserController.cs +++ b/Web/Controllers/UserController.cs @@ -1,5 +1,7 @@ using System; +using System.Data.SqlTypes; using System.Linq; +using System.Threading.Tasks; using System.Web.Mvc; using System.Web.Security; using MileageTraker.Web.Attributes; @@ -147,6 +149,29 @@ namespace MileageTraker.Web.Controllers return View(viewModel); } + public JsonResult SendInvite(Guid userId) + { + var user = DataService.GetUser(userId); + var resetPasswordUrl = ResetPassword(user); + var email = new EmailNotificationService(); + email.SendInitializePassword(user, resetPasswordUrl); + return Json(true, JsonRequestBehavior.AllowGet); + } + + [Authorize(Roles = "Developer")] + public ActionResult InviteUninitialized() + { + var uninitializedUsers = + (from user in DataService.GetUsers() + where user.LastPasswordChangedDate == SqlDateTime.MinValue.Value + && user.LastActivityDate == SqlDateTime.MinValue.Value + && user.IsApproved + orderby user.Username + select user).ToList(); + + return View(uninitializedUsers); + } + public ActionResult Edit(Guid id) { var user = DataService.GetUser(id); diff --git a/Web/Scripts/Shared/Site.js b/Web/Scripts/Shared/Site.js index b38166d..e119340 100644 --- a/Web/Scripts/Shared/Site.js +++ b/Web/Scripts/Shared/Site.js @@ -224,4 +224,5 @@ $(function () { }); }); -/* End Form Validation */ \ No newline at end of file +/* End Form Validation */ + diff --git a/Web/Views/User/Index.cshtml b/Web/Views/User/Index.cshtml index f756278..b3d8420 100644 --- a/Web/Views/User/Index.cshtml +++ b/Web/Views/User/Index.cshtml @@ -20,6 +20,10 @@
@Html.ActionLink("Add new User", "Create", null, new{@class="btn"}) @Html.ActionLink("Export", "Export", null, new{@class="btn"}) + @if (User.IsInRole("Developer")) + { + @Html.ActionLink("Invite Uninintialized", "InviteUninitialized", null, new{@class="btn"}) + }
Users online now: @Membership.GetNumberOfUsersOnline()
diff --git a/Web/Views/User/InviteUninitialized.cshtml b/Web/Views/User/InviteUninitialized.cshtml new file mode 100644 index 0000000..50c8bb6 --- /dev/null +++ b/Web/Views/User/InviteUninitialized.cshtml @@ -0,0 +1,54 @@ +@model List + +@{ + ViewBag.Title = "Invite Uninitialized Users"; +} + +@{ Html.RenderPartial("BackToUsers"); } + +@Html.Partial("_StatusMessage") + +

@ViewBag.Title

+ +
+ Send Invitations +

Inviting...

+ +
+ +@section Scripts +{ + +} diff --git a/Web/Web.csproj b/Web/Web.csproj index 8e2002d..111c092 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -302,6 +302,7 @@ +