public async Task Message(ContactUsMessageData model) { if (!ModelState.IsValid) { BadRequest(ModelState); // Note: BadRequest returns non-localized strings part of .net. I don't know if we display those return; } var messageDump = new ContactUsDump { Email = model.Email, Subject = model.Subject, Message = model.Message, Uri = model.Uri }; if (User.Identity.IsAuthenticated) { messageDump.UserId = User.Identity.GetClaims().Id; messageDump.Email = _db.AspNetUsers.Find(User.Identity.GetUserId()).Email; } await SendEmail(messageDump); Ok(); }
public IActionResult Contacts_Submit(ContactUsMessageData messageData) { if (!ModelState.IsValid) { return(View(ViewNameContacts, messageData)); } // санитайзер var sanitizer = new HtmlSanitizer(); var nameSanitized = sanitizer.Sanitize(messageData.CustomerName); var emailSanitized = sanitizer.Sanitize(messageData.CustomerEmail); var subjectSanitized = sanitizer.Sanitize(messageData.EmailSubject); var messageSanitized = sanitizer.Sanitize(messageData.EmailMessage); if (string.IsNullOrWhiteSpace(nameSanitized)) { var msg = @DbRes.T("CustomerName_Text", ResourceSet); ModelState.AddModelError(string.Empty, msg); return(View(ViewNameContacts, messageData)); } if (string.IsNullOrWhiteSpace(emailSanitized)) { var msg = @DbRes.T("CustomerEmail_Hint", ResourceSet); ModelState.AddModelError(string.Empty, msg); return(View(ViewNameContacts, messageData)); } if (!EMailValidator.IsValid(emailSanitized)) { var msg = @DbRes.T("CustomerEmail_Invalid", ResourceSet); ModelState.AddModelError(string.Empty, msg); return(View(ViewNameContacts, messageData)); } if (string.IsNullOrWhiteSpace(subjectSanitized)) { var msg = @DbRes.T("Subject_Hint", ResourceSet); ModelState.AddModelError(string.Empty, msg); return(View(ViewNameContacts, messageData)); } if (string.IsNullOrWhiteSpace(messageSanitized)) { var msg = @DbRes.T("Message_Text", ResourceSet); ModelState.AddModelError(string.Empty, msg); return(View(ViewNameContacts, messageData)); } var rc = DbHelper.ContactsEMailRegister(nameSanitized, emailSanitized, subjectSanitized, messageSanitized, out string errMsg); if (!rc) { ModelState.AddModelError(string.Empty, errMsg); return(View(ViewNameContacts, messageData)); } TempData["Message"] = "Yours message was registered successfully"; return(RedirectToAction("Info", "Home")); }