Sessions lastActivity logic improved; lastHumanActivity implemented

main
Inga 🏳‍🌈 14 years ago
parent c909683f8a
commit b94abe645a
  1. 2
      Builder/IISMainHandler/build.txt
  2. 29
      Common/dataobjects/Session.cs
  3. 41
      IISMainHandler/WebContext.cs
  4. 6
      IISMainHandler/designs/Classic.cs
  5. 4
      IISMainHandler/designs/IDesign.cs
  6. 6
      IISMainHandler/designs/Lite.cs
  7. 6
      IISMainHandler/designs/Raw.cs
  8. 6
      IISMainHandler/designs/Rss.cs
  9. 2
      IISMainHandler/handlers/BoardsHandler.cs
  10. 2
      IISMainHandler/handlers/response/AbstractUserGetHandler.cs
  11. 4
      IISMainHandler/handlers/response/WhoIsOnlineHandler.cs

@ -48,6 +48,7 @@ namespace FLocal.Common.dataobjects {
public const string FIELD_SESSIONKEY = "SessionKey";
public const string FIELD_ACCOUNTID = "AccountId";
public const string FIELD_LASTACTIVITY = "LastActivity";
public const string FIELD_LASTHUMANACTIVITY = "LastHumanActivity";
public const string FIELD_LASTURL = "LastUrl";
public const string FIELD_ISDELETED = "IsDeleted";
public static readonly TableSpec instance = new TableSpec();
@ -87,6 +88,14 @@ namespace FLocal.Common.dataobjects {
}
}
private DateTime _lastHumanActivity;
public DateTime lastHumanActivity {
get {
this.LoadIfNotLoaded();
return this._lastHumanActivity;
}
}
private string _lastUrl;
public string lastUrl {
get {
@ -105,7 +114,8 @@ namespace FLocal.Common.dataobjects {
protected override void doFromHash(Dictionary<string, string> data) {
this._sessionKey = data[TableSpec.FIELD_SESSIONKEY];
this._lastActivity = new DateTime(long.Parse(data[TableSpec.FIELD_LASTACTIVITY]));
this._lastActivity = Util.ParseDateTimeFromTimestamp(data[TableSpec.FIELD_LASTACTIVITY]).Value;
this._lastHumanActivity = Util.ParseDateTimeFromTimestamp(data[TableSpec.FIELD_LASTHUMANACTIVITY]).Value;
this._accountId = int.Parse(data[TableSpec.FIELD_ACCOUNTID]);
this._lastUrl = data[TableSpec.FIELD_LASTURL];
this._isDeleted = Util.string2bool(data[TableSpec.FIELD_ISDELETED]);
@ -117,17 +127,21 @@ namespace FLocal.Common.dataobjects {
string _url = lastUrl.ToLower();
if(_url.StartsWith("/upload/item")) return;
if(_url.StartsWith("/static")) return;
if(_url.StartsWith("/favicon.ico")) return;
}
try {
Dictionary<string, string> dataToUpdate = new Dictionary<string,string>();
dataToUpdate[TableSpec.FIELD_LASTACTIVITY] = DateTime.Now.ToUTCString();
if(lastUrl != null) {
dataToUpdate[TableSpec.FIELD_LASTURL] = lastUrl;
dataToUpdate[TableSpec.FIELD_LASTHUMANACTIVITY] = DateTime.Now.ToUTCString();
}
Config.Transactional(transaction => {
Config.instance.mainConnection.update(
transaction,
TableSpec.instance,
this.id.ToString(),
new Dictionary<string,string>() {
{ TableSpec.FIELD_LASTACTIVITY, DateTime.Now.ToUTCString() },
{ TableSpec.FIELD_LASTURL, (lastUrl != null) ? lastUrl : this.lastUrl },
}
dataToUpdate
);
});
} finally {
@ -154,6 +168,7 @@ namespace FLocal.Common.dataobjects {
{ TableSpec.FIELD_SESSIONKEY, key },
{ TableSpec.FIELD_ACCOUNTID, account.id.ToString() },
{ TableSpec.FIELD_LASTACTIVITY, DateTime.Now.ToUTCString() },
{ TableSpec.FIELD_LASTHUMANACTIVITY, DateTime.Now.ToUTCString() },
{ TableSpec.FIELD_LASTURL, "" },
{ TableSpec.FIELD_ISDELETED, "0" },
}
@ -181,7 +196,7 @@ namespace FLocal.Common.dataobjects {
public XElement exportToXml(UserContext context) {
return new XElement("session",
new XElement("lastActivity", this.lastActivity.ToXml()),
new XElement("lastActivity", this.lastHumanActivity.ToXml()),
new XElement("sessionKey", this.sessionKey),
this.account.user.exportToXmlForViewing(context),
AccountIndicator.LoadByAccount(this.account).exportToXml(context)
@ -206,7 +221,7 @@ namespace FLocal.Common.dataobjects {
new JoinSpec[0],
new SortSpec[] {
new SortSpec(
TableSpec.instance.getColumnSpec(TableSpec.FIELD_LASTACTIVITY),
TableSpec.instance.getColumnSpec(TableSpec.FIELD_LASTHUMANACTIVITY),
false
)
}

@ -99,13 +99,36 @@ namespace FLocal.IISHandler {
public WebContext(HttpContext httpcontext) {
this.httpcontext = httpcontext;
this.requestTime = DateTime.Now;
switch(this.httprequest.Url.Port % 1000) {
case 445:
this.design = new designs.Raw();
break;
case 447:
this.design = new designs.Lite();
break;
case 449:
this.design = new designs.Rss();
break;
case 443:
default:
this.design = new designs.Classic();
break;
}
HttpCookie sessionCookie = this.httprequest.Cookies["session"];
if(sessionCookie != null && sessionCookie.Value != null && sessionCookie.Value != "") {
try {
var session = Session.LoadByKey(sessionCookie.Value);
var tmp = session.account;
sessionCookie.Expires = DateTime.Now.AddDays(3);
session.updateLastActivity(this.httprequest.RequestType == "GET" ? this.httprequest.Path : null);
string lastUrl = null;
if(this.httprequest.RequestType == "GET") {
if(this.design.IsHuman) {
lastUrl = this.httprequest.Path;
}
}
session.updateLastActivity(lastUrl);
this.httpresponse.AppendCookie(sessionCookie);
this.session = session;
} catch(NotFoundInDBException) {
@ -120,22 +143,6 @@ namespace FLocal.IISHandler {
} else {
this.userSettings = new AnonymousUserSettings();
}
switch(this.httprequest.Url.Port % 1000) {
case 445:
this.design = new designs.Raw();
break;
case 447:
this.design = new designs.Lite();
break;
case 449:
this.design = new designs.Rss();
break;
case 443:
default:
this.design = new designs.Classic();
break;
}
}
public void WriteTransformResult(string templateName, System.Xml.Linq.XDocument data) {

@ -23,5 +23,11 @@ namespace FLocal.IISHandler.designs {
}
}
public bool IsHuman {
get {
return true;
}
}
}
}

@ -12,5 +12,9 @@ namespace FLocal.IISHandler.designs {
get;
}
bool IsHuman {
get;
}
}
}

@ -23,5 +23,11 @@ namespace FLocal.IISHandler.designs {
}
}
public bool IsHuman {
get {
return true;
}
}
}
}

@ -20,5 +20,11 @@ namespace FLocal.IISHandler.designs {
}
}
public bool IsHuman {
get {
return false;
}
}
}
}

@ -20,5 +20,11 @@ namespace FLocal.IISHandler.designs {
}
}
public bool IsHuman {
get {
return false;
}
}
}
}

