diff --git a/assets/js/session.js b/assets/js/session.js index de47615..9e3e8be 100644 --- a/assets/js/session.js +++ b/assets/js/session.js @@ -8,6 +8,9 @@ function Session(sId) this.timeout = 0; this.timeleft = 0; this.username = ""; + this.email = ""; + this.firstname = ""; + this.surname = ""; this.interval = null; this.draw(); @@ -18,12 +21,15 @@ Session.prototype.loadJSON = function(data) this.stop(); this.id = ("0" == data.id)? "none" : data.id; - this.timeout = data.timeout * 10; - this.timeleft = data.timeleft * 10; - this.username = data.username; + //this.timeout = data.timeout * 10; + //this.timeleft = data.timeleft * 10; + //this.username = data.username; + this.email = data.email; + this.firstname = data.firstname; + this.surname = data.surname; this.eSid.empty().append(this.id); - $("#main p:eq(1) span:eq(0)").empty().append(" " + this.username); + $("#main p:eq(1) span:eq(0)").empty().append(" " + this.firstname + " " + this.surname); this.draw(); if (0 < this.timeleft) @@ -68,6 +74,9 @@ Session.prototype.stop = function() this.timeout = 0; this.timeleft = 0; this.username = ""; + this.email = ""; + this.firstname = ""; + this.surname = ""; this.eSid.empty().append(this.id); $("#main p:eq(1) span:eq(0)").empty().append(" " + this.username); diff --git a/include/http/response.h b/include/http/response.h index b2e56ba..cfcc4fa 100644 --- a/include/http/response.h +++ b/include/http/response.h @@ -30,6 +30,7 @@ #include "class.h" #include "http/message.h" #include "session.h" +#include "user.h" #include "asset.h" @@ -51,6 +52,7 @@ HttpResponse httpResponseMe(); HttpResponse httpResponseLoginForm(); HttpResponse httpResponseRandval(time_t, int); HttpResponse httpResponseSession(Session); +HttpResponse httpResponseUser(User); HttpResponse httpResponseAsset(const char *, size_t); #endif // __HTTP_RESPONSE_H__ diff --git a/src/application/adapter/http/update.c b/src/application/adapter/http/update.c index 6d0a6d8..bca45e8 100644 --- a/src/application/adapter/http/update.c +++ b/src/application/adapter/http/update.c @@ -151,6 +151,9 @@ loginAdapter(Application application, HttpWorker worker, Session session) if (! applicationLogin(application, credential, session)) { worker->current_response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden"); + } else { + worker->current_response = + (HttpMessage)httpResponseUser(session->user); } delete(credential); @@ -190,8 +193,26 @@ applicationAdapterHttpUpdate(void * _this, void * subject) } if (0 == strcmp("GET", worker->current_request->method)) { + if (0 == strcmp("/user/get/", worker->current_request->path)) { + worker->current_response = + (HttpMessage)httpResponseUser(session->user); + return; + } + +// if (0 == strcmp("/sess/", worker->current_request->path)) { +// if (NO_SESSION_SID == sid +// || NULL == applicationSessionGet(this->application, sid)) { +// sid = applicationSessionStart(this->application, NULL, 0); +// } +// +// worker->current_response = +// (HttpMessage)httpResponseSession( +// applicationSessionGet(this->application, sid)); +// return; +// } + if (0 == strcmp("/randval/", worker->current_request->path)) { - if (NO_SESSION_SID != session->id) { + if (NULL != session->user) { worker->current_response = (HttpMessage)httpResponseRandval( this->application->val->timestamp, diff --git a/src/application/login.c b/src/application/login.c index 02e2246..627c2b7 100644 --- a/src/application/login.c +++ b/src/application/login.c @@ -42,7 +42,7 @@ applicationLogin( size_t i; for (i=0; inauth; i++) { - if (authenticate(this->auth, credential)) { + if (authenticate(this->auth[i], credential)) { session->user = new(User, NULL); switch (credential->type) { diff --git a/src/http/Makefile.am b/src/http/Makefile.am index 0b3a9f7..a96ac38 100644 --- a/src/http/Makefile.am +++ b/src/http/Makefile.am @@ -17,7 +17,8 @@ RESP = response.c \ response/login_form.c \ response/asset.c \ response/randval.c \ - response/session.c + response/session.c \ + response/user.c PARSER = parser.c \ parser/parse.c \ parser/new_message.c \ diff --git a/src/http/response/user.c b/src/http/response/user.c new file mode 100644 index 0000000..2cde03c --- /dev/null +++ b/src/http/response/user.c @@ -0,0 +1,67 @@ +/** + * \file + * + * \author Georg Hopp + * + * \copyright + * Copyright © 2012 Georg Hopp + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include + +#include "class.h" + +#include "http/response.h" +#include "http/message.h" +#include "http/header.h" +#include "session.h" + +#include "utils/memory.h" +#include "hash.h" + +#define RESP_DATA "{\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}" + +HttpResponse +httpResponseUser(User user) +{ + char buffer[200]; + HttpResponse response; + HttpMessage message; + size_t nbuf; + + response = new(HttpResponse, "HTTP/1.1", 200, "OK"); + message = (HttpMessage)response; + + hashAdd(message->header, + new(HttpHeader, CSTRA("Content-Type"), CSTRA("application/json"))); + + nbuf = sprintf(buffer, RESP_DATA, + (NULL != user)? user->email : "", + (NULL != user)? user->firstname : "", + (NULL != user)? user->surname : ""); + + message->nbody = nbuf; + message->body = memMalloc(nbuf); + memcpy(message->body, buffer, nbuf); + + return response; +} + +// vim: set ts=4 sw=4: diff --git a/src/usertest.c b/src/usertest.c index dafbee7..9369c68 100644 --- a/src/usertest.c +++ b/src/usertest.c @@ -58,6 +58,11 @@ main(int argc, char * argv[]) return 1; } + insertUser( + users, + CSTRA("georg"), + CSTRA("Georg"), + CSTRA("Hopp")); insertUser( users, CSTRA("georg@steffers.org"),