From b19b44305aae0a99a794b510dd11c3d21e78a69f Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Tue, 15 Jan 2013 15:28:17 -0500 Subject: [PATCH] Add details to emails A few clarifications --- Notes/MissingCityNames.sql | 9 +++++++++ Web/Controllers/AccountController.cs | 15 +++++++++++++-- Web/Controllers/UserController.cs | 13 ++++++++++++- Web/Email/EmailNotification.cs | 4 ++-- Web/ViewModels/User/ExportUserViewModel.cs | 10 ++++++++-- Web/Views/User/Details.cshtml | 14 +++++++++++++- Web/Web.config | 4 ++-- 7 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 Notes/MissingCityNames.sql diff --git a/Notes/MissingCityNames.sql b/Notes/MissingCityNames.sql new file mode 100644 index 0000000..45dcaba --- /dev/null +++ b/Notes/MissingCityNames.sql @@ -0,0 +1,9 @@ +select CityName, City.Name, lc.LogCount +from ( +select CityName, COUNT(1) as LogCount +from Log +group by log.CityName +) lc +left join City on lc.CityName = City.Name +where City.Name is null +order by LogCount desc \ No newline at end of file diff --git a/Web/Controllers/AccountController.cs b/Web/Controllers/AccountController.cs index 5696351..60b5ca4 100644 --- a/Web/Controllers/AccountController.cs +++ b/Web/Controllers/AccountController.cs @@ -158,9 +158,20 @@ namespace MileageTraker.Web.Controllers var email = new EmailNotificationService(); var resetPasswordUrl = ResetPassword(user); email.SendResetPassword(user, resetPasswordUrl); + TempData["StatusMessage"] = "Please check your email - we have sent a request for you to reset the password."; } - - TempData["StatusMessage"] = "Please check your email - we have sent a request for you to reset the password."; + else if (user == null) + { + TempData["StatusMessage"] = "Could not find username " + viewModel.Username + "."; + TempData["StatusMessage-Type"] = "alert-error"; + return RedirectToAction("ResetPassword"); + } + else if (!user.IsApproved) + { + TempData["StatusMessage"] = "Account is disabled for " + viewModel.Username + "."; + TempData["StatusMessage-Type"] = "alert-error"; + } + // even when if not successful, let the user think they're getting a cookie return RedirectToAction("Login"); } diff --git a/Web/Controllers/UserController.cs b/Web/Controllers/UserController.cs index 5f0b053..5463c17 100644 --- a/Web/Controllers/UserController.cs +++ b/Web/Controllers/UserController.cs @@ -1,7 +1,6 @@ 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; @@ -149,6 +148,7 @@ namespace MileageTraker.Web.Controllers return View(viewModel); } + [HttpGet] public JsonResult SendInvite(Guid userId) { var user = DataService.GetUser(userId); @@ -158,6 +158,17 @@ namespace MileageTraker.Web.Controllers return Json(true, JsonRequestBehavior.AllowGet); } + [HttpGet] + public ActionResult SendResetPassword(Guid userId) + { + var user = DataService.GetUser(userId); + var resetPasswordUrl = ResetPassword(user); + var email = new EmailNotificationService(); + email.SendResetPassword(user, resetPasswordUrl); + TempData["StatusMessage"] = "Reset password sent to User " + user.Username + " at " + user.Email; + return RedirectToAction("Details", new { id = userId}); + } + [Authorize(Roles = "Developer")] public ActionResult InviteUninitialized() { diff --git a/Web/Email/EmailNotification.cs b/Web/Email/EmailNotification.cs index 091a918..1b3f042 100644 --- a/Web/Email/EmailNotification.cs +++ b/Web/Email/EmailNotification.cs @@ -46,13 +46,13 @@ namespace MileageTraker.Web.Email /// Reset url public void SendResetPassword(User user, string url) { - var body = string.Format(_resetPasswordBody, url); + var body = string.Format(_resetPasswordBody, url, user.Username); SendMessage(new MailMessage(_emaialFromAddress, user.Email, _resetPasswordSubject, body)); } public void SendInitializePassword(User user, string url) { - var body = string.Format(_initializePasswordBody, url, user.FullName); + var body = string.Format(_initializePasswordBody, url, user.FullName, user.Username); SendMessage(new MailMessage(_emaialFromAddress, user.Email, _initializePasswordSubject, body)); } diff --git a/Web/ViewModels/User/ExportUserViewModel.cs b/Web/ViewModels/User/ExportUserViewModel.cs index 7f8a819..b730bb5 100644 --- a/Web/ViewModels/User/ExportUserViewModel.cs +++ b/Web/ViewModels/User/ExportUserViewModel.cs @@ -1,6 +1,7 @@ -using System.Web.Mvc; +using System; using System.Linq; using AutoMapper; +using MileageTraker.Web.Utility; namespace MileageTraker.Web.ViewModels.User { @@ -24,12 +25,17 @@ namespace MileageTraker.Web.ViewModels.User static ExportUserViewModel() { + Mapper.CreateMap() + .ConvertUsing(dt => + dt.IsSqlMinValue() + ? string.Empty + : dt.Date.ToString("d")); + Mapper.CreateMap() .ForMember(u => u.Roles, opt => opt.MapFrom(u => string.Join((", "), u.Roles.Select(r => r.RoleName)))); } - public ExportUserViewModel(Models.User user) { Mapper.Map(user, this); diff --git a/Web/Views/User/Details.cshtml b/Web/Views/User/Details.cshtml index 7943068..5b1fc2d 100644 --- a/Web/Views/User/Details.cshtml +++ b/Web/Views/User/Details.cshtml @@ -117,7 +117,19 @@
@Html.ActionLink("Edit", "Edit", new { id = Model.UserId }, new { @class = "btn" }) - @Html.ActionLink("Set Password", "SetPassword", new { id = Model.UserId }, new { @class = "btn" }) +
+ + Password + + +
@if (Model.IsApproved) { @Html.ActionLink("Disable Account", "DisableUser", new {id = Model.UserId}, new {@class = "btn"}) diff --git a/Web/Web.config b/Web/Web.config index 8e1e9c7..108ebf5 100644 --- a/Web/Web.config +++ b/Web/Web.config @@ -15,9 +15,9 @@ - + - +