public ActionResult ResetPassword(ResetPasswordModel model) { var message = ""; if (ModelState.IsValid) { using (CYBInfrastrctureContext db = new CYBInfrastrctureContext()) { var user = db.UserAccounts.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault(); if (user != null) { //user.Password = Crypto.Hash(model.NewPassword); user.Password = model.NewPassword; user.ResetPasswordCode = ""; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); message = "New password updated successfully"; } } } else { message = "Something invalid"; } ViewBag.Message = message; return(View(model)); }
public ActionResult ForgotPassword(string Email) { //Verify Email ID //Generate Reset password link //send Email string message = ""; //bool status = false; using (CYBInfrastrctureContext db = new CYBInfrastrctureContext()) { var account = db.UserAccounts.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; //this line i have added here to avoid confirm password not match issue, as db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); message = "password link has been sent to your email Id"; } else { message = "Account not found"; } } ViewBag.Message = message; return(View()); }
public ActionResult RoleCreate(CYBInfracstructure.DataStructure.Entities.Role role) { if (ModelState.IsValid) { bool RoleCreate = db.Roles.Any(x => x.RoleName == role.RoleName && x.RoleId == role.RoleId); if (RoleCreate == true) { ModelState.AddModelError("RoleName", "RoleName already exists, Try another one"); return(View(role)); } //if (Roles.RoleExists(role.RoleName)) //{ // ModelState.AddModelError("Error", "Rolename already exists"); // return View(role); //} else { //Roles.CreateRole(role.RoleName); db.Roles.Add(role); db.SaveChanges(); TempData["Success"] = "Registered Successfully"; return(RedirectToAction("RoleCreate", "Account")); } } else { ModelState.AddModelError("Error", "Please enter Username and Password"); { return(View(role)); } } }
public void SaveChanges() { context.SaveChanges(); }
public ActionResult Register([Bind(Include = "UserID,StaffID,StaffName,LastName,Email,Password,ConfirmPassword,ResetPassword,")] UserAccountModel user) { using (CYBInfrastrctureContext db = new CYBInfrastrctureContext()) { var checkexistance = (from reg in db.UserAccounts where reg.StaffID == user.StaffID select reg); if (checkexistance.Count() > 0) { ModelState.AddModelError("StaffID", "StaffID already exists, Try another one"); return(View()); } var checkexistance1 = (from reg in db.UserAccounts where reg.Email == user.Email select reg); if (checkexistance1.Count() > 0) { ModelState.AddModelError("Email", "Email already exists, Try another one"); return(View()); } if (!string.IsNullOrEmpty(user.Email)) { string emailRegex = @"^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$"; Regex re = new Regex(emailRegex); if (!re.IsMatch(user.Email)) { ModelState.AddModelError("Email", "Please Enter Correct Email Address"); return(View()); } else { var dpt = new UserAccount { UserID = user.UserID, StaffID = user.StaffID, StaffName = user.StaffName, Email = user.Email, Password = user.Password, ConfirmPassword = user.ConfirmPassword, ResetPasswordCode = user.ResetPasswordCode, //ActivationCode = user.ActivationCode }; db.UserAccounts.Add(dpt); db.SaveChanges(); TempData["Success"] = "Registered Successfully"; return(RedirectToAction("Index", "Admin", new { area = "Profile" })); } } //bool Register = db.UserAccounts.Any(x => x.StaffID == user.StaffID && x.UserID == user.UserID); //if (Register == true) //{ // ModelState.AddModelError("StaffID", "StaffID already exists, Try another one"); // return View(); //} //bool Register3 = db.UserAccounts.Any(x => x.Email == user.Email && x.UserID == user.UserID); //if (Register3 == true) //{ // ModelState.AddModelError("Email", "Email already exists, Try another one"); // return View(); //} else { var dpt = new UserAccount { UserID = user.UserID, StaffID = user.StaffID, StaffName = user.StaffName, Email = user.Email, Password = user.Password, ConfirmPassword = user.ConfirmPassword, ResetPasswordCode = user.ResetPasswordCode, //ActivationCode = user.ActivationCode }; db.UserAccounts.Add(dpt); db.SaveChanges(); TempData["Success"] = "Registered Successfully"; return(RedirectToAction("Login", "Account", new { area = "Profile" })); } } return(View(user)); }