/// <summary> /// 验证登录 /// </summary> /// <param name="sessionid">登录会话Id</param> /// <returns></returns> private BusinessBaseViewModel <object> ValidateLogin(string sessionid, HttpActionContext actionContext) { var response = new BusinessBaseViewModel <object> { Status = ResponseStatus.Fail }; if (sessionid.IsNullOrWhiteSpace()) { response.Status = ResponseStatus.UnSessionIdParamsError; return(response); } string deviceNo = string.Empty; string sessionidCacheKey = TianYuConsts.GetSessionIdCacheKey(sessionid); var userGroup = Cache.CacheHelper.Get <SystemLoginUserInfo>(sessionidCacheKey); if (userGroup.IsNull()) { var model = LoginSessionDataHelper.GetSessionInfoModel(sessionid); if (model.IsNull()) { response.Status = ResponseStatus.SessionIdError; return(response); } else { deviceNo = model.DeviceNo; } } else { // deviceNo = userGroup.DeviceNo; } string ticket = actionContext.Request.Headers.Authorization.Parameter; if (ticket.IsNullOrWhiteSpace()) { response.Status = ResponseStatus.UnAuthorityError; return(response); } //解密票据 string key = TianYuConsts.GetTicketCacheKey(ticket); var ticketDetailsModel = CacheHelper.Get <AuthenticationTicketDetailsModel>(key); if (ticketDetailsModel.IsNull()) { response.Status = ResponseStatus.AuthenticationTicketTimeOut; return(response); } if (ticketDetailsModel.ClientType != AuthClientType.SamllApp.GetEnumDescription() && ticketDetailsModel.DeviceNo != deviceNo) { response.Status = ResponseStatus.SessionIdOtherLogin; response.BusinessData = deviceNo; return(response); } response.BusinessData = userGroup; response.Status = ResponseStatus.Success; return(response); }
internal void AddAuthenticationTicketDetails(AuthenticationTicketDetailsModel model) { if (model.IsNull()) { return; } StringBuilder builder = new StringBuilder(); builder.Append("INSERT INTO AuthenticationTicketDetails(TicketId,Ticket,TicketAppID,TicketSecond,LastRefreshDate,DeviceNo,ClientType,CreateTime)"); builder.Append("VALUES(@TicketId,@Ticket,@TicketAppID,@TicketSecond,@LastRefreshDate,@DeviceNo,@ClientType,@CreateTime)"); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter() { ParameterName = "@TicketId", Value = model.TicketId }, new SqlParameter() { ParameterName = "@Ticket", Value = model.Ticket }, new SqlParameter() { ParameterName = "@TicketAppID", Value = model.TicketAppID }, new SqlParameter() { ParameterName = "@TicketSecond", Value = model.TicketSecond }, new SqlParameter() { ParameterName = "@LastRefreshDate", Value = model.LastRefreshDate }, new SqlParameter() { ParameterName = "@DeviceNo", Value = model.DeviceNo }, new SqlParameter() { ParameterName = "@ClientType", Value = model.ClientType }, new SqlParameter() { ParameterName = "@CreateTime", Value = model.CreateTime }, //new SqlParameter(){ ParameterName="AppSecret",Value=model.AppSecret}, }; bool flag = ExecuteNonQuery(builder.ToString(), parameters) > 0; if (flag) { string key = TianYuConsts.GetTicketCacheKey(model.Ticket); Cache.CacheHelper.Insert(key, model, 7200); } }
/// <summary> /// 刷新缓存 /// </summary> /// <param name="token"></param> internal void RefreshCache(string token) { string key = TianYuConsts.GetTicketCacheKey(token); var model = Cache.CacheHelper.Get <AuthenticationTicketDetailsModel>(key); if (model.IsNull()) { return; } Cache.CacheHelper.Remove(token); model.LastRefreshDate = DateTime.Now; Cache.CacheHelper.Insert(key, model, 7200); }
internal AuthenticationTicketDetailsModel GetCheckTicket(string token) { if (token.IsNullOrWhiteSpace()) { return(null); } string key = TianYuConsts.GetTicketCacheKey(token); AuthenticationTicketDetailsModel model = Cache.CacheHelper.Get <AuthenticationTicketDetailsModel>(key); if (model.IsNull()) { StringBuilder builder = new StringBuilder(); builder.Append("SELECT * FROM AuthenticationTicketDetails WHERE Ticket=@Ticket AND LastRefreshDate>@LastRefreshDate"); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter() { ParameterName = "@Ticket", Value = token }, new SqlParameter() { ParameterName = "@LastRefreshDate", Value = DateTime.Now.AddSeconds(-7200) } }; var dt = ExecuteQuery(builder.ToString(), parameters); if (!dt.IsNull() && dt.Rows.Count > 0) { var row = dt.Rows[0]; model = new AuthenticationTicketDetailsModel { ClientType = row["ClientType"].ToString(), DeviceNo = row["DeviceNo"].ToString(), LastRefreshDate = row["LastRefreshDate"].ToDateTime(), Ticket = row["Ticket"].ToString(), TicketId = Guid.Parse(row["TicketId"].ToString()), TicketAppID = row["TicketAppID"].ToString(), TicketSecond = row["TicketSecond"].ToInt(), }; builder.Clear(); builder.Append("SELECT * FROM ApplocationAuthor WHERE AppId=@AppId"); parameters = new SqlParameter[] { new SqlParameter() { ParameterName = "@AppId", Value = model.TicketAppID } }; dt = ExecuteQuery(builder.ToString(), parameters); if (!dt.IsNull() && dt.Rows.Count > 0) { model.AppSecret = dt.Rows[0]["AppSecret"].ToString(); } Cache.CacheHelper.Insert(key, model, 7200); } else { return(null); } } RefreshCache(token); return(model); }