public ActionResult EditRole(RoleEditModel model) { if (model.FunctionIDs.Count == 0) { ModelState.AddModelError("FunctionIDs", Asiatek.Resource.DataAnnotations.RoleMustHaveOneFunction); } if (ModelState.IsValid) { var result = RoleBLL.ModifyRoleInfo(model, base.UserIDForLog); base.DoLog(Model.OperationTypeEnum.Edit, result, "RoleID:" + model.ID); return(Json(result)); } else { if (IsSuperAdmin) { model.FunctionTreeNodes = FunctionBLL.GetAllFunctionsForTree(); } else { model.FunctionTreeNodes = FunctionBLL.GetNormalFunctionsForTree(); } model.FunctionTreeNodes.ForEach(node => { if (model.FunctionIDs.Contains(node.ID)) { node.Checked = true; } }); return(PartialView("_EditRole", model)); } }
public ActionResult GetParentFunctionByName(string functionName) { var list = FunctionBLL.GetFunctionsByName(functionName); var query = from f in list select new { label = f.FunctionName, value = f.ID }; return(Json(query, JsonRequestBehavior.AllowGet)); }
public void FunctionAdd(HttpContext context) { int FunctionId = 0; if (!string.IsNullOrEmpty(context.Request.QueryString["FunctionId"].ToString())) { FunctionId = Convert.ToInt32(context.Request.QueryString["FunctionId"].ToString()); } string objOrder = GetParam("FunctionModel", context); Function function = JsonConvert.DeserializeObject <Function>(objOrder); FunctionBLL functionbll = new FunctionBLL(); int result = 0; //编辑 if (FunctionId > 0) { if (function.FunctionName != "") { result = functionbll.Update(function) ? 1 : 0; } } else { //添加 if (function.FunctionName != "") { result = functionbll.Add(function); } } context.Response.Write(result); }
public IHttpActionResult Get() { //申明返回对象 ExtRole model = new ExtRole(); model.ExtFuns = new List <ExtFun>(); FunctionBLL fctionBLL = new FunctionBLL(); PermissionBLL perBLL = new PermissionBLL(); List <Function> Functions = fctionBLL.GetList(p => p.ISMENU && !string.IsNullOrEmpty(p.PARENTID) && !p.ISPUBLIC && !p.ISDELETED); List <Permission> Permissions = perBLL.GetList(); foreach (Function fun in Functions) { ExtFun extFun = new ExtFun(); extFun.FunctionID = fun.FunctionID; extFun.FunctionCode = fun.FunctionCode; extFun.FunctionName = fun.FunctionName; extFun.IsMenu = fun.IsMenu; extFun.Permissions = Permissions; model.ExtFuns.Add(extFun); } //返回 return(Ok(model)); }
public ActionResult EditRole(int id) { var obj = RoleBLL.GetRoleByID(id); if (obj.DataResult == null) { return(Content(obj.Message)); } var role = obj.DataResult; if (IsSuperAdmin) { role.FunctionTreeNodes = FunctionBLL.GetAllFunctionsForTree(); } else { role.FunctionTreeNodes = FunctionBLL.GetNormalFunctionsForTree(); } role.FunctionTreeNodes.ForEach(node => { if (role.FunctionIDs.Contains(node.ID)) { node.Checked = true; } }); return(PartialView("_EditRole", role)); }
/// <summary> /// 获取左侧导航菜单 /// </summary> protected void GetLeftMenu() { try { int parentId = DNTRequest.GetInt("parentId", 0); FunctionBLL opFunctionBLL = new FunctionBLL(); Function modelFunction = new Function(); DataSet ds = opFunctionBLL.GetList("IsDeleted=0"); DataTable dt = null; if (ds != null && ds.Tables.Count > 0) { dt = ds.Tables[0]; } StringBuilder html = new StringBuilder(); List <Hashtable> list = new List <Hashtable>(); if (dt != null && dt.Rows.Count > 0) { DataRow[] allList = dt.Select(string.Format("ClassId=0 and ParentId={0}", parentId), "OrderId ASC"); if (allList.Length > 0) { foreach (DataRow dr in allList) { bool isParent = false; DataRow[] allChild = dt.Select(string.Format("ClassId=0 and ParentId={0}", dr["FunctionId"]), "OrderId ASC"); if (allChild != null && allChild.Length > 0) { isParent = true; } if (ComPage.CurrentAdmin.UserType == 1) { html.AppendFormat("<li class=\"par\">{0}</li>", dr["FunctionName"]); } else { if (userFunction.Contains(dr["FunctionId"])) { html.AppendFormat("<li class=\"par\">{0}</li>", dr["FunctionName"]); } } if (isParent) { GetLeftMenuChild(html, allChild, dt); } } } } if (string.IsNullOrEmpty(html.ToString())) { html.Append("<li>暂无权限</li>"); } litLeftMenu.Text = html.ToString(); } catch (Exception ex) { ExceptionLogBLL.WriteExceptionLogToDB(ex.ToString()); } }
public ActionResult DeleteFunction(FormCollection fc) { string[] ids = fc["funid"].Split(','); var result = FunctionBLL.DeleteFunctions(ids); base.DoLog(OperationTypeEnum.Delete, result, fc["funid"]); return(Json(result)); }
/// <summary> /// 获取左侧导航菜单 /// </summary> static public Object GetLeftMenu() { #region 开始 string result = string.Empty; try { int parentId = DNTRequest.GetInt("parentId", 0); FunctionBLL opFunctionBLL = new FunctionBLL(); Function modelFunction = new Function(); DataSet ds = opFunctionBLL.GetList("IsDeleted=0"); DataTable dt = null; if (ds != null && ds.Tables.Count > 0) { dt = ds.Tables[0]; } List <Hashtable> list = new List <Hashtable>(); if (dt != null && dt.Rows.Count > 0) { DataRow[] allList = dt.Select(string.Format("ClassId=0 and ParentId={0}", parentId), "OrderId ASC"); if (allList.Length > 0) { foreach (DataRow dr in allList) { bool isParent = false; DataRow[] allChild = dt.Select(string.Format("ClassId=0 and ParentId={0}", dr["FunctionId"]), "OrderId ASC"); if (allChild != null && allChild.Length > 0) { isParent = true; } string className = ComPage.SafeToString(dr["FunctionName"]); Hashtable ht = new Hashtable(); ht.Add("id", dr["FunctionId"]); ht.Add("name", className); ht.Add("pId", dr["ParentId"]); ht.Add("url", dr["ExternalLinkAddress"]); ht.Add("code", dr["FunctionCode"]); if (isParent) { GetLeftMenuChild(list, allChild, dt); } list.Add(ht); } } } result = DNTRequest.GetResultJson(true, "success", list); } catch (Exception ex) { result = DNTRequest.GetResultJson(false, ex.Message, null); ExceptionLogBLL.WriteExceptionLogToDB(ex.ToString()); } return(result); #endregion end 开始 }
protected void LoadRoleFunction() { FunctionBLL bll = new FunctionBLL(); List <string> list = bll.GetRole2Function(Request.QueryString["Code"].ToString()); foreach (TreeNode node in this.tvModel.Nodes) { SetCheckedNodes(node, list); } }
protected void Page_Load(object sender, EventArgs e) { LoginUserID = currentAdmin.UserID; if (Request.QueryString["FunctionId"] != null) { FunctionId = Convert.ToInt32(Request.QueryString["FunctionId"].ToString()); } if (!IsPostBack) { this.btnSave.Text = "添加功能"; FunctionBLL opFunctionBLL = new FunctionBLL(); int maxOrderId = opFunctionBLL.GetMaxOrderId(); txtOrderId.Value = maxOrderId.ToString(); if (FunctionId > 0) { DataSet ds = new DataSet(); ds = Functionbll.GetListParent(" f.FunctionId=" + FunctionId + " AND f.IsDeleted=0 "); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ParentFunctionName"].ToString() != "") { this.txtFunctionName.Value = ds.Tables[0].Rows[0]["ParentFunctionName"].ToString(); this.txtFunctionID.Value = ds.Tables[0].Rows[0]["ParentId"].ToString(); } else { this.txtFunctionName.Value = "添加根节点"; this.txtFunctionID.Value = "0"; } this.HidFunctionCode.Value = ds.Tables[0].Rows[0]["FunctionCode"].ToString(); this.txtFunctionNameChild.Value = ds.Tables[0].Rows[0]["FunctionName"].ToString(); txtExternalLinkAddress.Value = ds.Tables[0].Rows[0]["ExternalLinkAddress"].ToString(); txtOrderId.Value = ds.Tables[0].Rows[0]["OrderId"].ToString(); this.SeleFunctionType.Value = ds.Tables[0].Rows[0]["ClassId"].ToString(); this.btnSave.Text = "修改功能"; } } } } //DataSet ds = Functionbll.GetList(" IsDeleted=0"); //DataTable dt = ds.Tables[0]; //DataRow[] dr = ds.Tables[0].Select("ParentId=0"); //TreeNode node = new TreeNode(); //node.Text = dr[0]["FunctionName"].ToString(); //node.Value = dr[0]["FunctionId"].ToString(); //this.TreeView1.Nodes.Add(node); //BindTree(node, dr[0]["FunctionId"].ToString(), dt); //AddTree(0, null); }
public void DeleteFunction(HttpContext context) { var FunctionID = context.Request.QueryString["FunctionID"]; FunctionBLL bll = new FunctionBLL(); bool b = false; if (!string.IsNullOrEmpty(FunctionID)) { b = bll.UpdateDelete(Convert.ToInt32(FunctionID)); } context.Response.Write(b ? "1" : "0"); }
public void GetFunctionOne(HttpContext context) { var FunctionId = context.Request.QueryString["FunctionId"]; FunctionBLL bll = new FunctionBLL(); Function a = new Function(); if (!string.IsNullOrEmpty(FunctionId)) { a = bll.GetModel(Convert.ToInt32(FunctionId)); } context.Response.Write(SerializerHelper.SerializeObject(a)); }
public ResponseFuncDelete FuncDelete([FromBody] RequestFuncDelete request) { try { FunctionBLL bll = new FunctionBLL(); return(bll.FuncDelete(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult AddRole() { RoleAddModel model = new RoleAddModel(); if (IsSuperAdmin) { model.FunctionTreeNodes = FunctionBLL.GetAllFunctionsForTree(); } else { model.FunctionTreeNodes = FunctionBLL.GetNormalFunctionsForTree(); } return(PartialView("_AddRole", model)); }
public bool CheckedAuthorize(string functionCode) { List <Function> list = new List <Function>(); FunctionBLL bll = new FunctionBLL(); list = bll.GetFuctionDepartmentExtentList2(" f.IsDeleted=0 AND ur.UserId=" + ComPage.CurrentAdmin.UserID + ""); if (ComPage.CurrentAdmin.UserType == 1) { return(true); } else { return(list.Exists(t => t.FunctionCode == functionCode)); } }
protected void btn_Sure_Click(object sender, EventArgs e) { List <string> funcList = GetAllSelectedTreeNodes(); string roleCode = Request.QueryString["Code"].ToString(); int re = new FunctionBLL().SetRole2Function(roleCode, funcList); if (re > 0) { UtilityService.Alert(this.Page, "设置完成!"); LoadRoleFunction(); } else { UtilityService.Alert(this.Page, "设置失败!"); } }
public ActionResult EditFunctionInfo(FunctionEditModel model) { if (ModelState.IsValid) { var result = FunctionBLL.EditFunction(model, base.UserIDForLog); base.DoLog(OperationTypeEnum.Edit, result, "FunctionID:" + model.ID); return(Json(result)); } else { if (model.FunctionIsMenu) { var aList = AreaBLL.GetAreas(); model.AreasSelectList = new SelectList(aList, "ID", "AreaName"); var cList = ControllerBLL.GetControllersByAreaID(aList.First().ID); model.ControllersSelectList = new SelectList(cList, "ID", "ControllerName"); var actionList = ActionBLL.GetActionsByControllerID(cList.First().ID); model.ActionsSelectList = actionList.ToSelectList(m => GetSelectListItem(m.ID, m.ActionName)); var parentFuncList = FunctionBLL.GetFunctions(); model.ParentFunctionsSelectList = new SelectList(FunctionBLL.GetFunctions(model.ID), "ID", "FunctionName"); return(PartialView("_EditFunctionInfo", model)); } else { int areaID = model.AreaID.Value; int controllerID = model.ControllerID.Value; int?parentID = model.ParentID; int actionID = model.ActionID.Value; model.IsTopFunction = model.ParentID == null; model.AreasSelectList = new SelectList(AreaBLL.GetAreas(), "ID", "AreaName", areaID); model.ControllersSelectList = new SelectList(ControllerBLL.GetControllersByAreaID(areaID), "ID", "ControllerName", controllerID); model.ActionsSelectList = ActionBLL.GetActionsByControllerID(controllerID).ToSelectList(m => GetSelectListItem(m.ID, m.ActionName)); model.ParentFunctionsSelectList = new SelectList(FunctionBLL.GetFunctions(model.ID), "ID", "FunctionName"); return(PartialView("_EditFunctionInfo", model)); } } }
public void VerificationIsFunName(HttpContext context) { int FunctionId = 0; var FunctionName = context.Request.QueryString["FunctionName"]; if (!string.IsNullOrEmpty(context.Request.QueryString["FunctionId"])) { FunctionId = Convert.ToInt32(context.Request.QueryString["FunctionId"]); } FunctionBLL functionbll = new FunctionBLL(); if (!string.IsNullOrEmpty(FunctionName)) { FunctionId = functionbll.VerificationIsFunName(FunctionName, FunctionId); } context.Response.Write(FunctionId); }
protected void BindTreeView() { FunctionBLL bll = new FunctionBLL(); IList <Function> list = bll.GetChildFunctionList("0", false); foreach (Function model in list) { string name = model.F_Name; string code = model.F_Code.ToString(); TreeNode td = new TreeNode(name, code); td.SelectAction = TreeNodeSelectAction.None; td.Expanded = false; BindChildTree(td); tvModel.Nodes.Add(td); } }
private IList <Function> GetBindFuclist(string id) { int userType = Convert.ToInt32(Session["UserType"]); IList <Function> allChildFuc = new FunctionBLL().GetChildFunctionList(id, userType.Equals(100)); /**************测试时关闭********************/ IList <Function> bindFuc = new List <Function>(); foreach (Function f in allChildFuc) { if (userFuc != null) { if (userFuc.FirstOrDefault <Function>(X => X.F_Code == f.F_Code) != null && f.F_Type == 0) { bindFuc.Add(f); } } } return(bindFuc); //return allChildFuc; }
/// <summary> /// 获取功能实体类 /// </summary> static public Object GetFunctionModel() { #region 开始 string result = string.Empty; try { int functionId = DNTRequest.GetInt("functionId", -1); FunctionBLL op = new FunctionBLL(); Function model = new Function(); model = op.GetModel(functionId); result = DNTRequest.GetResultJson(true, "success", model); } catch (Exception ex) { result = DNTRequest.GetResultJson(false, ex.Message, null); Log.WriteLog(ex.ToString()); } return(result); #endregion end 开始 }
public ActionResult GetFunctionDDLWithDefault(int controllerID, int areaID) { List <FunctionDDLModel> list; if (areaID == -1 && controllerID == -1)//区域与控制器均为全部 { list = FunctionBLL.GetFunctions(); } else if (areaID != -1 && controllerID == -1)//选了区域,但没选控制器 { list = FunctionBLL.GetFunctionsByAreaID(areaID); } else//选了具体的控制器 { list = FunctionBLL.GetFunctionsByControllerID(controllerID); } list.Insert(0, new Model.FunctionDDLModel() { ID = -1, FunctionName = UIText.All }); return(Json(list, JsonRequestBehavior.AllowGet)); }
protected void BindChildTree(TreeNode node) { string nodeid = node.Value; FunctionBLL bll = new FunctionBLL(); IList <Function> list = bll.GetChildFunctionList(nodeid, false); if (list != null) { foreach (Function model in list) { string name = model.F_Name; string code = model.F_Code.ToString(); TreeNode td = new TreeNode(name, code); td.SelectAction = TreeNodeSelectAction.None; td.Expanded = false; BindChildTree(td); node.ChildNodes.Add(td); } } }
/// <summary> /// 检查用户权限 /// </summary> /// <param name="functionCode">功能代码</param> /// <returns>True:具有权限,False:不具有权限</returns> /// <returns></returns> public bool CheckedAuthorize(string functionCode) { // 如果是管理员的,默认具有所有权限 if (this.IsMaster) { return(true); } //if (Authorize == null || Authorize.Count == 0) // return false; FunctionBLL bll = new FunctionBLL(); Authorize = bll.GetFuctionDepartmentExtentList2(" f.IsDeleted=0 AND ur.UserId=" + currentAdmin.UserID + ""); if (currentAdmin.UserType == 1) { return(true); } else { return(Authorize.Exists(t => t.FunctionCode == functionCode)); } }
//public ActionResult AddFunctionInfo() //{ // var aList = AreaBLL.GetAreas(); // FunctionAddModel model = new FunctionAddModel(); // model.AreasSelectList = new SelectList(aList, "ID", "AreaName"); // var cList = ControllerBLL.GetControllersByAreaID(aList.First().ID); // model.ControllersSelectList = new SelectList(cList, "ID", "ControllerName"); // var actionList = ActionBLL.GetActionsByControllerID(cList.First().ID); // model.ActionsSelectList = new SelectList(actionList, "ID", "ActionName"); // var parentFuncList = FunctionBLL.GetFunctions(); // model.ParentFunctionsSelectList = new SelectList(parentFuncList, "ID", "FunctionName"); // return PartialView("_AddFunctionInfo", model); //} public ActionResult AddFunctionInfo() { var aList = AreaBLL.GetAreas(); FunctionAddModel model = new FunctionAddModel(); model.OrderIndex = Int32.MaxValue;//默认新增的处于最后的位置 model.AreasSelectList = new SelectList(aList, "ID", "AreaName"); var cList = ControllerBLL.GetControllersByAreaID(aList.First().ID); model.ControllersSelectList = new SelectList(cList, "ID", "ControllerName"); var actionList = ActionBLL.GetActionsByControllerID(cList.First().ID); //model.ActionsSelectList = actionList.ToSelectListWithEmpty(m => GetSelectListItem(m.ID, m.ActionName)); model.ActionsSelectList = actionList.ToSelectList(m => GetSelectListItem(m.ID, m.ActionName)); var parentFuncList = FunctionBLL.GetFunctions(); model.ParentFunctionsSelectList = new SelectList(parentFuncList, "ID", "FunctionName", parentFuncList.First().ID); return(PartialView("_AddFunctionInfo", model)); }
//public ActionResult FunctionSetting() //{ // ViewBag.AreaID = -1; // ViewBag.ControllerID = -1; // ViewBag.ParentFunctionID = -1; // ViewBag.FunctionName = string.Empty; // FunctionSettingModel model = new FunctionSettingModel(); // model.PagedFunctions = FunctionBLL.GetPagedFunctions(PageSize); // var areaList = AreaBLL.GetAreas(); // model.AreasSelectList = areaList.ToSelectListWithAll(m => GetSelectListItem(m.ID, m.AreaName)); // var ctrList = ControllerBLL.GetControllers(); // model.ControllersSelectList = ctrList.ToSelectListWithAll(m => GetSelectListItem(m.ID, m.ControllerName)); // var parentFuncList = FunctionBLL.GetFunctions(); // model.ParentFunctionsSelectList = parentFuncList.ToSelectListWithAll(m => GetSelectListItem(m.ID, m.FunctionName)); // return PartialView("_FunctionSetting", model); //} //private ActionResult GetFunctionPagedGridPV(string functionName, int areaID, int controllerID, int parentFunctionID, int currentPage) //{ // ViewBag.AreaID = areaID; // ViewBag.ControllerID = controllerID; // ViewBag.FunctionName = functionName; // ViewBag.ParentFunctionID = parentFunctionID; // return PartialView("_FunctionPagedGrid", FunctionBLL.GetPagedFunctions(PageSize, currentPage, functionName, controllerID, areaID, parentFunctionID)); //} //public ActionResult FunctionPagedGrid(string functionName, int areaID = -1, int controllerID = -1, int currentPage = 1, int parentFunctionID = -1) //{ // return GetFunctionPagedGridPV(functionName, areaID, controllerID, parentFunctionID, currentPage); //} //[HttpPost, ValidateAntiForgeryToken] //public ActionResult GetFunctionInfo(string functionName, int areaID, int controllerID, int parentFunctionID) //{ // return GetFunctionPagedGridPV(functionName, areaID, controllerID, parentFunctionID, 1); //} #endregion public ActionResult FunctionSetting() { FunctionSettingModel model = new FunctionSettingModel(); var areaList = AreaBLL.GetAreas(); model.AreasSelectList = areaList.ToSelectListWithAll(m => GetSelectListItem(m.ID, m.AreaName)); var ctrList = ControllerBLL.GetControllers(); model.ControllersSelectList = ctrList.ToSelectListWithAll(m => GetSelectListItem(m.ID, m.ControllerName)); var parentFuncList = FunctionBLL.GetFunctions(); model.ParentFunctionsSelectList = parentFuncList.ToSelectListWithAll(m => GetSelectListItem(m.ID, m.FunctionName)); model.SearchPage = 1; model.AreaID = -1; model.ControllerID = -1; model.ParentFunctionID = -1; model.PagedDatas = FunctionBLL.GetPagedFunctions(model, this.PageSize); return(PartialView("_FunctionSetting", model)); }
/// <summary> /// 确定按钮 /// </summary> protected void FunctionInfoSave() { FunctionBLL funInfoBLL = new FunctionBLL(); FunctionNameChild = this.txtFunctionNameChild.Value.Trim(); FunctionType = Convert.ToInt32(this.SeleFunctionType.Value.Trim()); FunctionName = this.txtFunctionName.Value.ToString(); try { ParentID = int.Parse(this.txtFunctionID.Value); } catch { } if (FunctionNameChild == "") { Response.Write(IFrameLayerClosetwo("请填写功能名称!")); Response.End(); } if (FunctionNameChild.Length > 50) { Response.Write(IFrameLayerClosetwo("功能名称输入过长,请重新输入!")); Response.End(); } if (this.SeleFunctionType.Value.Trim() == "2") { Response.Write(IFrameLayerClosetwo("请选择功能类型!")); Response.End(); } if ((ParentID == FunctionId) && ParentID != 0 && FunctionId != 0) { Response.Write(IFrameLayerClosetwo("父级选择错误,请重新选择!")); Response.End(); } DataSet ds = new DataSet(); ds = funInfoBLL.GetList(" FunctionId<>" + FunctionId + " and FunctionName='" + FunctionNameChild + "' and IsDeleted=0 "); if (ds.Tables[0].Rows.Count > 0) { Response.Write(IFrameLayerClosetwo("功能名称重复,重新填写!")); Response.End(); } bool bFlag = false; if (this.btnSave.Text == "修改功能") { Function model = new Function(); model.FunctionId = Request.QueryString["FunctionID"].ToString().ToInt(); model.FunctionName = FunctionNameChild; model.ExternalLinkAddress = txtExternalLinkAddress.Value.Trim(); model.OrderId = ComPage.SafeToInt(txtOrderId.Value.Trim()); model.ParentId = ParentID; model.FunctionCode = this.HidFunctionCode.Value.ToString(); model.ClassId = FunctionType; model.IsDeleted = 0; model.EditId = LoginUserID; model.EditDate = DateTime.Now; bFlag = funInfoBLL.Update(model); if (bFlag) { Response.Write(IFrameLayerClosetwo("修改功能成功!")); Response.End(); } else { Response.Write(IFrameLayerClosetwo("修改功能失败")); Response.End(); } } else { bool aFlag = false; RandomCode = GetRandomCode(); aFlag = funInfoBLL.soleFunctionCode(RandomCode, 0); if (aFlag == true) { RandomCode = GetRandomCode(); } Function model = new Function(); model.FunctionId = FunctionID; model.FunctionName = FunctionNameChild; model.ExternalLinkAddress = txtExternalLinkAddress.Value.Trim(); model.OrderId = ComPage.SafeToInt(txtOrderId.Value.Trim()); model.ParentId = ParentID; model.FunctionCode = RandomCode; model.ClassId = FunctionType; model.IsDeleted = 0; model.CreateId = LoginUserID; model.EditId = LoginUserID; model.EditDate = DateTime.Now; model.CreateDate = DateTime.Now; int FunctionIdNew = 0; FunctionIdNew = funInfoBLL.Add(model); if (FunctionIdNew > 0) { Response.Write(IFrameLayerClosetwo("添加功能成功!")); Response.End(); } else { Response.Write(IFrameLayerClosetwo("添加功能失败,继续添加!")); Response.End(); } } }
public override void OnAuthorization(AuthorizationContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } #region 允许匿名 //如果当前控制器或操作上拥有AllowAnonymousAttribute特性,那么跳过身份验证 //比如登录操作 if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length > 0 | filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length > 0) { return; } #endregion #region 是否登录 if (!filterContext.HttpContext.User.Identity.IsAuthenticated)//未登录情况 { //当没有登录时,默认返回未授权结果 ActionResult result = new HttpUnauthorizedResult(); //但是如果是Ajax操作,那么需要返回一个状态值,通过脚本返回指定页面 if (filterContext.HttpContext.Request.IsAjaxRequest()) { string url = FormsAuthentication.LoginUrl; //string url = UrlHelper.GenerateUrl("Default", "Login", "Account", filterContext.RouteData.Values, RouteTable.Routes, filterContext.RequestContext, true); result = new JsonResult() { Data = new { AsiatekError = true, Url = url, Message = string.Empty }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } filterContext.Result = result; return; } #endregion #region Session是否过期 //通过登录界面登录的时候,会创建一个临时cookie,如果有这个cookie,并且session为null,就代表session过期了,那么就可以直接返回登录页 //如果是通过免登录并且关闭过浏览器上来的用户,肯定没有这个cookie值,所以直接对session赋值,并且创建该cookie //因此不管是哪种情况,只要有该cookie并且session为null就代表session过期,可以返回登录页 //当前登录凭证信息 用户编号|用户名|角色编号|角色名称|角色等级|用户昵称|单位ID|车辆查看模式 int userID = 0; string userName = string.Empty; int roleID = 0; string roleName = string.Empty; int roleLevel = 0; string nickName = string.Empty; int strucID = 0; bool vehicleViewMode = true; try { string identity = filterContext.HttpContext.User.Identity.Name; string[] identities = identity.Split('|'); userID = Convert.ToInt32(identities[0]); //用户编号 userName = identities[1]; //用户名 roleID = Convert.ToInt32(identities[2]); //角色编号 roleName = identities[3]; roleLevel = Convert.ToInt32(identities[4]); //角色等级 nickName = identities[5]; //用户昵称 strucID = Convert.ToInt32(identities[6]); //单位ID vehicleViewMode = Convert.ToBoolean(identities[7]); //车辆查看模式 } catch { //解析Cookie出错 FormsAuthentication.SignOut(); ActionResult result = new HttpUnauthorizedResult(); if (filterContext.HttpContext.Request.IsAjaxRequest()) { string url = FormsAuthentication.LoginUrl; result = new JsonResult() { Data = new { AsiatekError = true, Url = url, Message = string.Empty }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } filterContext.Result = result; return; } HttpCookie ck = filterContext.HttpContext.Request.Cookies["loginflag"]; //登录标识cookie Asiatek.Model.UserSessionModel currentUser = filterContext.HttpContext.Session["currentUser"] as Asiatek.Model.UserSessionModel; //存储在session中的用户信息 if (ck != null && currentUser == null) //session过期,清除cookie信息,返回登录页 { ck.Expires = DateTime.Now.AddYears(-1); filterContext.HttpContext.Response.Cookies.Add(ck); FormsAuthentication.SignOut(); ActionResult result = new HttpUnauthorizedResult(); if (filterContext.HttpContext.Request.IsAjaxRequest()) { string url = FormsAuthentication.LoginUrl; //string url = UrlHelper.GenerateUrl("Default", "Login", "Account", filterContext.RouteData.Values, RouteTable.Routes, filterContext.RequestContext, true); result = new JsonResult() { Data = new { AsiatekError = true, Url = url, Message = string.Empty }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } filterContext.Result = result; return; } //关闭浏览器后免登录上来的用户无登录标识cookie,并且session为null,此时对session赋值,并且发送登录标识cookie else if (ck == null && currentUser == null) { //临时的登录标识cookie,关闭浏览器后消失 ck = new HttpCookie("loginflag"); ck.Expires = DateTime.MinValue; filterContext.HttpContext.Response.Cookies.Add(ck); //进行当前用户的信息绑定 currentUser = new Asiatek.Model.UserSessionModel() { UserName = userName, UserId = userID, NickName = nickName, StrucID = strucID, RoleInfo = new Asiatek.Model.RoleInfoModel() { RoleID = roleID, RoleName = roleName, RoleLevel = (Asiatek.Model.RoleLevelEnum)roleLevel }, VehicleViewMode = vehicleViewMode }; //这里查询出该用户的权限信息,赋值给currentUser对象 if (currentUser.RoleInfo.RoleLevel == Model.RoleLevelEnum.SuperAdmin) { currentUser.Functions = FunctionBLL.GetAllFunctions(); } else { currentUser.Functions = FunctionBLL.GetFunctionsByUserID(currentUser.UserId); } //重新添加回session中 filterContext.HttpContext.Session["currentUser"] = currentUser; } #endregion #region 是否是超级管理员(超级管理员拥有全部权限,可以不用验证) if (currentUser.RoleInfo.RoleLevel == RoleLevelEnum.SuperAdmin) { return; } #endregion #region 权限 #region 跳过权限 //拥有PassPremissionAttribute的可以跳过数据库权限验证 //比如有些操作中的ajax操作,这些操作完全可以跳过权限验证,比如动态刷新时间,否则权限设定处还需要将这些操作列出来赋给用户,毫无意义 if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(AsiatekPassPremissionAttribute), true).Length > 0 | filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(AsiatekPassPremissionAttribute), true).Length > 0) { return; } #endregion #region 是否具有权限 //当前访问控制器名称 string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; //当前访问的操作名称 string actionName = filterContext.ActionDescriptor.ActionName; //当前访问的区域名称 没有指定区域 结果为null var routeData = filterContext.HttpContext.Request.RequestContext.RouteData; var area = routeData.DataTokens["area"]; string areaName = "DefaultArea";//默认的区域是空 我们系统默认为DefaultArea if (area != null) { areaName = area.ToString(); } #region 欢迎页无需权限 if (areaName == "DefaultArea" && controllerName == "Home" && actionName == "Welcome") { return; } #endregion #region 是否是从属功能 //当前行为具有从属特性,检查上级内容是否在用户权限中 var subAttributes = filterContext.ActionDescriptor.GetCustomAttributes(typeof(AsiatekSubordinateFunctionAttribute), true); if (subAttributes.Length > 0) { foreach (var item in subAttributes) { AsiatekSubordinateFunctionAttribute temp = item as AsiatekSubordinateFunctionAttribute; string superiorAreaName = temp.SuperiorAreaName; string superiorControllerName = temp.SuperiorControllerName; string superiorActionName = temp.SuperiorActionName; //如果superiorControllerName或superiorControllerName是NULL,则默认为当前值 var tempQuery = from c in currentUser.Functions where c.AreaName == (superiorAreaName == null ? areaName : superiorAreaName) && c.ControllerName == (superiorControllerName == null ? controllerName : superiorControllerName) && c.ActionName == superiorActionName select c; if (tempQuery.Count() != 0)//拥有权限 { return; } } } #endregion //查询当前登录用户的权限中是否包含目前访问的区域、控制器与操作 //只有三个条件均包含才算拥有权限 var query = from c in currentUser.Functions where c.ControllerName == controllerName && c.ActionName == actionName && c.AreaName == areaName select c; if (query.Count() != 0)//拥有权限 { return; } #endregion #region 包含权限的逻辑 //不包含权限的处理 //通过Html.Action或Html.RenderAction方式执行的操作算作子操作 //子操作不能执行重定向操作 //这里返回无权限的文字显示 if (filterContext.IsChildAction) { filterContext.Result = new ContentResult() { Content = Resource.UIText.NoPermission }; return; } //处理操作为Ajax操作 if (filterContext.HttpContext.Request.IsAjaxRequest()) { //没有权限的话,对于Ajax方法,返回一个json值,前端通过该值决定返回到哪个URL //这里返回无权限页面 string url = UrlHelper.GenerateUrl("Default", "UnAuth", "Account", filterContext.RouteData.Values, RouteTable.Routes, filterContext.RequestContext, true); filterContext.Result = new JsonResult() { Data = new { AsiatekError = true, Url = url, Message = string.Empty }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return; } //普通操作,将用户重定向到无权限页面 RouteValueDictionary rvd = new RouteValueDictionary(); rvd.Add("controller", "Account"); rvd.Add("action", "UnAuth"); filterContext.Result = new RedirectToRouteResult("Default", rvd); #endregion #endregion }
private ActionResult GetFunctionPagedGridPV(FunctionSettingModel model) { model.PagedDatas = FunctionBLL.GetPagedFunctions(model, this.PageSize); return(PartialView("_FunctionPagedGrid", model)); }
public ActionResult CheckEditFeaturesCodeExists(string featuresCode, int ID) { return(Json(!FunctionBLL.CheckEditFeaturesCodeExists(featuresCode, ID))); }