public ActionResult ForgotPassword(string Email) { bool status = false; using (ParentsRegEntities parentsReg = new ParentsRegEntities()) { var account = parentsReg.ParentsLogins.Where(a => a.Email == Email).FirstOrDefault(); if (account != null) { //Send email for reset password string resetCode = Guid.NewGuid().ToString(); SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword"); account.ResetPasswordCode = resetCode; //Avoid confirm password not match issue, as we had added a confirm password property parentsReg.Configuration.ValidateOnSaveEnabled = false; parentsReg.SaveChanges(); ViewBag.Message = "Reset password link has been sent to your email id"; ModelState.Clear(); } else { ViewBag.ErrorMessage = "Sorry! account not found"; } } return(View()); }
public ActionResult Register([Bind(Exclude = "IsEmailVerified,ActivationCode")] ParentsLogin parentsLogin) { bool Status = false; string message = ""; if (ModelState.IsValid) { // Email is already Exist var isExist = IsEmailExist(parentsLogin.Email); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(parentsLogin)); } // Generate Activation Code parentsLogin.ActivationCode = Guid.NewGuid(); // Password Hashing parentsLogin.Password = Crypto.Hash(parentsLogin.Password); parentsLogin.ConfirmPassword = Crypto.Hash(parentsLogin.ConfirmPassword); parentsLogin.IsEmailVerified = false; // Save to Database using (ParentsRegEntities parentsReg = new ParentsRegEntities()) { Parents parents = new Parents(); parents.Id = parentsLogin.Id; if (parents.checkId()) { parents.Id = parentsLogin.Id; parents.Registration(); parentsReg.ParentsLogins.Add(parentsLogin); parentsReg.SaveChanges(); // Send Email to User SendVerificationLinkEmail(parentsLogin.Email, parentsLogin.ActivationCode.ToString()); message = "Registration successfully done. Account activation link " + " has been sent to your email id:" + parentsLogin.Email; Status = true; } else { message = "Invalid id"; } } } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View()); }
public ActionResult VerifyAccount(string id) { bool Status = false; using (ParentsRegEntities parentsReg = new ParentsRegEntities()) { parentsReg.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid // Confirm password does not match issue on save changes var v = parentsReg.ParentsLogins.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; parentsReg.SaveChanges(); Status = true; } else { ViewBag.Message = "Invalid Request"; } } ViewBag.Status = Status; return(View()); }
public ActionResult ResetPassword(ResetPassword reset) { if (ModelState.IsValid) { using (ParentsRegEntities parentsReg = new ParentsRegEntities()) { var user = parentsReg.ParentsLogins.Where(a => a.ResetPasswordCode == reset.ResetCode).FirstOrDefault(); if (user != null) { user.Password = Crypto.Hash(reset.NewPassword); user.ResetPasswordCode = ""; parentsReg.Configuration.ValidateOnSaveEnabled = false; parentsReg.SaveChanges(); ViewBag.message = "New password updated successfully"; } } ModelState.Clear(); } else { ViewBag.Errormessage = "Something invalid!"; } return(View(reset)); }