/// <summary> /// Sends the validation token to the given mail. /// </summary> /// <param name="mail"></param> /// <param name="redirect"></param> public void SendMailValidation(FullUser fullUser, string redirect) { var guid = Guid.NewGuid(); MaileCode mc = new MaileCode(fullUser.finalMailID, guid); //check if old request is exist and remove it MaileCode existMailCode = _context.MailCodes.SingleOrDefault(mcoode => mcoode.mail == fullUser.finalMailID); if (existMailCode != null) { // remove old request for reset password _context.Remove(existMailCode); } //save new request for reset pass _context.MailCodes.Add(mc); _context.SaveChanges(); if (whiteListEmailFilter.IsValid(fullUser.finalMailID)) { SendMsg(redirect, fullUser.finalMailID, guid); } }
public IActionResult ResetPassword(string mail, string code) { Guid guid = _context.MailCodes.Single(mc => mc.mail == mail).code; if (guid != null) { if (guid.ToString() == code) { MaileCode mailCode = _context.MailCodes.Single(mc => mc.mail == mail); _context.Remove(mailCode); return(View()); } } return(RedirectToAction("Error", "Index")); }
/// <summary> /// Validating the user's mail. /// We are getting here when the user clicks the link in the validation mail. /// </summary> /// <param name="mail"></param> /// <param name="code"></param> /// <returns></returns> public ActionResult validate(string mail, string code) { if (whiteListEmailFilter.IsValid(mail)) { // Getting the GUID from the url and searching for it in the DB. MaileCode mc = _context.MailCodes.SingleOrDefault(m => m.mail.Equals(mail)); if (mc != null) { Guid g = mc.code; } if (code.Equals(mc.code.ToString())) { // Marking the user as verifyed and redirecting it to the login screen var user = _context.FullUsers.SingleOrDefault(fm => fm.finalMailID == mail); //var user = ElasticsearchUtils.Search(mail); if (!user.isVerifyed) { user.isVerifyed = true; _context.Update(user); _context.SaveChanges(); _context.MailCodes.Remove(mc); _context.SaveChanges(); } LoginStep ls = new LoginStep(); ls.mail = mail; ls.pass = user.finalPass; return(RedirectToAction("Index")); } else { return(RedirectToAction("Error", "Index", new { eror = "חלה שגיאה בתהליך האימות" })); } } else { return(RedirectToAction("Error", "Index", new { eror = "חלה שגיאה בתהליך האימות" })); } }