Browse Source

Username is shown again in the frontend

master
Georg Hopp 14 years ago
parent
commit
78ee46aa49
  1. 2
      assets/html/main.html
  2. 2
      assets/js/serverval.js
  3. 11
      assets/js/session.js
  4. 5
      src/http/response/session.c

2
assets/html/main.html

@ -65,7 +65,7 @@
</div> </div>
<div id="main"> <div id="main">
<h1>Testpage</h1> <h1>Testpage</h1>
Welcome You!!!<br />
Welcome<span></span>!!!<br />
<img src="/image/me" /> <img src="/image/me" />
</div> </div>
<hr /> <hr />

2
assets/js/serverval.js

@ -17,6 +17,7 @@ ServerVal.prototype.loadJSON = function(data)
this.vnext = data.vnext; this.vnext = data.vnext;
this.value = data.value; this.value = data.value;
$.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
this.show(); this.show();
} }
@ -57,7 +58,6 @@ ServerVal.prototype.process = function()
break; break;
} }
}, this)); }, this));
$.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
} }
else { else {

11
assets/js/session.js

@ -7,6 +7,7 @@ function Session(sId)
this.id = "none" this.id = "none"
this.timeout = 0; this.timeout = 0;
this.timeleft = 0; this.timeleft = 0;
this.username = "";
this.interval = null; this.interval = null;
this.draw(); this.draw();
@ -17,6 +18,10 @@ Session.prototype.loadJSON = function(data)
this.id = ("0" == data.id)? "none" : data.id; this.id = ("0" == data.id)? "none" : data.id;
this.timeout = data.timeout * 10; this.timeout = data.timeout * 10;
this.timeleft = data.timeleft * 10; this.timeleft = data.timeleft * 10;
this.username = data.username;
this.eSid.empty().append(this.id);
$("#main span:eq(0)").empty().append(" " + this.username);
this.draw(); this.draw();
if (0 < this.timeleft) if (0 < this.timeleft)
@ -25,8 +30,6 @@ Session.prototype.loadJSON = function(data)
Session.prototype.draw = function() Session.prototype.draw = function()
{ {
this.eSid.empty().append(this.id);
this.context.fillStyle = "rgb(255, 0, 0)"; this.context.fillStyle = "rgb(255, 0, 0)";
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height); this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
@ -62,6 +65,10 @@ Session.prototype.stop = function()
this.id = "none"; this.id = "none";
this.timeout = 0; this.timeout = 0;
this.timeleft = 0; this.timeleft = 0;
this.username = "";
this.eSid.empty().append(this.id);
$("#main span:eq(0)").empty().append(" " + this.username);
this.draw(); this.draw();
} }

5
src/http/response/session.c

@ -36,7 +36,7 @@
#include "utils/memory.h" #include "utils/memory.h"
#define RESP_DATA "{\"id\":\"%lu\",\"timeout\":%d,\"timeleft\":%ld}"
#define RESP_DATA "{\"id\":\"%lu\",\"timeout\":%d,\"timeleft\":%ld,\"username\":\"%s\"}"
HttpResponse HttpResponse
httpResponseSession(Session session) httpResponseSession(Session session)
@ -57,7 +57,8 @@ httpResponseSession(Session session)
nbuf = sprintf(buffer, RESP_DATA, nbuf = sprintf(buffer, RESP_DATA,
(NULL != session)? session->id : 0, (NULL != session)? session->id : 0,
(NULL != session)? SESSION_LIVETIME : 0, (NULL != session)? SESSION_LIVETIME : 0,
(NULL != session)? session->livetime - time(NULL) : 0);
(NULL != session)? session->livetime - time(NULL) : 0,
(NULL != session)? session->username : "");
message->nbody = nbuf; message->nbody = nbuf;
message->body = malloc(nbuf); message->body = malloc(nbuf);

Loading…
Cancel
Save