public virtual ISessionKey Current() { try { ISessionKey user = GetCallContextValue("FBState") as ISessionKey; if (user == null) { if (user != null) { return(user); } user = new ISessionKey(); var cookie = CookieHelper.GetCookie(SYSConstants.LoginJWTKey); // Session build user = StateChecker.CheckAuthString(cookie); // StateCheck 验证当前登录状态 todo // Add Context SetCallContextValue("FBState", user); } // 这里可以做线程缓存处理 ?这里需要check校验? 分两步 第一步bulid 然后校验 return(user); } catch (Exception ex) { //return new ISessionKey(); throw new Exception(ex.Message); } }
public void EmptyUser(string uid) { ISessionKey user = new ISessionKey(); user.UserID = uid; StateChecker.RemoveOnlineUser(user); }
public void AddCurrent(ISessionKey user) { // 创建服务器端令牌 user.Token = StateChecker.CreateServerStateToken(user); // 写入cookie CookieHelper.WriteCookie(SYSConstants.LoginJWTKey, StateChecker.CreateJWTToken(user)); }
/// <summary> /// 清除在线状态 /// </summary> /// <param name="info"></param> public static void RemoveOnlineUser(ISessionKey info) { Database db = DataBaseManger.GetDB(""); //info.Token var clearSql = new Sql("delete from FBOnlineUser where UserID=@0 and DeviceType='PC'", info.UserID); db.Execute(clearSql); }
public ISessionKey getDebugSession() { var session = new ISessionKey(); session.UserID = "admin"; session.UserCode = "admin"; session.UserName = "******"; session.IPAddress = ""; return(session); }
private static void CheckPCState(ISessionKey user) { Database db = DataBaseManger.GetDB(""); var sql = new Sql("select count(1) from FBOnlineUser where UserToken=@0 and UserID=@1 and DeviceType='PC'", user.Token, user.UserID); if (db.ExecuteScalar <long>(sql) <= 0) { throw new Exception("您的登录身份已过期,请重新登录,"); } }
public void EmptyCurrent() { ISessionKey user = GetCallContextValue("FBState") as ISessionKey; if (user != null) { StateChecker.RemoveOnlineUser(user); } // 清除cookie SetCallContextValue("FBState", null); CookieHelper.DelCookie(SYSConstants.LoginJWTKey); }
public static ISessionKey CheckAuthString(string cookieStr) { // 获取当前用户ID 和token 检查状态 ISessionKey user = null; buildSession(cookieStr, out user); CheckPCState(user); return(user); // 检查完之后更新最后访问时间 // 如果检查不同过则返回状态校验不通过 }
public virtual ISessionKey Current() { try { // 根据 url querysstring build一下 ISessionKey user = new ISessionKey(); user = getLBFSession(); return(user); } catch { //return new ISessionKey(); throw new Exception("登录信息超时,请重新登录。"); } }
public ISessionKey getLBFSession() { UserService svr = new UserService(); var session = new ISessionKey(); session.UserID = LBFContext.Current.Session.UserId; session.UserCode = LBFContext.Current.Session.UserCode; session.UserName = svr.GetUserNameById(session.UserID); session.IPAddress = ""; session.TokenID = LBFContext.Current.TokenId; session.MainDatabaseCode = LBFContext.Current.MainDatabaseCode; return(session); }
public static string CreateServerStateToken(ISessionKey info) { Database db = DataBaseManger.GetDB(""); var token = Guid.NewGuid().ToString(); // 这里要预留出pc端登陆的接口 var clearSql = new Sql("delete from FBOnlineUser where UserID=@0 and DeviceType='PC'", info.UserID); db.Execute(clearSql); var sql = new Sql("insert into FBOnlineUser(ID,UserID,LoginIP,LoginMachine,UserState,CreateTime,UserToken,DeviceType) values(@0,@1,@2,@3,@4,@5,@0,@6)", token, info.UserID, info.IPAddress, WebHelper.GetMachineName(), "1", DateTime.Now.ToString(), "PC"); db.Execute(sql); return(token); }
private static void buildSession(string stateCookie, out ISessionKey user) { if (string.IsNullOrEmpty(stateCookie)) { throw new Exception("客户端身份校验失败,Illegal Client Cerifcation"); } // 验证token是否有效 JsonWebToken.Decode(stateCookie, "XB#4%", true); var parts = stateCookie.Split('.'); //if (parts.Length != 3) throw new Exception("invalid Session Info!"); var payload = parts[1]; var payloadJson = Encoding.UTF8.GetString(Base64UrlDecode(payload)); user = Newtonsoft.Json.JsonConvert.DeserializeObject <ISessionKey>(payloadJson); }
public void AddCurrent(ISessionKey user) { throw new NotImplementedException(); }
public static string CreateJWTToken(ISessionKey info) { return(JsonWebToken.Encode(info, "XB#4%", JwtHashAlgorithm.RS256)); }