@ -29,7 +29,7 @@ namespace FLocal.IISHandler.handlers {
new XElement("sessions", Config.instance.mainConnection.GetCountByConditions(
Session.TableSpec.instance,
new ComparisonCondition(
Session.TableSpec.instance.getColumnSpec(Session.TableSpec.FIELD_LASTACTIVITY),
Session.TableSpec.instance.getColumnSpec(Session.TableSpec.FIELD_LASTHUMANACTIVITY),
ComparisonType.GREATEROREQUAL,
DateTime.Now.Subtract(Config.instance.ActivityThreshold).ToUTCString()
)

@ -43,7 +43,7 @@ namespace FLocal.IISHandler.handlers.response {
return new XElement[] {
user.exportToXmlForViewing(context),
(account == null) ? null : new XElement("accountId", account.id.ToString()), //for PM history, PM send etc
(lastSession == null) ? null : new XElement("lastActivity", lastSession.lastActivity.ToXml()),
(lastSession == null) ? null : new XElement("lastActivity", lastSession.lastHumanActivity.ToXml()),
}.Union(this.getUserSpecificData(context, user));
}

@ -28,7 +28,7 @@ namespace FLocal.IISHandler.handlers.response {
new ComplexCondition(
ConditionsJoinType.AND,
new ComparisonCondition(
Session.TableSpec.instance.getColumnSpec(Session.TableSpec.FIELD_LASTACTIVITY),
Session.TableSpec.instance.getColumnSpec(Session.TableSpec.FIELD_LASTHUMANACTIVITY),
Core.DB.conditions.ComparisonType.GREATEROREQUAL,
DateTime.Now.Subtract(Config.instance.ActivityThreshold).ToUTCString()
),
@ -47,7 +47,7 @@ namespace FLocal.IISHandler.handlers.response {
where !account.isStatusHidden
select account.user.exportToXmlForViewing(
context,
new XElement("lastActivity", session.lastActivity.ToXml()),
new XElement("lastActivity", session.lastHumanActivity.ToXml()),
!account.isDetailedStatusHidden ? new XElement("lastUrl", session.lastUrl) : null
)
)

Loading…
Cancel
Save