public IActionResult Info([FromBody] JObject value) { Dictionary <string, object> d = value.ToObject <Dictionary <string, object> >(); Dictionary <string, object> r = new Dictionary <string, object>(); try { string tokenUserId = UIDP.UTILITY.AccessTokenTool.GetUserId(d["token"].ToString()); string userID = tokenUserId; if (d.Keys.Contains("userId") && d["userId"] != null && d["userId"].ToString() != "") { userID = d["userId"].ToString(); } if (userID == mm.getAdminCode()) { //if (tokenUserId == mm.getAdminCode()&&(d["userId"]==null|| d["userId"].ToString()=="")){ UIDP.LOG.SysLog log = new LOG.SysLog(); log.Info(DateTime.Now, tokenUserId, "系统超级管理员", ClientIp, 0, "info", "", 1); return(Json(new { code = 2000, message = "", roles = JsonConvert.DeserializeObject("['admin']"), name = "系统超级管理员", userCode = tokenUserId, token = d["token"].ToString(), introduction = "", avatar = "", sysCode = "1", sysName = mm.getSysName(), userId = tokenUserId, userSex = 0, departCode = "", departName = "", userType = "0" })); } //string token = UIDP.UTILITY.AccessTokenTool.GetAccessToken(d["userId"].ToString()); string token = UIDP.UTILITY.AccessTokenTool.GetAccessToken(userID); //DataTable dt = mm.GetUserAndOrgByUserId(d["userId"].ToString()); DataTable dt = mm.GetUserAndOrgByUserId(userID); if (dt != null && dt.Rows.Count > 0) { string _name = dt.Rows[0]["USER_NAME"] == null ? "" : dt.Rows[0]["USER_NAME"].ToString(); string _userCode = dt.Rows[0]["USER_DOMAIN"] == null ? "" : dt.Rows[0]["USER_DOMAIN"].ToString(); string _userId = dt.Rows[0]["USER_ID"] == null ? "" : dt.Rows[0]["USER_ID"].ToString(); int _userSex = Convert.ToInt32(dt.Rows[0]["USER_SEX"].ToString()); string _deptCode = dt.Rows[0]["ORG_CODE"] == null ? "" : dt.Rows[0]["ORG_CODE"].ToString(); string _deptName = dt.Rows[0]["ORG_SHORT_NAME"] == null ? "" : dt.Rows[0]["ORG_SHORT_NAME"].ToString(); string _userType = dt.Rows[0]["USER_TYPE"] == null ? "" : dt.Rows[0]["USER_TYPE"].ToString(); UIDP.LOG.SysLog log = new LOG.SysLog(); //log.Info(DateTime.Now, d["userId"].ToString(), _name, ClientIp, 0, "info", "",1); log.Info(DateTime.Now, userID, _name, ClientIp, 0, "info", "", 1); return(Json(new { code = 2000, message = "", roles = new Dictionary <string, object>(), token = token, introduction = "", avatar = "", name = _name, userCode = _userCode, sysCode = "1", sysName = mm.getSysName(), userId = _userId, userSex = _userSex, departCode = _deptCode, departName = _deptName, userType = _userType })); } return(Json(new { code = 2000, message = "", roles = "", name = "", userCode = "", token = token, introduction = "", avatar = "", sysCode = "1", sysName = mm.getSysName(), userId = "", userSex = 0, departCode = "", departName = "", userType = "0" })); } catch (Exception ex) { r["code"] = -1; r["message"] = ex.Message; } return(Json(r)); }
public override void OnActionExecuting(ActionExecutingContext context) { try { Microsoft.Extensions.Primitives.StringValues AccessToken; //获取header中某一项的值 context.HttpContext.Request.Headers.TryGetValue("X-Token", out AccessToken); ClientIp = Extension.GetClientUserIp(Request.HttpContext); actionName = (context.RouteData.Values["action"]).ToString().ToLower(); //获取当前方法 if (actionName == "loginconfig") { base.OnActionExecuting(context); return; } //根据实际需求进行具体实现 accessToken = AccessToken; if (accessToken == "") { context.Result = new ObjectResult(new { code = 50008, msg = "没有找到X-Token" }); } string userId = STORE.UTILITY.AccessTokenTool.GetUserId(AccessToken); UserId = userId; if (actionName == "info") { STORE.UTILITY.Message mes = STORE.UTILITY.AccessTokenTool.IsInValidUser(userId, AccessToken, "user"); if (mes.code != 2000) { context.Result = new ObjectResult(mes); } } else { BIZModule.UserModule mm = new BIZModule.UserModule(); string admin = mm.getAdminCode(); if (userId == admin) { UserName = "******"; } else { UserName = mm.getUserInfoByUserId(userId).USER_NAME; } STORE.UTILITY.Message mes = STORE.UTILITY.AccessTokenTool.IsInValidUser(userId, AccessToken, admin); if (mes.code != 2000) { context.Result = new ObjectResult(mes); } } STORE.LOG.SysLog log = new LOG.SysLog(); log.Info(DateTime.Now, userId, UserName, ClientIp, 0, actionName, "", 1); } catch (Exception ex) { STORE.LOG.SysLog log = new LOG.SysLog(); log.Info(DateTime.Now, UserId, UserName, ClientIp, 1, actionName, ex.Message.Length > 120 ? ex.Message.Substring(0, 100) : ex.Message, 1); context.Result = new ObjectResult(new { code = -1, msg = "验证token时程序出错", result = ex.Message }); } #region 备份原来的逻辑 /* * public override void OnActionExecuting(ActionExecutingContext context) * { * try * { * Microsoft.Extensions.Primitives.StringValues AccessToken;//获取header中某一项的值 * context.HttpContext.Request.Headers.TryGetValue("X-Token", out AccessToken); * * actionName = (context.RouteData.Values["action"]).ToString().ToLower();//获取当前方法 * //根据实际需求进行具体实现 * accessToken = AccessToken; * if (accessToken == "") * { * context.Result = new ObjectResult(new { code = 50008, msg = "没有找到X-Token" }); * } * string userId = UIDP.UTILITY.AccessTokenTool.GetUserId(AccessToken); * BIZModule.UserModule mm = new BIZModule.UserModule(); * string admin = mm.getAdminCode(); * if (userId == admin) * { * UserName = "******"; * } * else * { * UserName = mm.getUserInfoByUserId(userId).USER_NAME; * } * UIDP.UTILITY.Message mes = UIDP.UTILITY.AccessTokenTool.IsInValidUser(userId, AccessToken,admin); * if (mes.code != 2000) * { * context.Result = new ObjectResult(mes); * } * UserId = userId; * ClientIp = Extension.GetClientUserIp(Request.HttpContext); * UIDP.LOG.SysLog log = new LOG.SysLog(); * log.Info(DateTime.Now, userId, UserName, ClientIp, 0, actionName, ""); * } * catch (Exception ex) * { * UIDP.LOG.SysLog log = new LOG.SysLog(); * log.Info(DateTime.Now, UserId, UserName, ClientIp, 1, actionName, ex.Message.Length > 120 ? ex.Message.Substring(0, 100) : ex.Message); * context.Result = new ObjectResult(new { code = -1, msg = "验证token时程序出错", result = ex.Message }); * } * * } */ #endregion }