public ActionResult VerifyAccount(string id) { bool status = false; using (JITContext db = new JITContext()) { db.Configuration.ValidateOnSaveEnabled = false; try { var v = db.Users.Where(user => user.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; db.SaveChanges(); status = true; } else { ViewBag.Message = "Invalid Request"; ViewBag.Status = false; } } catch (FormatException e) { ViewBag.Message = "Invalid Request"; ViewBag.Status = false; } } ViewBag.Status = status; return(View()); }
public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] User user) { bool status = false; string message = ""; if (ModelState.IsValid) { #region Email or name already exists bool emailCheck = EmailExist(user.Email); bool userNameCheck = UserNameExist(user.UserName); if (emailCheck) { ModelState.AddModelError("EmailExists", "Email already exists"); } if (userNameCheck) { ModelState.AddModelError("UserNameExists", "User name already exists"); } if (emailCheck || userNameCheck) { return(View(user)); } #endregion #region Generate activation code user.ActivationCode = Guid.NewGuid(); #endregion #region Password hashing user.Password = System.Web.Helpers.Crypto.HashPassword(user.Password); System.Diagnostics.Debug.WriteLine(System.Web.Helpers.Crypto.VerifyHashedPassword(user.Password, "qwerty")); #endregion #region Save to DB using (JITContext db = new JITContext()) { user.IsEmailVerified = false; db.Users.Add(user); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = true; } #endregion SendVerificationEmail(user.Email, user.ActivationCode.ToString()); message = "Registration succsessfully done. Account activation link" + "has been sent to your email: " + user.Email; status = true; } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = status; return(View(user)); }