public ActionResult ForgetPassword(string id) { //Verify Email ID //Generate Reset password link //Send Email string message = ""; bool status = false; var account = DB.Users.Where(a => a.Email == id).FirstOrDefault(); if (account != null) { //Send email for reset password Guid resetCode = Guid.NewGuid(); //RegisterHelperFunc.OldURL = Request.Url.PathAndQuery; /*LogInOut_ForgPass_Func HelperFunc = new LogInOut_ForgPass_Func(); * User returneUser = HelperFunc.UserExists(id); * returneUser.navigateToLink = false; * DB.Users.Attach(returneUser); * var entry = DB.Entry(returneUser); * entry.Property(e => e.navigateToLink).IsModified = true; * // other changed properties * DB.SaveChanges();*/ RegisterHelperFunc.sendverification(account.Email, resetCode.ToString(), "Forget_Password/ResetPassword"); account.ResetPasswordCode = resetCode; account.ResetPasswordDate = DateTime.Now; account.navigateToLink = false; //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property //in our model class in part 1 DB.Configuration.ValidateOnSaveEnabled = false; DB.SaveChanges(); message = "Reset password link has been sent to your email id."; } else { message = "Account not found"; } ViewBag.Message = message; //return RedirectToAction("Login", "LoginAndLogout"); return(View()); }
public ActionResult Register([Bind(Exclude = "Admin,State,IsEmailVerified,ActivationCode")] User user) { bool Status = false; string message = ""; // //model validation if (ModelState.IsValid) { #region //email already exists //User exist = RegisterHelperFunc.UserExists(user.Email); User emailExist = DB.Users.Where(x => x.Email == user.Email).FirstOrDefault(); User usernameExist = RegisterHelperFunc.UsernameExists(user.UserName); if (emailExist != null && usernameExist != null) { ViewBag.validate = "Username and Email already exist"; return(View(user)); } else if (emailExist != null) { ViewBag.validate = "Email already exist"; ModelState.AddModelError("Email Exists", "Email already exists"); return(View(user)); } else if (usernameExist != null) { ViewBag.validate = "Username already exist"; return(View(user)); } #endregion #region Generate Activation code user.ActivationCode = Guid.NewGuid(); #endregion #region password hashing user.Password = LogInOut_ForgPass_Func.GenerateSHA256String(user.Password); //user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); #endregion #region answer hashing user.QuestionAnswer = LogInOut_ForgPass_Func.GenerateSHA256String(user.QuestionAnswer); #endregion user.IsEmailVerified = false; user.CaptchaCounter = 0; user.navigateToLink = false; #region save to database // using (DBentities db = new DBentities()) //{ // user.State = "active"; /// string ques = Request.Params[6].ToString(); // user.Question = (from q in db.Questions // where q.QTextEnglish == ques // select q).FirstOrDefault(); user.Admin = false; user.State = "Active"; DB.Users.Add(user); DB.SaveChanges(); //send email to user RegisterHelperFunc.OldURL = Request.Url.PathAndQuery; RegisterHelperFunc.sendverification(user.Email, user.ActivationCode.ToString()); message = "successfully registered. Account activation link has been sent to email: " + user.Email; Status = true; // } #endregion } else { message = "Invalid Request"; } //generate activation code //password hashing //save data to database ViewBag.Message = message; ViewBag.Status = Status; ViewBag.questions = DB.Questions.ToList(); return(View(user)); //return Content("ok"); }