public bool updateUser(user entity) { try { var u = db.users.Where(x => x.username == entity.username).FirstOrDefault(); MaHoaSHA1 sha1 = new MaHoaSHA1(); if (!String.IsNullOrEmpty(entity.password)) { u.password = sha1.EncodeSHA1(entity.password); } u.fullName = entity.fullName.ToUpper(); u.chinhanh = entity.chinhanh; u.dirPathName = entity.dirPathName; u.doimk = entity.doimk; u.phongban = entity.phongban; u.trangthai = entity.trangthai; u.upload = entity.upload; u.show = entity.show; u.adminkd = entity.adminkd; u.adminkl = entity.adminkl; u.role = entity.role; u.email = entity.email; db.Entry(u).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } catch (Exception ex) { throw ex; // return false; } }
public ActionResult Create(Users entity) { if (ModelState.IsValid) { entity.Password = sha1.EncodeSHA1(entity.Password); entity.Hoten = entity.Hoten.ToUpper(); var result = _userRepository.Create(entity); int n = _userRepository.createUsers_qltaikhoan(entity.Username, entity.Hoten.ToUpper(), entity.Password, entity.Maphong, entity.chinhanh); if (result != null) { SetAlert("Tạo user thành công", "success"); } else { SetAlert("Tạo user không thành công", "error"); } } return(Redirect(HttpContext.Session.GetString("urlNhanvien"))); }
public int doimatkhau(string username, string password, string newpassword, string confirmpassword, string phongban) { MaHoaSHA1 sha1 = new MaHoaSHA1(); if (String.IsNullOrEmpty(password)) { return(-1); } if (Session["oldpassword"].ToString() != sha1.EncodeSHA1(password)) { return(-2); } if (String.IsNullOrEmpty(newpassword)) { return(-3); } if (String.IsNullOrEmpty(confirmpassword)) { return(-4); } if (newpassword != confirmpassword) { return(-5); } else { var result = db.Database.ExecuteSqlCommand("spDoimatkhau @username, @password, @phongban", new SqlParameter[] { new SqlParameter("@username", username), new SqlParameter("@password", sha1.EncodeSHA1(newpassword)), new SqlParameter("@phongban", phongban) }); if (result == 0) { return(0); } else { return(1); } } }
public ActionResult Index(LoginViewModel model) { if (ModelState.IsValid) { LoginModel result = _loginRepository.login(model.Username, model.Password, "011"); if (result == null) { ModelState.AddModelError("", "Tài khoản này không tồn tại"); } else { if (!result.trangthai) { ModelState.AddModelError("", "Tài khoản này không đã bị khoá"); } string modelPass = sha1.EncodeSHA1(model.Password); if (result.Password != modelPass) { ModelState.AddModelError("", "Mật khẩu không đúng"); } else { var user = _userRepository.GetById(result.Username);//.FirstOrDefault(); HttpContext.Session.SetString("username", result.Username); HttpContext.Session.SetString("password", model.Password); HttpContext.Session.SetString("hoten", result.hoten); HttpContext.Session.SetString("chinhanh", user.chinhanh); HttpContext.Session.SetString("maviettat", user.maviettat); HttpContext.Session.SetString("mausohd", model.mausohd); HttpContext.Session.SetString("kyhieuhd", model.kyhieuhd); HttpContext.Session.SetString("accounthddt", user.accounthddt); HttpContext.Session.SetString("passhddt", user.passwordhddt); HttpContext.Session.SetString("admin", user.isAdmin.ToString()); return(RedirectToAction("Index", "Home")); } } } return(View()); }
public string insertUser(user entity) { try { MaHoaSHA1 sha1 = new MaHoaSHA1(); entity.password = !string.IsNullOrEmpty(entity.password) ? sha1.EncodeSHA1(entity.password) : sha1.EncodeSHA1("123"); db.Entry(entity).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); return(entity.username); } catch (Exception ex) { throw ex; //return string.Empty ; } }
public int login(string username, string password, string phongban) { MaHoaSHA1 sha1 = new MaHoaSHA1(); var result = db.Database.SqlQuery <user>("spLogin @username, @password, @phongban", new SqlParameter[] { new SqlParameter("@username", username), new SqlParameter("@password", sha1.EncodeSHA1(password)), new SqlParameter("@phongban", phongban) }).FirstOrDefault(); if (result == null) { return(0); } else { return(1); } }
public IActionResult Create(Users entity) { if (ModelState.IsValid) { entity.password = sha1.EncodeSHA1(entity.password); entity.accounthddt = string.IsNullOrEmpty(entity.accounthddt) ? "" : entity.accounthddt; entity.passwordhddt = string.IsNullOrEmpty(entity.passwordhddt) ? "" : entity.passwordhddt; entity.nguoitao = HttpContext.Session.GetString("username"); entity.ngaytao = System.DateTime.Now; entity.logfile = "* User tạo nhân viên: " + HttpContext.Session.GetString("username"); var result = _userRepository.Create(entity); int n = _userRepository.createUsers_qltaikhoan(entity.username, entity.hoten, entity.password, entity.chinhanh); if (result != null) { SetAlert("Tạo nhân viên thành công.", "success"); return(Redirect(HttpContext.Session.GetString("urlUsers"))); } else { SetAlert("Tạo nhân viên không thành công.", "error"); } } return(View()); }
public ActionResult Index(LoginModel model) { if (ModelState.IsValid) { var result = _loginRepository.login(model.Username, model.Password, "001"); if (result == null) { ModelState.AddModelError("", "Tài khoản này không tồn tại"); } else { if (!result.Trangthai) { ModelState.AddModelError("", "Tài khoản này đã bị khóa"); } string modelPass = sha1.EncodeSHA1(model.Password); if (result.Password != modelPass) { ModelState.AddModelError("", "Mật khẩu không đúng"); } if (result.Password == modelPass) { var user = _userRepository.GetById(model.Username); HttpContext.Session.SetString("username", model.Username); HttpContext.Session.SetString("password", model.Password); HttpContext.Session.SetString("hoten", result.Hoten); HttpContext.Session.SetString("phong", result.Maphong); HttpContext.Session.SetString("chinhanh", user.chinhanh); HttpContext.Session.SetString("dienthoai", String.IsNullOrEmpty(result.Dienthoai)?"":result.Dienthoai); HttpContext.Session.SetString("macode", result.Macode); HttpContext.Session.SetString("roleId", string.IsNullOrEmpty(result.RoleId)?"":result.RoleId); HttpContext.Session.SetString("Newtour", user.Newtour.ToString()); HttpContext.Session.SetString("Dongtour", user.Dongtour.ToString()); HttpContext.Session.SetString("Danhmuc", user.Catalogue.ToString()); HttpContext.Session.SetString("Booking", user.Booking.ToString()); HttpContext.Session.SetString("Report", user.Report.ToString()); HttpContext.Session.SetString("Showprice", user.Showprice.ToString()); HttpContext.Session.SetString("Print", user.Print.ToString()); HttpContext.Session.SetString("Doixe", user.Doixe.ToString()); HttpContext.Session.SetString("Maybay", user.Maybay.ToString()); HttpContext.Session.SetString("Huongdan", user.Huongdan.ToString()); HttpContext.Session.SetString("Sales", user.Sales.ToString()); HttpContext.Session.SetString("Vetq", user.Vetq.ToString()); HttpContext.Session.SetString("Admin", user.Admin.ToString()); HttpContext.Session.SetString("khachle", user.khachle.ToString()); HttpContext.Session.SetString("khachdoan", user.khachdoan.ToString()); if (!string.IsNullOrEmpty(user.Email)) { HttpContext.Session.SetString("Email", user.Email.ToString()); } DateTime ngaydoimk = Convert.ToDateTime(result.Ngaydoimk); int kq = (DateTime.Now.Month - ngaydoimk.Month) + 12 * (DateTime.Now.Year - ngaydoimk.Year); if (kq >= 3) { return(View("changepass")); } else if (result.Doimk) { return(View("changepass")); } else { return(RedirectToAction("Index", "Tour")); } } } } return(View()); }