diff --git a/Amen/Controllers/NotificationController.cs b/Amen/Controllers/NotificationController.cs index ac317ae..b892add 100644 --- a/Amen/Controllers/NotificationController.cs +++ b/Amen/Controllers/NotificationController.cs @@ -31,7 +31,6 @@ namespace Amen.Controllers ManageUrl = controllerHelper.Absolute(this.Url, Url.Action("Index", "Manage", new { affiliatekey = prayer.Affiliate.Key })) }; ViewBag.LogoUrl = controllerHelper.Absolute(this.Url, Url.Content("~/Content/Images/amen-logo-flyin.gif")); - return View("~/Views/Email/Prayed.cshtml", model); } @@ -47,7 +46,6 @@ namespace Amen.Controllers ManageUrl = controllerHelper.Absolute(this.Url, Url.Action("Index", "Manage", new { affiliatekey = prayer.Affiliate.Key })) }; ViewBag.LogoUrl = controllerHelper.Absolute(this.Url, Url.Content("~/Content/Images/amen-logo-flyin.gif")); - return View("~/Views/Email/PrayerSubmitted.cshtml", model); } @@ -64,7 +62,6 @@ namespace Amen.Controllers ManageUrl = controllerHelper.Absolute(this.Url, Url.Action("Index", "Manage", new { affiliatekey = prayer.Affiliate.Key })) }; ViewBag.LogoUrl = controllerHelper.Absolute(this.Url, Url.Content("~/Content/Images/amen-logo-flyin.gif")); - return View("~/Views/Email/NoteSent.cshtml", model); } @@ -82,7 +79,6 @@ namespace Amen.Controllers NotificationTypeMessage = string.Format("A new {0} has been submitted.", prayer.IsPraise ? "Praise" : "Prayer") }; ViewBag.LogoUrl = controllerHelper.Absolute(this.Url, Url.Content("~/Content/Images/amen-logo-flyin.gif")); - return View("~/Views/Email/AdminNotification.cshtml", model); } @@ -206,34 +202,21 @@ namespace Amen.Controllers var model = new PrayerEmailViewModel(); model.Title = prayer.Summary; model.Subject = "We are praying for you!"; - if (appUser != null) - { - model.To = appUser.Email; - } - else - { - model.To = prayer.AnonymousEmail; - } model.DetailUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Detail", "Prayer", new { id = prayer.Id, affiliatekey = affiliate.Key })); model.ManageUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Index", "Manage", new { affiliatekey = affiliate.Key })); model.IsUserLoggedIn = !string.IsNullOrEmpty(prayer.ApplicationUserId); model.IsPraise = prayer.IsPraise; - if (CanSendEmail(affiliate, ref appUser, prayer, false, true)) + if (CanSendEmail(affiliate, ref appUser, prayer, false, true) && (prayer.ContactPreference == "email" || prayer.ContactPreference == "any")) { - if (prayer.ContactPreference == "email" || prayer.ContactPreference == "any") - { - var body = ControllerHelper.RenderViewToString(controller.ControllerContext, "~/Views/Email/PrayerSubmitted.cshtml", model); - SendEmailMessage(model.To, model.Subject, body); - } + var body = ControllerHelper.RenderViewToString(controller.ControllerContext, "~/Views/Email/PrayerSubmitted.cshtml", model); + SendEmailMessage(prayer.AnonymousEmail, model.Subject, body); } - if (CanSendText(affiliate, ref appUser, prayer)) + if (CanSendText(affiliate, ref appUser, prayer) && (prayer.ContactPreference == "phone" || prayer.ContactPreference == "any")) { - if (prayer.ContactPreference == "phone" || prayer.ContactPreference == "any") - { - SendSmsMessage(affiliate.TwilioSID, affiliate.TwilioAuthToken, affiliate.TwilioPhoneNumber, appUser.PhoneNumber, string.Format("We are praying for you! {0}", model.DetailUrl)); - } + var message = string.Format("We are praying for you! {0}", model.DetailUrl); + SendSmsMessage(affiliate.TwilioSID, affiliate.TwilioAuthToken, affiliate.TwilioPhoneNumber, prayer.AnonymousPhone, message); } if (affiliate != null @@ -247,9 +230,7 @@ namespace Amen.Controllers { var controller2 = GetBaseController(affiliate); controller2.ViewBag.LogoUrl = controller2.controllerHelper.Absolute(urlHelper, urlHelper.Content("~/Content/Images/amen-logo-flyin.gif")); - var adminModel = new AdminEmailViewModel(); - adminModel.PrayerTitle = prayer.Summary; adminModel.PrayerContent = prayer.Content; adminModel.Subject = string.Format("Admin Notification: {0} Requested", prayer.IsPraise ? "Praise" : "Prayer"); @@ -261,9 +242,7 @@ namespace Amen.Controllers } adminModel.DetailUrl = controller2.controllerHelper.Absolute(urlHelper, urlHelper.Action("Detail", "Prayer", new { id = prayer.Id, affiliatekey = affiliate.Key, isPraise = prayer.IsPraise })); adminModel.ManageUrl = controller2.controllerHelper.Absolute(urlHelper, urlHelper.Action("Index", "Group")); - var body = ControllerHelper.RenderViewToString(controller2.ControllerContext, "~/Views/Email/AdminNotification.cshtml", adminModel); - SendEmailMessage(adminModel.To, adminModel.Subject, body); } } @@ -274,51 +253,37 @@ namespace Amen.Controllers var controller = GetBaseController(affiliate); model.DetailUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Detail", "Prayer", new { id = prayer.Id, affiliatekey = affiliate.Key })); model.ManageUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Index", "Manage", new { affiliatekey = affiliate.Key })); + model.Title = prayer.Summary; - if (CanSendText(affiliate, ref appUser, prayer)) + if (CanSendEmail(affiliate, ref appUser, prayer) && (prayer.ContactPreference == "email" || prayer.ContactPreference == "any")) { - if (prayer.ContactPreference == "phone" || prayer.ContactPreference == "any") - { - SendSmsMessage(affiliate.TwilioSID, affiliate.TwilioAuthToken, affiliate.TwilioPhoneNumber, appUser.PhoneNumber, string.Format("Someone just prayed for you! {0}", model.DetailUrl)); - } + controller.ViewBag.LogoUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Content("~/Content/Images/amen-logo-flyin.gif")); + var subject = !string.IsNullOrEmpty(affiliate.SendMessagePrayed) ? affiliate.SendMessagePrayed : "Someone just prayed for you!"; + var body = ControllerHelper.RenderViewToString(controller.ControllerContext, "~/Views/Email/Prayed.cshtml", model); + SendEmailMessage(prayer.AnonymousEmail, subject, body); } - if (CanSendEmail(affiliate, ref appUser, prayer)) + if (CanSendText(affiliate, ref appUser, prayer) && (prayer.ContactPreference == "phone" || prayer.ContactPreference == "any")) { - if (prayer.ContactPreference == "email" || prayer.ContactPreference == "any") - { - controller.ViewBag.LogoUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Content("~/Content/Images/amen-logo-flyin.gif")); - - model.Title = prayer.Summary; - model.Subject = !string.IsNullOrEmpty(affiliate.SendMessagePrayed) ? affiliate.SendMessagePrayed : "Someone just prayed for you!"; - model.To = appUser.Email; - - var body = ControllerHelper.RenderViewToString(controller.ControllerContext, "~/Views/Email/Prayed.cshtml", model); - - SendEmailMessage(model.To, model.Subject, body); - } + var message = string.Format("Someone just prayed for you! {0}", model.DetailUrl); + SendSmsMessage(affiliate.TwilioSID, affiliate.TwilioAuthToken, affiliate.TwilioPhoneNumber, prayer.AnonymousPhone, message); } } public static void NotifyNoteSent(UrlHelper urlHelper, Affiliate affiliate, ApplicationUser appUser, Prayer prayer, PrayerNote note) { - if (!CanSendEmail(affiliate, ref appUser, prayer, true) || !prayer.EnableEmailNote) - return; - + if (!CanSendEmail(affiliate, ref appUser, prayer, true) || !prayer.EnableEmailNote) { return; } var controller = GetBaseController(affiliate); controller.ViewBag.LogoUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Content("~/Content/Images/amen-logo-flyin.gif")); - var model = new PrayerEmailViewModel(); model.Title = prayer.Summary; model.NoteText = note.NoteText; model.Subject = !string.IsNullOrEmpty(affiliate.SendMessagePrayed) ? affiliate.SendMessageNote : "A note from Amen"; - model.To = appUser.Email; model.DetailUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Detail", "Prayer", new { id = prayer.Id, affiliatekey = affiliate.Key })); model.ManageUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Index", "Manage", new { affiliatekey = affiliate.Key })); - var body = ControllerHelper.RenderViewToString(controller.ControllerContext, "~/Views/Email/NoteSent.cshtml", model); - SendEmailMessage(model.To, model.Subject, body); + SendEmailMessage(prayer.AnonymousEmail, model.Subject, body); } public static void NotifyPrayerFlagged(UrlHelper urlHelper, Affiliate affiliate, Prayer prayer, PrayerFlag flag) @@ -327,22 +292,16 @@ namespace Amen.Controllers { var controller = GetBaseController(affiliate); controller.ViewBag.LogoUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Content("~/Content/Images/amen-logo-flyin.gif")); - - var model = new AdminEmailViewModel(); - model.NotificationTypeMessage = "Prayer Flagged"; - model.PrayerTitle = prayer.Summary; - if (!string.IsNullOrEmpty(flag.Reason)) - { - model.PrayerContent = "Has been flagged for the following reason: " + flag.Reason; - } - model.Subject = "An Amen Prayer Has Been Flagged"; - model.To = affiliate.EmailFlag; - model.DetailUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Detail", "Prayer", new { id = prayer.Id, affiliatekey = affiliate.Key })); - model.ManageUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Index", "Group", new { affiliatekey = affiliate.Key })); - - var body = ControllerHelper.RenderViewToString(controller.ControllerContext, "~/Views/Email/AdminNotification.cshtml", model); - - SendEmailMessage(model.To, model.Subject, body); + var adminModel = new AdminEmailViewModel(); + adminModel.NotificationTypeMessage = "Prayer Flagged"; + adminModel.PrayerTitle = prayer.Summary; + if (!string.IsNullOrEmpty(flag.Reason)) { adminModel.PrayerContent = "Has been flagged for the following reason: " + flag.Reason; } + adminModel.Subject = "An Amen Prayer Has Been Flagged"; + adminModel.To = affiliate.EmailFlag; + adminModel.DetailUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Detail", "Prayer", new { id = prayer.Id, affiliatekey = affiliate.Key })); + adminModel.ManageUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Index", "Group", new { affiliatekey = affiliate.Key })); + var body = ControllerHelper.RenderViewToString(controller.ControllerContext, "~/Views/Email/AdminNotification.cshtml", adminModel); + SendEmailMessage(adminModel.To, adminModel.Subject, body); } } } diff --git a/Amen/Scripts/site-prayer.js b/Amen/Scripts/site-prayer.js index e4b9a10..59b0a63 100644 --- a/Amen/Scripts/site-prayer.js +++ b/Amen/Scripts/site-prayer.js @@ -600,49 +600,49 @@ $(function () { } if (name.length == 0) { - alert('First Name is required'); + alert('First Name is required.'); return false; } if (content.length == 0) { - alert('Prayer Request is required'); + alert('Prayer Request is required.'); return false; } if (email.length == 0) { - alert('Email is required'); + alert('Email is required.'); return false; } if (contactpreference == 'phone' || contactpreference == 'any') { if (phone.length == 0) { - alert('Phone is required'); + alert('Phone number is required for text notifications.'); return false; } } if (email && email.length > 0) { if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) { - alert("You have entered an invalid email address!"); + alert("You have entered an invalid email address. Please, check and try again."); return (false); } } if (phone && phone.length > 0) { if (!(/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/.test(phone))) { - alert("You have entered an invalid phone number!"); + alert("You have entered an invalid phone number. Please, check and try again."); return (false); } } if (UpperCasePercent(content) > 0.5) { - alert('Please do not use ALL CAPS') + alert('Please do not use ALL CAPS.') return false; } var containsLinkRegex = new RegExp(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi); if (content.match(containsLinkRegex)) { - alert('Please do not include links') + alert('Please do not include links.') return false; } diff --git a/Amen/Views/Email/AdminNotification.cshtml b/Amen/Views/Email/AdminNotification.cshtml index e90b04b..6524e1e 100644 --- a/Amen/Views/Email/AdminNotification.cshtml +++ b/Amen/Views/Email/AdminNotification.cshtml @@ -8,36 +8,63 @@