Commit 785b1c361cf71e02ac6a1af38b2e78e7564dd56f

Authored by Georg Hopp
1 parent 5fc9ce54

changed frontend to make it to use ldap login and simple session setup without username

@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 <body> 13 <body>
14 <ul id="menu"> 14 <ul id="menu">
15 <li>random Value</li> 15 <li>random Value</li>
  16 + <li>start session</li>
16 <li>login</li> 17 <li>login</li>
17 </ul> 18 </ul>
18 <div id="sessinfo" class="x-small"> 19 <div id="sessinfo" class="x-small">
@@ -14,6 +14,10 @@ $(document).ready(function() { @@ -14,6 +14,10 @@ $(document).ready(function() {
14 }); 14 });
15 15
16 $("ul#menu li:eq(1)").click(function() { 16 $("ul#menu li:eq(1)").click(function() {
  17 + $.getJSON("/sess/", $.proxy(sess.loadJSON, sess));
  18 + });
  19 +
  20 + $("ul#menu li:eq(2)").click(function() {
17 $("#login").removeClass("hide"); 21 $("#login").removeClass("hide");
18 }); 22 });
19 23
@@ -15,6 +15,8 @@ function Session(sId) @@ -15,6 +15,8 @@ function Session(sId)
15 15
16 Session.prototype.loadJSON = function(data) 16 Session.prototype.loadJSON = function(data)
17 { 17 {
  18 + this.stop();
  19 +
18 this.id = ("0" == data.id)? "none" : data.id; 20 this.id = ("0" == data.id)? "none" : data.id;
19 this.timeout = data.timeout * 10; 21 this.timeout = data.timeout * 10;
20 this.timeleft = data.timeleft * 10; 22 this.timeleft = data.timeleft * 10;
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 #include <stdio.h> 24 #include <stdio.h>
25 #include <stdlib.h> 25 #include <stdlib.h>
26 #include <time.h> 26 #include <time.h>
  27 +#include <string.h>
27 #include <sys/time.h> 28 #include <sys/time.h>
28 29
29 #include "class.h" 30 #include "class.h"
@@ -116,7 +117,7 @@ httpWorkerProcess(HttpWorker this, Stream st) @@ -116,7 +117,7 @@ httpWorkerProcess(HttpWorker this, Stream st)
116 * an empty 200 OK 117 * an empty 200 OK
117 */ 118 */
118 if (NULL == password || NULL == username) { 119 if (NULL == password || NULL == username) {
119 - response = new(HttpResponse, "HTTP/1.1", 200, "OK"); 120 + response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden");
120 } 121 }
121 122
122 if (NULL == response) { 123 if (NULL == response) {
@@ -126,11 +127,22 @@ httpWorkerProcess(HttpWorker this, Stream st) @@ -126,11 +127,22 @@ httpWorkerProcess(HttpWorker this, Stream st)
126 (char*)(password->value), password->nvalue); 127 (char*)(password->value), password->nvalue);
127 128
128 if (!authenticate(this->auth, cred)) { 129 if (!authenticate(this->auth, cred)) {
129 - response = new(HttpResponse, "HTTP/1.1", 200, "OK"); 130 + response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden");
130 } else { 131 } else {
131 - this->session = sessionAdd(  
132 - this->sroot,  
133 - new(Session, username->value, username->nvalue)); 132 + if (NULL == this->session) {
  133 + this->session = sessionAdd(
  134 + this->sroot,
  135 + new(Session,
  136 + username->value,
  137 + username->nvalue));
  138 + } else {
  139 + this->session->username = malloc(username->nvalue + 1);
  140 + this->session->username[username->nvalue] = 0;
  141 + memcpy(this->session->username,
  142 + username->value,
  143 + username->nvalue);
  144 + }
  145 +
134 nbuf = sprintf(buffer, 146 nbuf = sprintf(buffer,
135 "sid=%lu;Path=/", 147 "sid=%lu;Path=/",
136 this->session->id); 148 this->session->id);
@@ -161,6 +173,15 @@ httpWorkerProcess(HttpWorker this, Stream st) @@ -161,6 +173,15 @@ httpWorkerProcess(HttpWorker this, Stream st)
161 response = (HttpMessage)httpResponseSession(this->session); 173 response = (HttpMessage)httpResponseSession(this->session);
162 } 174 }
163 175
  176 + if (0 == strcmp("/sess/", request->path)) {
  177 + if (NULL == this->session) {
  178 + this->session = sessionAdd(
  179 + this->sroot,
  180 + new(Session, NULL, 0));
  181 + }
  182 + response = (HttpMessage)httpResponseSession(this->session);
  183 + }
  184 +
164 if (0 == strcmp("/randval/", request->path)) { 185 if (0 == strcmp("/randval/", request->path)) {
165 if (NULL != this->session) { 186 if (NULL != this->session) {
166 response = (HttpMessage)httpResponseRandval( 187 response = (HttpMessage)httpResponseRandval(
Please register or login to post a comment