コード例 #1
0
		public ActionResult Index(ContactUsFormViewModel form)
		{
			if (!ModelState.IsValid)
			{
				return View(form);
			}


			if (validateContactMessage(form))
			{
				var settings = _contactUsService.Get();
				var recipient = _membershipService.GetUser(settings.RecipientUserName);

				if (recipient == null || String.IsNullOrEmpty(recipient.Email))
				{
					Services.Notifier.Warning(T("Site error: Couldn't send message. Site owner needs to set valid recipient user with an email address."));
					return View(form);
				}

				_messageManager.Send(recipient.ContentItem.Record, "ContactUs", "Email",
										new Dictionary<String, String> {
											{ "Name", form.Name },
											{ "Email", form.Email },
											{ "Message", form.Message }
										});

				Services.Notifier.Information(T("Thank you for your message."));
			}
			else
			{
				// Message stopped because it looked like spam
				Services.Notifier.Information(T("Sorry we could not send your message."));
			}

			return View("Sent", form);
		}
コード例 #2
0
		private bool validateContactMessage(ContactUsFormViewModel form)
		{
			var comment = new CommentPart() { Record = new CommentPartRecord {
														Author		= form.Name,
														Email		= form.Email,
														CommentText	= form.Message,
														SiteName	= "",
													} };
			return _commentValidator.ValidateComment(comment);
		}