public override void OnActionExecuting(HttpActionContext actionContext) { RequestResult result = new RequestResult(); // 请求限制间隔 HttpContextBase context = (HttpContextBase)actionContext.Request.Properties["MS_HttpContext"];//获取传统context HttpRequestBase request = context.Request; if (!IsOpenApi) { if (request["UserToken"] == null) { result.code = 101; result.message = "无法验证用户密钥."; actionContext.Response = GetHttpResponseMessage(result); } else { string UserToken = request["UserToken"].ToString(); if (PDAUserMsg.TokenGetUser(UserToken) == null) { result.code = 101; result.message = "用户密钥已过期或不存在."; actionContext.Response = GetHttpResponseMessage(result); } } } }
public RequestResult LoginOut() { RequestResult result = new RequestResult(); try { if (PDAUserMsg.RemoveUser(UserToken)) { result.message = "登出成功"; result.success = true; } else { result.message = "登出失败"; result.success = false; } PDALog.Write("退出登录", "退出", "", PdaUser.PUserName + "-" + PdaUser.PRealName, "", result.message); } catch (Exception ex) { result.code = 500; result.message = "服务出错"; result.success = false; DAL.Log.Instance.Write("PDA用户退出出错:" + ex.Message, "PDA用户退出出错"); } return(result); }
public static void UserClearEvent(object obj) { try { PDAUserMsg.ClearTimeOutUser(); } catch { } }
public TimingEvent() { // 定时处理IP地址 timer = new System.Threading.Timer(IPClearEvent, null, 0, 400); // 定时处理用户登录状态 // timer2 = new System.Threading.Timer(UserClearEvent, null, 0, 10000); PDAUserMsg.InitPDASystemParam(); }
protected override void Initialize(HttpControllerContext controllerContext) { HttpContextBase context = (HttpContextBase)controllerContext.Request.Properties["MS_HttpContext"];//获取传统context HttpRequestBase request = context.Request; if (request["UserToken"] != null) { UserToken = request["UserToken"].ToString(); if (!string.IsNullOrWhiteSpace(UserToken)) { CachePDAUser User = PDAUserMsg.TokenGetUser(UserToken); if (User != null) { PdaUser = PDAUser.GetEntityByID(User.UserID); } } } base.Initialize(controllerContext); }
public RequestResult Login(string DeviceCode, string UserName, string Password) { RequestResult result = new RequestResult(); try { PDA pda = PDA.GetEntityByKeys(DeviceCode); if (pda == null) { result.code = 1009; result.message = "该设备验证不通过,禁止访问服务器"; result.success = false; PDALog.Write("用户登录", "登录", "", UserName, string.Format("DeviceCode:{0}", DeviceCode), result.message); return(result); } PDAUser user = PDAUser.PDAUserLogin(UserName, Password); if (user == null) { result.message = "用户名或密码错误"; result.success = false; PDALog.Write("用户登录", "登录", "", UserName, string.Format("DeviceCode:{0}", DeviceCode), result.message); return(result); } string IsUserToken = PDAUserMsg.PDAUserLogin(DeviceCode, UserName); // 验证重复登录 CachePDAUser muser = new CachePDAUser(); muser.DeviceCode = DeviceCode; muser.UserID = user.ID; muser.UserName = user.PUserName; muser.Timestamp = CommonFunc.GetNowMTimestamp(); muser.UserToken = string.IsNullOrEmpty(IsUserToken) ? PDAUserMsg.CreateUserToken() : IsUserToken; //muser.AuthCodeList = B_RoleRights.GetEntitysByRoleID(user.C_UserTypeID); // 权限控制 PDAUserMsg.CacheMobileUserList.Add(muser); UserLoginInfo UserInfo = new UserLoginInfo(); UserInfo.UserToken = muser.UserToken; UserInfo.ExpireDate = DateTime.Now.AddHours(20).ToString("yyyy-MM-dd HH:mm:ss"); result.data = UserInfo; result.timestamp = CommonFunc.GetNowTimestamp(); result.message = "登录成功"; result.success = true; user.LastLoginTime = DateTime.Now; user.LastLoginDCode = DeviceCode; user.UpdateByID(); PDALog.Write("用户登录", "登录", "", user.PUserName + "-" + user.PRealName, string.Format("DeviceCode:{0}", DeviceCode), result.message); } catch (Exception ex) { result.code = 500; result.message = "服务出错"; result.success = false; DAL.Log.Instance.Write("PDA登录出错:" + ex.Message, "PDA登录出错"); } return(result); }