public static SessionInfo ParseRedeemSessionPayload(string payload) { SessionInfo sessionInfo = null; if(payload != null && payload.Length >0){ // Get Session info XmlQueryDoc expDoc = new XmlQueryDoc(payload); sessionInfo = new SessionInfo(); string STR_RedeemSessionPayload = "RedeemSessionPayload/"; string userID = expDoc.Query(STR_RedeemSessionPayload + "userID"); sessionInfo.userID = Convert.ToInt32(userID); string groupID = expDoc.Query(STR_RedeemSessionPayload + "groupID"); sessionInfo.groupID = Convert.ToInt32(groupID); string clientID = expDoc.Query(STR_RedeemSessionPayload + "clientID"); sessionInfo.clientID = Convert.ToInt32(clientID); sessionInfo.userName = expDoc.Query(STR_RedeemSessionPayload + "userName"); sessionInfo.groupName = expDoc.Query(STR_RedeemSessionPayload + "groupName"); } return sessionInfo; }
private void SessionInfoToSession(SessionInfo sessionInfo) { if (sessionInfo != null) { //Establish session credentials with the new information. Session["UserID"] = sessionInfo.userID; if (sessionInfo.groupID > 0) { Session["GroupID"] = sessionInfo.groupID; Session["GroupName"] = sessionInfo.groupName; } else { Session.Remove("GroupID"); Session.Remove("GroupName"); } if (sessionInfo.clientID > 0) { Session["ClientID"] = sessionInfo.clientID; } else Session.Remove("ClientID"); } else { Session.Remove("UserID"); Session.Remove("GroupID"); Session.Remove("ClientID"); Session.Remove("UserName"); Session.Remove("GroupName"); } }
/// <summary> /// to select a user's sessions given the session IDs /// </summary> public static SessionInfo SelectSessionInfo(long sessionID) { SessionInfo sessionInfo = null; DbConnection myConnection = FactoryDB.GetConnection(); DbCommand myCommand = FactoryDB.CreateCommand("SessionInfo_Retrieve", myConnection); myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.Add(FactoryDB.CreateParameter("@sessionID",sessionID, DbType.Int64)); try { myConnection.Open(); // get session info from table user_sessions DbDataReader myReader = myCommand.ExecuteReader(); while (myReader.Read()) { sessionInfo = new SessionInfo(); sessionInfo.sessionID = sessionID; sessionInfo.userID = myReader.GetInt32(0); sessionInfo.groupID = myReader.GetInt32(1); if (!myReader.IsDBNull(2)) sessionInfo.clientID = myReader.GetInt32(2); else sessionInfo.clientID = 0; sessionInfo.userName = myReader.GetString(3); sessionInfo.groupName = myReader.GetString(4); sessionInfo.tzOffset = myReader.GetInt32(5); } myReader.Close(); } catch (Exception ex) { throw new Exception("Exception thrown in selecting sessions given sessionIDs", ex); } finally { myConnection.Close(); } return sessionInfo; }
public static SessionInfo GetSessionInfo(Coupon coupon) { SessionInfo sessionInfo = null; TicketIssuerDB ticketIssuer = new TicketIssuerDB(); Ticket sessionTicket = ticketIssuer.RetrieveIssuedTicket(coupon, TicketTypes.REDEEM_SESSION, ProcessAgentDB.ServiceGuid); if (sessionTicket != null) { if (sessionTicket.IsExpired()) { throw new AccessDeniedException("The ticket has expired."); } // Get Session info XmlQueryDoc expDoc = new XmlQueryDoc(sessionTicket.payload); sessionInfo = new SessionInfo(); string STR_RedeemSessionPayload = "RedeemSessionPayload/"; string userID = expDoc.Query(STR_RedeemSessionPayload + "userID"); sessionInfo.userID = Convert.ToInt32(userID); string groupID = expDoc.Query(STR_RedeemSessionPayload + "groupID"); sessionInfo.groupID = Convert.ToInt32(groupID); string clientID = expDoc.Query(STR_RedeemSessionPayload + "clientID"); sessionInfo.clientID = Convert.ToInt32(clientID); sessionInfo.userName = expDoc.Query(STR_RedeemSessionPayload + "userName"); sessionInfo.groupName = expDoc.Query(STR_RedeemSessionPayload + "groupName"); } return sessionInfo; }