public IActionResult SendConfirmMail(string userId, string email) { var vm = new EmailConfirmationVM() { UserId = Convert.ToInt32(_protector.Decode(userId)), ConfirmationEmail = _protector.Decode(email.ToString()), }; if (!IsValidEmail(vm.ConfirmationEmail)) { ModelState.AddModelError("Email", "Invalid Email"); return(View(vm)); } //send Confirm Email var user = _userService.GetUserById(vm.UserId); if (user == null) { return(NotFound()); } string code = Guid.NewGuid().ToString(); user.EmailCode = code; _userService.EditUser(user); var subject = "Email Confirmation."; var CallBackUrl = Url.Action("ConfirmEmail", "User", new { userId = userId, code = _protector.Encode(code) }, protocol: Request.Scheme); var mailTemplate = System.IO.File.ReadAllText("./Models/ViewModel/UserVM/EmailConfirm.html"); mailTemplate = mailTemplate.Replace("{UserName}", user.UserName); mailTemplate = mailTemplate.Replace("{Content}", "Please click bellow button for confirm your email."); mailTemplate = mailTemplate.Replace("{ConfirmationLink}", CallBackUrl); _emailService.SendEmail(user.Email, subject, mailTemplate); ModelState.AddModelError("", "Confirmation mail is sent. Please check your email."); return(View(vm)); }
public IActionResult SendConfirmMail(EmailConfirmationVM vm) { if (ModelState.IsValid) { var user = _userService.GetUserById(vm.UserId); if (vm.ConfirmationEmail != user.Email) { user.Email = vm.ConfirmationEmail; _userService.EditUser(user); } //send Confirm Email string code = Guid.NewGuid().ToString(); user.EmailCode = code; _userService.EditUser(user); var subject = "Email Confirmation."; var CallBackUrl = Url.Action("ConfirmEmail", "User", new { userId = _protector.Encode(user.Id.ToString()), code = _protector.Encode(code) }, protocol: Request.Scheme); var mailTemplate = System.IO.File.ReadAllText("./Models/ViewModel/UserVM/EmailConfirm.html"); mailTemplate = mailTemplate.Replace("{UserName}", user.UserName); mailTemplate = mailTemplate.Replace("{Content}", "Please click bellow button for confirm your email."); mailTemplate = mailTemplate.Replace("{ConfirmationLink}", CallBackUrl); _emailService.SendEmail(user.Email, subject, mailTemplate); ModelState.AddModelError("", "Confirmation mail is sent. Please check your email."); return(View(vm)); } return(View(vm)); }
public async Task <BaseResponse> EmailConfirmation([FromBody] EmailConfirmationVM model) { return(constructResponse(_businessWrapper.UserBL.ConfirmEmail(model.UserIdentifire, model.Token))); }