public ActionResult ConfirmEmail(string validateToken) { EmailConfirmation emailconf = new EmailConfirmation(); try { if (Request.IsAuthenticated) { var username = User.Identity.Name; string decryptedEmail = EncryptionUtility.Decrypt(validateToken); emailconf.Email = decryptedEmail; using (PnPTestAutomationEntities dbContext = new PnPTestAutomationEntities()) { var user = dbContext.UsersSets.FirstOrDefault( u => u.Email.Equals(decryptedEmail, StringComparison.InvariantCultureIgnoreCase) && u.UPN.Equals(username, StringComparison.InvariantCultureIgnoreCase)); if (user != null) { user.IsEmailVerified = true; user.SendTestResults = true; dbContext.SaveChanges(); emailconf.IsEmailVerified = true; } } } else { HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/Usersettings/ConfirmEmail/" + validateToken }, OpenIdConnectAuthenticationDefaults.AuthenticationType); } } catch (Exception ex) { throw; } return View(emailconf); }
public ActionResult UpdateSettings(string email, bool isSendTestResults) { EmailConfirmation emailConfirmation = new EmailConfirmation(); try { if (Request.IsAuthenticated) { var username = User.Identity.Name; StringBuilder sbUserStatus = new StringBuilder(); using (PnPTestAutomationEntities dbContext = new PnPTestAutomationEntities()) { var user = dbContext.UsersSets.SingleOrDefault(u => u.UPN.Equals(username, StringComparison.InvariantCultureIgnoreCase)); if (user != null) { if (!isSendTestResults) { user.SendTestResults = false; user.Email = email; user.IsEmailVerified = false; dbContext.SaveChanges(); emailConfirmation.IsSettingsUpdated = true; } else if (isSendTestResults && user.Email != email) { user.SendTestResults = true; user.Email = email; dbContext.SaveChanges(); SendEmail(email); emailConfirmation.IsEmailSent = true; } } } } } catch (Exception ex) { throw; } return View(emailConfirmation); }