public string ActivationKey(string email) { string guid = Guid.NewGuid().ToString(); while (_activationService.GetByFilter(i => i.ActivationKey == guid) != null) { guid = Guid.NewGuid().ToString(); } string key = email + ":OSK:" + DateTime.Now + ":OSK:" + guid; EmailValid emailValid = new EmailValid { Email = email, Time = DateTime.Now, ActivationKey = guid }; _activationService.Insert(emailValid); return(new Helpers.AESEncryption().EncryptText(key)); }
public IActionResult Activation(string key) { string output = new Helpers.AESEncryption().DecryptText(key); string[] tokens = output.Split(":OSK:"); EmailValid emailValid = _activationService.GetByFilter(i => i.Email == tokens[0] && i.ActivationKey == tokens[2] && DateTime.Parse(i.Time.ToString()) == DateTime.Parse(tokens[1])); if (emailValid != null) { if (DateTime.Now > DateTime.Parse(tokens[1]).AddDays(1)) { return(RedirectToAction("EmailValidExpired", "Alert")); } _activationService.Delete(emailValid); CryptoBox.Data.Models.Users user = _userService.GetByFilter(i => emailValid.Email == i.Email); user.EmailValid = true; _userService.UpdateUser(user); return(RedirectToAction("EmailValidSuccess", "Alert")); } return(RedirectToAction("EmailValidFailed", "Alert")); }