Commit 19c59fd0c6030a29e7b6119f342efc452da92a9d
1 parent
463583c5
use user class to load and get user informations.
Showing
7 changed files
with
112 additions
and
7 deletions
... | ... | @@ -8,6 +8,9 @@ function Session(sId) |
8 | 8 | this.timeout = 0; |
9 | 9 | this.timeleft = 0; |
10 | 10 | this.username = ""; |
11 | + this.email = ""; | |
12 | + this.firstname = ""; | |
13 | + this.surname = ""; | |
11 | 14 | this.interval = null; |
12 | 15 | |
13 | 16 | this.draw(); |
... | ... | @@ -18,12 +21,15 @@ Session.prototype.loadJSON = function(data) |
18 | 21 | this.stop(); |
19 | 22 | |
20 | 23 | this.id = ("0" == data.id)? "none" : data.id; |
21 | - this.timeout = data.timeout * 10; | |
22 | - this.timeleft = data.timeleft * 10; | |
23 | - this.username = data.username; | |
24 | + //this.timeout = data.timeout * 10; | |
25 | + //this.timeleft = data.timeleft * 10; | |
26 | + //this.username = data.username; | |
27 | + this.email = data.email; | |
28 | + this.firstname = data.firstname; | |
29 | + this.surname = data.surname; | |
24 | 30 | |
25 | 31 | this.eSid.empty().append(this.id); |
26 | - $("#main p:eq(1) span:eq(0)").empty().append(" " + this.username); | |
32 | + $("#main p:eq(1) span:eq(0)").empty().append(" " + this.firstname + " " + this.surname); | |
27 | 33 | |
28 | 34 | this.draw(); |
29 | 35 | if (0 < this.timeleft) |
... | ... | @@ -68,6 +74,9 @@ Session.prototype.stop = function() |
68 | 74 | this.timeout = 0; |
69 | 75 | this.timeleft = 0; |
70 | 76 | this.username = ""; |
77 | + this.email = ""; | |
78 | + this.firstname = ""; | |
79 | + this.surname = ""; | |
71 | 80 | |
72 | 81 | this.eSid.empty().append(this.id); |
73 | 82 | $("#main p:eq(1) span:eq(0)").empty().append(" " + this.username); | ... | ... |
... | ... | @@ -30,6 +30,7 @@ |
30 | 30 | #include "class.h" |
31 | 31 | #include "http/message.h" |
32 | 32 | #include "session.h" |
33 | +#include "user.h" | |
33 | 34 | #include "asset.h" |
34 | 35 | |
35 | 36 | |
... | ... | @@ -51,6 +52,7 @@ HttpResponse httpResponseMe(); |
51 | 52 | HttpResponse httpResponseLoginForm(); |
52 | 53 | HttpResponse httpResponseRandval(time_t, int); |
53 | 54 | HttpResponse httpResponseSession(Session); |
55 | +HttpResponse httpResponseUser(User); | |
54 | 56 | HttpResponse httpResponseAsset(const char *, size_t); |
55 | 57 | |
56 | 58 | #endif // __HTTP_RESPONSE_H__ | ... | ... |
... | ... | @@ -151,6 +151,9 @@ loginAdapter(Application application, HttpWorker worker, Session session) |
151 | 151 | if (! applicationLogin(application, credential, session)) { |
152 | 152 | worker->current_response = |
153 | 153 | new(HttpResponse, "HTTP/1.1", 403, "Forbidden"); |
154 | + } else { | |
155 | + worker->current_response = | |
156 | + (HttpMessage)httpResponseUser(session->user); | |
154 | 157 | } |
155 | 158 | |
156 | 159 | delete(credential); |
... | ... | @@ -190,8 +193,26 @@ applicationAdapterHttpUpdate(void * _this, void * subject) |
190 | 193 | } |
191 | 194 | |
192 | 195 | if (0 == strcmp("GET", worker->current_request->method)) { |
196 | + if (0 == strcmp("/user/get/", worker->current_request->path)) { | |
197 | + worker->current_response = | |
198 | + (HttpMessage)httpResponseUser(session->user); | |
199 | + return; | |
200 | + } | |
201 | + | |
202 | +// if (0 == strcmp("/sess/", worker->current_request->path)) { | |
203 | +// if (NO_SESSION_SID == sid | |
204 | +// || NULL == applicationSessionGet(this->application, sid)) { | |
205 | +// sid = applicationSessionStart(this->application, NULL, 0); | |
206 | +// } | |
207 | +// | |
208 | +// worker->current_response = | |
209 | +// (HttpMessage)httpResponseSession( | |
210 | +// applicationSessionGet(this->application, sid)); | |
211 | +// return; | |
212 | +// } | |
213 | + | |
193 | 214 | if (0 == strcmp("/randval/", worker->current_request->path)) { |
194 | - if (NO_SESSION_SID != session->id) { | |
215 | + if (NULL != session->user) { | |
195 | 216 | worker->current_response = |
196 | 217 | (HttpMessage)httpResponseRandval( |
197 | 218 | this->application->val->timestamp, | ... | ... |
src/http/response/user.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2012 Georg Hopp | |
8 | + * | |
9 | + * This program is free software: you can redistribute it and/or modify | |
10 | + * it under the terms of the GNU General Public License as published by | |
11 | + * the Free Software Foundation, either version 3 of the License, or | |
12 | + * (at your option) any later version. | |
13 | + * | |
14 | + * This program is distributed in the hope that it will be useful, | |
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | + * GNU General Public License for more details. | |
18 | + * | |
19 | + * You should have received a copy of the GNU General Public License | |
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | + */ | |
22 | + | |
23 | +#include <stdlib.h> | |
24 | +#include <string.h> | |
25 | +#include <stdio.h> | |
26 | +#include <time.h> | |
27 | +#include <sys/types.h> | |
28 | + | |
29 | +#include "class.h" | |
30 | + | |
31 | +#include "http/response.h" | |
32 | +#include "http/message.h" | |
33 | +#include "http/header.h" | |
34 | +#include "session.h" | |
35 | + | |
36 | +#include "utils/memory.h" | |
37 | +#include "hash.h" | |
38 | + | |
39 | +#define RESP_DATA "{\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}" | |
40 | + | |
41 | +HttpResponse | |
42 | +httpResponseUser(User user) | |
43 | +{ | |
44 | + char buffer[200]; | |
45 | + HttpResponse response; | |
46 | + HttpMessage message; | |
47 | + size_t nbuf; | |
48 | + | |
49 | + response = new(HttpResponse, "HTTP/1.1", 200, "OK"); | |
50 | + message = (HttpMessage)response; | |
51 | + | |
52 | + hashAdd(message->header, | |
53 | + new(HttpHeader, CSTRA("Content-Type"), CSTRA("application/json"))); | |
54 | + | |
55 | + nbuf = sprintf(buffer, RESP_DATA, | |
56 | + (NULL != user)? user->email : "", | |
57 | + (NULL != user)? user->firstname : "", | |
58 | + (NULL != user)? user->surname : ""); | |
59 | + | |
60 | + message->nbody = nbuf; | |
61 | + message->body = memMalloc(nbuf); | |
62 | + memcpy(message->body, buffer, nbuf); | |
63 | + | |
64 | + return response; | |
65 | +} | |
66 | + | |
67 | +// vim: set ts=4 sw=4: | ... | ... |
Please
register
or
login
to post a comment