public async Task <IActionResult> Register([Bind("UserName, Email,Password,ConfirmPassword, Phone, PhoneNumber, ConfirmPhoneNumber")] RegisterViewModel model) { if (ModelState.IsValid) { var user = new IdentityUser { UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber, }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { user = await _userManager.FindByEmailAsync(user.Email); var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationLink = Url.ActionLink("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme); var email = new EmailComposer { emailAddressSender = "*****@*****.**", emailAddressRecipient = user.Email, smtpServiceAddress = "smtp.sapo.pt", port = 25, password = "******", subject = "Email Confirmation", body = "Please confirm your email in order to login on to our Book Sharing web application. Click on the following link...." + confirmationLink, }; email.SendEmail(); ViewBag.Message = "We sent you a confirmation request for your email. Plese check your mailbox."; return(View("ConfirmEmail")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } return(View(model)); }
public IActionResult Contact([Bind("Email, FullName, Message")] CreateContactViewModel model) { if (ModelState.IsValid) { var user = new CreateContactViewModel { Email = model.Email, FullName = model.FullName, Message = model.Message }; var adminUsers = (from p in _context.Users join e in _context.UserRoles on p.Id equals e.UserId where e.RoleId == "b51d6fb0-1d08-4e6a-854c-10d1f1d84a71" select new { email = p.Email }).ToList(); for (int i = 0; i < adminUsers.Count; i++) { var email = new EmailComposer { emailAddressSender = "*****@*****.**", emailAddressRecipient = adminUsers[i].email, smtpServiceAddress = "smtp.sapo.pt", port = 25, password = "******", subject = user.FullName + " is contacting the administration", body = user.Message + "\nUser Email: " + user.Email, }; email.SendEmail(); } } return(RedirectToAction("Contact")); }