/// <summary> /// 判断用户是否登陆 /// </summary> /// <returns></returns> protected bool IsLogin() { if (Session[SessionKey.Admin_User_Info] != null) { return(true); } else { //检查COOKIE int uid = TypeHelper.ObjectToInt(WebHelper.GetCookie(CookieKey.Login_UserID)); string upwd = WebHelper.GetCookie(CookieKey.Login_UserPassword); if (uid != 0 && !string.IsNullOrWhiteSpace(upwd)) { BaseBLL <Entity.SysUser> bll = new BaseBLL <Entity.SysUser>(); List <FilterSearch> filters = new List <FilterSearch>(); filters.Add(new FilterSearch("ID", uid.ToString(), FilterSearchContract.等于)); filters.Add(new FilterSearch("Password", upwd, FilterSearchContract.等于)); Entity.SysUser model = bll.GetModel(filters, null, "SysRole.SysRoleRoutes.SysRoute"); if (model != null) { if (model.Status) { Session[SessionKey.Admin_User_Info] = model; return(true); } return(false); } return(false); } return(false); } }
public ActionResult Login(Models.ViewModelLogin viewModelLogin) { //登陆错误次数限制 if (Session[SessionKey.Login_Fail_Total] != null) { if (TypeHelper.ObjectToInt(Session[SessionKey.Login_Fail_Total]) > 3) { ModelState.AddModelError("user_name", "失败次数过多,重启浏览器后再试"); return(View(viewModelLogin)); } } if (ModelState.IsValid) { string passworld = SecureHelper.MD5(viewModelLogin.password); BLL.BaseBLL <Entity.SysUser> bll = new BLL.BaseBLL <Entity.SysUser>(); List <BLL.FilterSearch> filters = new List <BLL.FilterSearch>(); filters.Add(new BLL.FilterSearch("UserName", viewModelLogin.user_name, BLL.FilterSearchContract.等于)); filters.Add(new BLL.FilterSearch("Password", passworld, BLL.FilterSearchContract.等于)); Entity.SysUser model = bll.GetModel(filters, null, "SysRole.SysRoleRoutes.SysRoute"); if (model == null) { ModelState.AddModelError("user_name", "用户名或密码错误"); return(View(viewModelLogin)); } if (!model.Status) { ModelState.AddModelError("user_name", "用户已被禁用"); return(View(viewModelLogin)); } Session[SessionKey.Admin_User_Info] = model; Session.Timeout = 60; if (viewModelLogin.is_rember) { WebHelper.SetCookie(CookieKey.Is_Remeber, "1", 14400); WebHelper.SetCookie(CookieKey.Login_UserID, model.ID.ToString(), 14400); WebHelper.SetCookie(CookieKey.Login_UserPassword, model.Password, 14400); } else { WebHelper.SetCookie(CookieKey.Login_UserID, model.ID.ToString()); WebHelper.SetCookie(CookieKey.Login_UserPassword, model.Password); } model.LastLoginTime = DateTime.Now; bll.Modify(model, new string[] { "LastLoginTime" }); AddAdminLogs(Entity.SysLogMethodType.Login, "通过后台网页登陆", model.ID); return(RedirectToAction("Index", "Home")); } return(View(viewModelLogin)); }
public ActionResult Login() { var viewModelLogin = new Models.ViewModelLogin(); if (WorkContext.UserInfo != null) { return(RedirectToAction("Index")); } //如果保存了cookie,则为用户做自动登录 if (!string.IsNullOrWhiteSpace(WebHelper.GetCookie(CookieKey.Is_Remeber))) { if (WebHelper.GetCookie(CookieKey.Is_Remeber) == "1") { int uid = TypeHelper.ObjectToInt(WebHelper.GetCookie(CookieKey.Login_UserID)); string upwd = WebHelper.GetCookie(CookieKey.Login_UserPassword); BLL.BaseBLL <Entity.SysUser> bll = new BLL.BaseBLL <Entity.SysUser>(); List <BLL.FilterSearch> filters = new List <BLL.FilterSearch>(); filters.Add(new BLL.FilterSearch("ID", uid.ToString(), BLL.FilterSearchContract.等于)); filters.Add(new BLL.FilterSearch("Password", upwd, BLL.FilterSearchContract.等于)); Entity.SysUser model = bll.GetModel(filters, null, "SysRole.SysRoleRoutes.SysRoute"); if (model != null) { if (model.Status) { AddAdminLogs(Entity.SysLogMethodType.Login, "已记住密码,做自动登录", model.ID); Session[SessionKey.Admin_User_Info] = model; Session.Timeout = 60; //一小时不操作,session就过期 model.LastLoginTime = DateTime.Now; bll.Modify(model, new string[] { "LastLoginTime" }); return(RedirectToAction("Index")); } else { return(View(viewModelLogin)); } } else { return(View(viewModelLogin)); } } else { return(View(viewModelLogin)); } } return(View(viewModelLogin)); }
public void EFDBContextTest() { var db = new EFDBContext(); //编辑用户组 //var role = db.SysRoles.Where(p => p.ID == 2).Include(s => s.SysRoleRoutes.Select(y => y.SysRoute)).FirstOrDefault(); //添加测试路由 //int[] power = { (int)DataCore.Entity.SysRouteType.add, (int)DataCore.Entity.SysRouteType.delete, (int)DataCore.Entity.SysRouteType.select }; //int[] power2 = { (int)DataCore.Entity.SysRouteType.update, (int)DataCore.Entity.SysRouteType.upload }; //var route1 = new DataCore.Entity.SysRoute() { AddTime = DateTime.Now, Desc = "测试路由", Route = "/home/index", Tag = "其他", RouteType = power }; //var route2 = new DataCore.Entity.SysRoute() { AddTime = DateTime.Now, Desc = "测试路由2", Route = "/home/test", Tag = "其他2", RouteType = power2 }; //db.SysRoutes.Add(route1); //db.SysRoutes.Add(route2); //添加组对应权限 //var roleroute = new DataCore.Entity.SysRoleRoute() { SysRoleID = role.ID, SysRoute = route1 }; //var roleroute2 = new DataCore.Entity.SysRoleRoute() { SysRoleID = role.ID, SysRoute = route2 }; //db.SysRoleRoutes.Add(roleroute); //db.SysRoleRoutes.Add(roleroute2); //添加用户 var entity = db.SysRoles.Find(2); string pwd = SecureHelper.MD5("admin"); for (int i = 0; i < 30; i++) { var user = new Entity.SysUser() { Avatar = "", Gender = Entity.UserGender.男, LastLoginTime = DateTime.Now, NickName = "编辑用户" + (i + 1).ToString(), Password = pwd, RegTime = DateTime.Now, Status = true, SysRole = entity, UserName = "******" + (i + 1).ToString() }; db.SysUsers.Add(user); } db.SaveChanges(); //var group = db.SysRoutes.GroupBy(p => p.Tag).ToList(); db.Dispose(); Assert.AreEqual(1, 1); }
public ActionResult Edit(int?id) { BLL.BaseBLL <Entity.SysUser> bll = new BLL.BaseBLL <Entity.SysUser>(); Load(); Entity.SysUser entity = new Entity.SysUser(); int num = TypeHelper.ObjectToInt(id, 0); if (num != 0) { entity = bll.GetModel(p => p.ID == num, null); if (entity == null) { return(PromptView("/admin/SysUser", "404", "Not Found", "信息不存在或已被删除", 5)); } } return(View(entity)); }
/// <summary> /// 获取登陆用户的信息 /// </summary> /// <returns></returns> protected Entity.SysUser GetUserInfo() { if (IsLogin()) { Entity.SysUser model = Session[SessionKey.Admin_User_Info] as Entity.SysUser; if (model != null) { if (model.Status) { return(model); } else { return(null); } } return(null); } return(null); }
protected override void Seed(Universal.DataCore.EFDBContext context) { var role_list = new List <Entity.SysRole>() { new Entity.SysRole() { AddTime = DateTime.Now, RoleName = "管理员", RoleDesc = "管理员组", IsAdmin = true }, new Entity.SysRole() { AddTime = DateTime.Now, RoleName = "编辑用户", RoleDesc = "编辑用户组", IsAdmin = false } }; role_list.ForEach(p => context.SysRoles.AddOrUpdate(x => x.RoleName, p)); context.SaveChanges(); var role_root = context.SysRoles.Where(p => p.RoleName == "管理员").FirstOrDefault(); string pwd = SecureHelper.MD5("admin"); var user_root = new Entity.SysUser() { LastLoginTime = DateTime.Now, RegTime = DateTime.Now, NickName = "超级管理员", Password = pwd, Status = true, SysRole = role_root, UserName = "******", Gender = Entity.UserGender.男, Avatar = "" }; context.SysUsers.AddOrUpdate(p => p.UserName, user_root); var category_a = new Entity.CusCategory(); category_a.PID = null; category_a.Title = "国内"; context.CusCategorys.Add(category_a); var category_b = new Entity.CusCategory(); category_b.PID = null; category_b.Title = "世界"; context.CusCategorys.Add(category_b); var category_1 = new Entity.CusCategory(); category_1.PCategory = category_a; category_1.Title = "社会"; category_1.Depth = 2; context.CusCategorys.Add(category_1); var category_2 = new Entity.CusCategory(); category_2.PCategory = category_a; category_2.Title = "经济"; category_2.Depth = 2; context.CusCategorys.Add(category_2); var category_3 = new Entity.CusCategory(); category_3.PCategory = category_a; category_3.Title = "文化"; category_3.Depth = 2; context.CusCategorys.Add(category_3); var category_4 = new Entity.CusCategory(); category_4.PCategory = category_b; category_4.Title = "格局"; category_4.Depth = 2; context.CusCategorys.Add(category_4); var category_5 = new Entity.CusCategory(); category_5.PCategory = category_b; category_5.Title = "要闻"; category_5.Depth = 2; context.CusCategorys.Add(category_5); var category_6 = new Entity.CusCategory(); category_6.PCategory = category_b; category_6.Title = "趋势"; category_6.Depth = 2; context.CusCategorys.Add(category_6); context.SaveChanges(); }
public ActionResult Edit(Entity.SysUser entity) { var isAdd = entity.ID == 0 ? true : false; BLL.BaseBLL <Entity.SysUser> bll = new BLL.BaseBLL <Entity.SysUser>(); Load(); if (entity.SysRoleID == 0) { ModelState.AddModelError("SysRoleID", "请选择用户组"); } //数据验证 if (isAdd) { //判断用户名是否存在 if (!bll.Exists(p => p.UserName == entity.UserName)) { ModelState.AddModelError("UserName", "该用户名已存在"); } } else { //如果要编辑的用户不存在 if (!bll.Exists(p => p.ID == entity.ID)) { return(PromptView("/admin/SysUser", "404", "Not Found", "信息不存在或已被删除", 5)); } ModelState.Remove("UserName"); } if (ModelState.IsValid) { //添加 if (entity.ID == 0) { entity.RegTime = DateTime.Now; entity.Password = SecureHelper.MD5(entity.Password); entity.LastLoginTime = DateTime.Now; bll.Add(entity); } else //修改 { var user = bll.GetModel(p => p.ID == entity.ID, null); if (entity.Password != "litdev") { user.Password = SecureHelper.MD5(entity.Password); } user.NickName = entity.NickName; user.Gender = entity.Gender; user.Status = entity.Status; user.Avatar = entity.Avatar; user.SysRoleID = entity.SysRoleID; bll.Modify(user); } return(PromptView("/admin/SysUser", "OK", "Success", "操作成功", 5)); } else { return(View(entity)); } }