public ActionResult UploadHeadPic(int id) { JsonModel jm = new JsonModel(); //获取要上传头像的总公司用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //用户存在 if (companyUser != null) { LoggedInAccountModel userModel = new LoggedInAccountModel() { UserId = companyUser.Id, HeadPath = companyUser.HeadPath }; return(View(userModel)); } //用户不存在 else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult EditUserPwd(AccountPasswordChangeModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { //获取要修改密码的用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { companyUser.Password = PropertyUtils.GetMD5Str(model.Password); // 保存到数据库 companyUserBll.Update(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult AddCompanyUser(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser propertyUser = new T_CompanyUser() { UserName = model.UserName, TrueName = model.TrueName, Password = PropertyUtils.GetMD5Str(model.Password), Memo = model.Memo, Tel = model.Tel, Phone = model.Phone, Email = model.Email, CompanyId = GetSessionModel().CompanyId.Value }; // 保存到数据库 companyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult CompanyPlatformLogin(AccountModel model) { //判断提交模型数据是否正确 if (!ModelState.IsValid) { return(View(model)); } string code = (string)Session["ValidateCode"]; if (model.CheckCode != code) { ModelState.AddModelError("CheckCode", "验证码不正确"); return(View(model)); } //根据用户名查找用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser user = companyUserBll.GetEntity(u => u.UserName == model.UserName.Trim() && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //1.判断用户名是否正确 if (user == null) { ModelState.AddModelError("UserName", "用户名不存在"); return(View(model)); } //2.判断密码是否正确 string md5Str = PropertyUtils.GetMD5Str(model.Password); if (user.Password != md5Str) { ModelState.AddModelError("Password", "密码不正确"); return(View(model)); } //3.如果未设置角色 if (user.CompanyUserRoles.Count == 0) { ModelState.AddModelError("UserName", "该用户未设置角色,请联系管理员"); return(View(model)); } //4.获取用户对象信息(权限菜单,Action等)保存基本信息到session中 this.SetUserSessiong(user, companyUserBll); //5.判断是否拥有访问首页的权限 UserSessionModel session = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; if (session.IsMgr == ConstantParam.USER_ROLE_DEFAULT && !session.ActionDic.ContainsKey("/CompanyPlatform/Index")) { ModelState.AddModelError("UserName", "该用户无访问权限,请联系管理员"); return(View(model)); } BreadCrumb.ClearState(); //5.跳转到 return(RedirectToAction("Index", "CompanyPlatform")); }
public ActionResult UploadHeadPic(string data, int userId) { JsonModel jm = new JsonModel(); //保存头像文件 string directory = Server.MapPath(ConstantParam.COMPANY_USER_HEAD_DIR); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } var fileName = DateTime.Now.ToFileTime().ToString() + ".jpg"; var path = Path.Combine(directory, fileName); using (FileStream fs = new FileStream(path, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] datas = Convert.FromBase64String(data); bw.Write(datas); bw.Close(); } } //获取要上传头像的总公司用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == userId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //用户存在 if (companyUser != null) { string oldFile = companyUser.HeadPath; companyUser.HeadPath = ConstantParam.COMPANY_USER_HEAD_DIR + fileName; companyUserBll.Update(companyUser); //更新SessionModel中的最新个人信息 UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; sessionModel.HeadPath = ConstantParam.COMPANY_USER_HEAD_DIR + fileName; //删除旧头像 if (!string.IsNullOrEmpty(oldFile)) { oldFile = Server.MapPath(oldFile); FileInfo f = new FileInfo(oldFile); if (f.Exists) { f.Delete(); } } } //用户不存在 else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public JsonResult SetCompanyAdministrator(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL propertyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = new T_CompanyUser() { CompanyId = model.CompanyId, UserName = model.UserName, Email = model.Email, Password = PropertyUtils.GetMD5Str(model.Password), IsMgr = ConstantParam.USER_ROLE_MGR, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, }; //为管理员添加角色 ICompanyRoleBLL roleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); var role = roleBll.GetEntity(r => r.IsSystem == ConstantParam.USER_ROLE_MGR && r.CompanyId == model.CompanyId); if (role != null) { companyUser.CompanyUserRoles.Add(new R_CompanyUserRole() { RoleId = role.Id, }); } //创建管理员 propertyUserBll.Save(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult SetUserInfo(LoggedInAccountModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { //获取要编辑个人信息的总公司用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { companyUser.TrueName = model.TrueName; companyUser.Phone = model.Phone; companyUser.Email = model.Email; companyUser.Memo = model.Memo; // 保存到数据库 companyUserBll.Update(companyUser); //更新SessionModel中的最新个人信息 UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; sessionModel.TrueName = model.TrueName; //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult EditUserPwd() { UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; var id = sessionModel.UserID; //获取要修改密码的总公司用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { AccountPasswordChangeModel model = new AccountPasswordChangeModel(); model.UserId = companyUser.Id; model.UserName = companyUser.UserName; return(View(model)); } else { return(RedirectToAction("Index", "CompanyPlatform")); } }
public ActionResult EditCompanyUser(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == model.CompanyUserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { companyUser.UserName = model.UserName; companyUser.TrueName = model.TrueName; companyUser.Memo = model.Memo; companyUser.Tel = model.Tel; companyUser.Phone = model.Phone; companyUser.Email = model.Email; // 保存到数据库 companyUserBll.Update(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ConfigRole(CompanyUserConfigRoleModel model) { JsonModel jm = new JsonModel(); ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); //获取要分配角色的物业总公司用户 T_CompanyUser user = companyUserBll.GetEntity(m => m.Id == model.userId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); // 新建物业总公司用户角色关联表 List <R_CompanyUserRole> roles = new List <R_CompanyUserRole>(); if (model.ids != null) { //没有设置任何角色 则不执行循环操作 foreach (var id in model.ids) { R_CompanyUserRole item = new R_CompanyUserRole() { UserId = model.userId, RoleId = id }; roles.Add(item); } } //修改物业用户对应的角色集合 if (companyUserBll.ConfigRole(user, roles)) { jm.Content = "物业用户 " + user.TrueName + " 分配角色"; } else { jm.Msg = "分配角色失败"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ConfigRole(int id) { // 创建物业总公司用户角色模型 CompanyUserRoleModel companyUserRoleModel = new CompanyUserRoleModel(); // 获取指定id的物业总公司用户模型 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); companyUserRoleModel.User = new CompanyUserModel() { CompanyUserId = companyUser.Id, UserName = companyUser.UserName, TrueName = companyUser.TrueName, Tel = companyUser.Tel, Phone = companyUser.Phone, Memo = companyUser.Memo, Email = companyUser.Email }; // 获取本总公司中所有的角色 ICompanyRoleBLL companyRoleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); //排序 var sortModel = this.SettingSorting("Id", false); var roleList = companyRoleBll.GetList(p => p.CompanyId == companyUser.CompanyId && p.IsSystem == ConstantParam.USER_ROLE_DEFAULT, sortModel.SortName, sortModel.IsAsc).ToList(); companyUserRoleModel.RoleList = roleList; //获取该总公司用户已分配的角色id的集合 companyUserRoleModel.RoleIds = companyUser.CompanyUserRoles.Select(m => m.RoleId).ToList(); return(View(companyUserRoleModel)); }
/// <summary> /// 保存总公司用户的session信息 /// </summary> /// <param name="user"></param> private void SetUserSessiong(T_CompanyUser user, ICompanyUserBLL bll) { //用户session模型 UserSessionModel sessionInfo = new UserSessionModel(); //设置基本信息 sessionInfo.UserID = user.Id; sessionInfo.UserName = user.UserName; sessionInfo.TrueName = user.TrueName; sessionInfo.IsMgr = user.IsMgr; sessionInfo.UserType = ConstantParam.USER_TYPE_COMPANY; sessionInfo.CompanyId = user.CompanyId; sessionInfo.HeadPath = user.HeadPath; //构造菜单业务对象 IMenuBLL menuBll = BLLFactory <IMenuBLL> .GetBLL("MenuBLL"); #region 设置总公司用户菜单以及权限 //管理员 if (user.IsMgr == ConstantParam.USER_ROLE_MGR) { //获取菜单 var list = menuBll.GetList(m => m.MenuFlag == ConstantParam.MENU_LEFT && m.IsPlatform == ConstantParam.USER_TYPE_COMPANY).Select(m => new MenuModel { MenuId = m.Id, MenuName = m.MenuName, MenuCode = m.MenuCode, MenuUrl = m.Href, MenuFlag = m.MenuFlag, MenuCss = m.IconClass, ParentId = m.ParentId, Order = m.Order, IsPlatform = m.IsPlatform }).ToList(); //设置左边菜单 sessionInfo.MenuList = list; } else { //获取总公司用户对应的角色权限表 var roleActions = user.CompanyUserRoles.Select(ur => ur.CompanyRole.CompanyRoleActions); //菜单字典 Dictionary <string, MenuModel> menuDic = new Dictionary <string, MenuModel>(); //权限字典 Dictionary <string, string> actionDic = new Dictionary <string, string>(); foreach (var item in roleActions) { var actions = item.Select(obj => obj.Action); foreach (var action in actions) { //添加权限 if (!actionDic.ContainsKey(action.Href)) { actionDic.Add(action.Href, action.ActionName); } foreach (var li in action.ActionItems) { //添加权限 if (!actionDic.ContainsKey(li.Href)) { actionDic.Add(li.Href, li.ItemName); } } var menu = action.Menu; if (menu.ParentId != null) { if (!menuDic.ContainsKey(menu.ParentMenu.MenuCode)) { menuDic.Add(menu.ParentMenu.MenuCode, GetMenuModel(menu.ParentMenu)); } } if (!menuDic.ContainsKey(menu.MenuCode)) { menuDic.Add(menu.MenuCode, GetMenuModel(menu)); } } } //设置菜单和权限 sessionInfo.MenuList.AddRange(menuDic.Values.ToList()); sessionInfo.ActionDic = actionDic; } #endregion //设置session信息 Session[ConstantParam.SESSION_USERINFO] = sessionInfo; }