public ActionResult ResetPassword(string email = "", string code = "", string newpassword = "", string retypePassword = "") { ViewBag.Email = email; ViewBag.code = code; if (UserAccountBLL.GetCode(email, UserAccountTypes.Employee) != code) { ViewBag.Eror = "Eror"; return(View()); } if (newpassword != "") { if (newpassword != retypePassword) { ModelState.AddModelError("", "Password incorrect"); return(View()); } else { Account account = new Account(); account.Email = email; account.Password = newpassword; UserAccountBLL.Account_Update(account, UserAccountTypes.Employee); UserAccountBLL.SetCode(email, Guid.NewGuid().ToString(), UserAccountTypes.Employee); return(RedirectToAction("Login", "Account")); } } return(View()); }
public ActionResult ChangePwd(Account account, String oldPassword, String reNewPassword) { if (Request.HttpMethod == "GET") { return(View()); } else { try { WebUserData userData = User.GetUserData(); account.Email = userData.UserID; Account oldAccount = new Account(); oldAccount.Email = account.Email; oldAccount.Password = oldPassword; if (UserAccountBLL.Account_Get(oldAccount, UserAccountTypes.Employee)) { if (account.Password == reNewPassword) { UserAccountBLL.Account_Update(account, UserAccountTypes.Employee); return(RedirectToAction("Index", "DashBoard")); } ModelState.AddModelError("reNewPass", "Password incorrect,please try again"); return(View()); } else { ModelState.AddModelError("", "Wrong password"); return(View()); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message + ": " + ex.StackTrace); return(View()); } } }
public ActionResult Edit(Employee model, HttpPostedFileBase uploadPhoto) { if (string.IsNullOrEmpty(model.Notes)) { model.Notes = ""; } WebUserData userData = User.GetUserData(); model.EmployeeID = Convert.ToInt32(userData.UserID); string emailCookie = userData.Email; if (!HumanResourceBLL.Employee_CheckEmail(model.EmployeeID, model.Email, "update") && (model.Email != emailCookie)) { ModelState.AddModelError("Email", "Email ready exist"); } //Upload ảnh if (uploadPhoto != null && uploadPhoto.ContentLength > 0) { string filePath = Path.Combine(Server.MapPath("~/Images"), uploadPhoto.FileName); uploadPhoto.SaveAs(filePath); model.PhotoPath = "/Images/" + uploadPhoto.FileName; } else if (model.PhotoPath == null) { model.PhotoPath = userData.Photo; } DateTime hireDate = DateTime.Today; if ((hireDate.Year - (model.BirthDate).Year) < 18) { ModelState.AddModelError("BirthDate", "You must be over 18 years old"); } //Kiểm tra có tồn tại bất kỳ lỗi nào hay không if (!ModelState.IsValid) { return(View(model)); } try { WebUserData userDatas = User.GetUserData(); string role = userDatas.GroupName; bool rs = UserAccountBLL.Account_Update(model); if ((model.Email != userData.Email) || (model.PhotoPath != userData.Photo)) { // WebUserData cookieData = new WebUserData() { UserID = model.EmployeeID.ToString(), FullName = model.LastName + " " + model.FirstName, GroupName = role, SessionID = Session.SessionID, ClientIP = Request.UserHostAddress, Photo = model.PhotoPath, Email = model.Email }; FormsAuthentication.SetAuthCookie(cookieData.ToCookieString(), false); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError("", e.Message + ":" + e.StackTrace); return(View(model)); } }