private string SendConfirmationEmail(string code, string userId, string password, string language) { if (language == "en") { string confirmationLink = Url.Action("ConfirmEmail", "Auth", new { userid = userId, code }, protocol: HttpContext.Request.Scheme); string emailBody = ""; //using (StreamReader reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Email/accountCreation.html"))) //{ // emailBody = reader.ReadToEnd(); // emailBody = emailBody.Replace("^Password^", password, StringComparison.OrdinalIgnoreCase); // emailBody = emailBody.Replace("^Confirm^", confirmationLink, StringComparison.OrdinalIgnoreCase); //} var templateObj = new EmailTemplateData { Password = password, HrefLink = confirmationLink, Url = AppDomain.CurrentDomain.BaseDirectory, FileName = "Email/accountCreation.html" }; emailBody = EmailTextFormatter.Format(templateObj); return(emailBody); } return(""); }
public async Task <IActionResult> Post(string personId, [FromBody] EmailVerification value) { value.PersonId = new Guid(personId); //check the email address in verification email table var emailVerification = repository.Find(null, p => p.Address.Equals(value.Address, StringComparison.OrdinalIgnoreCase))?.Items?.FirstOrDefault(); //if not null then email address already exists if (emailVerification != null) { ModelState.AddModelError("EmailAddress", "email address already in use"); return(BadRequest(ModelState)); } value.IsVerified = false; try { //resending byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary()); byte[] key = applicationUser.PersonId.ToByteArray(); string token = Convert.ToBase64String(time.Concat(key).ToArray()); string confirmationLink = Url.Action("ConfirmEmailAddress", "Auth", new { emailAddress = value.Address, token = token }, protocol: HttpContext.Request.Scheme); string emailBody = ""; //using (StreamReader reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Email/confirm-en.html"))) //{ // emailBody = reader.ReadToEnd(); // emailBody = emailBody.Replace("^Confirm^", confirmationLink); //} var templateObj = new EmailTemplateData { HrefLink = confirmationLink, Url = AppDomain.CurrentDomain.BaseDirectory, FileName = "Email/confirm-en.html" }; emailBody = EmailTextFormatter.Format(templateObj); var subject = "Confirm your email address at " + Constants.PRODUCT; bool isEmailAllowed = emailSender.IsEmailAllowed(); if (isEmailAllowed) { EmailMessage emailMessage = new EmailMessage(); EmailAddress address = new EmailAddress(value.Person.Name, value.Address); emailMessage.To.Add(address); emailMessage.Body = emailBody; emailMessage.Subject = subject; await emailSender.SendEmailAsync(emailMessage, null, null, "Outgoing").ConfigureAwait(false); value.IsVerificationEmailSent = true; } else { value.IsVerificationEmailSent = false; } } catch (Exception ex) { return(ex.GetActionResult()); } var verificationEmail = await base.PostEntity(value).ConfigureAwait(false); return(verificationEmail); }