Commit 45dc79e2100d706acb6ce0acc4390b70a4d4fd1e
1 parent
9b32da5e
generalise user handling more so that not only signup and login is possible but …
…also password or userdata changes and further administration.
Showing
14 changed files
with
599 additions
and
47 deletions
... | ... | @@ -76,7 +76,7 @@ $(document).ready(function() { |
76 | 76 | $("#signup").load("/_signup.html", function (){ |
77 | 77 | $("#signup form").submit(function(event) { |
78 | 78 | event.preventDefault(); |
79 | - $.post("/user/", | |
79 | + $.post("/signup/", | |
80 | 80 | $("#signup form").serialize(), |
81 | 81 | $.proxy(sess.loadUserJSON, sess)); |
82 | 82 | $("#signup").addClass("hide"); | ... | ... |
... | ... | @@ -64,6 +64,9 @@ CLASS(Application) { |
64 | 64 | int applicationLogin(Application, Credential, Session); |
65 | 65 | void applicationLogout(Application, Session); |
66 | 66 | int applicationSignup(Application, Credential, User, Session); |
67 | +Uuid applicationCreateUser(Application, Credential, User); | |
68 | +User applicationGetUser(Application, Uuid); | |
69 | +int applicationUpdatePassword(Application, Credential, User); | |
67 | 70 | |
68 | 71 | Session applicationSessionStart(Application); |
69 | 72 | Session applicationSessionGet(Application, const char *); | ... | ... |
... | ... | @@ -5,6 +5,9 @@ APPLICATION = application.c \ |
5 | 5 | login.c \ |
6 | 6 | logout.c \ |
7 | 7 | signup.c \ |
8 | + get_user.c \ | |
9 | + create_user.c \ | |
10 | + update_password.c \ | |
8 | 11 | session_start.c \ |
9 | 12 | session_stop.c \ |
10 | 13 | session_get.c \ |
... | ... | @@ -17,7 +20,11 @@ CONTROLLER = controller/authenticate/create.c \ |
17 | 20 | controller/randval/read.c \ |
18 | 21 | controller/sessinfo/read.c \ |
19 | 22 | controller/user/create.c \ |
20 | - controller/version/read.c | |
23 | + controller/user/read.c \ | |
24 | + controller/signup/create.c \ | |
25 | + controller/version/read.c \ | |
26 | + controller/_validate_password_repeat.c \ | |
27 | + controller/_process_user_create_args.c | |
21 | 28 | |
22 | 29 | AM_CFLAGS += -I../../include/ |
23 | 30 | ... | ... |
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2013 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 | +#define _GNU_SOURCE | |
24 | + | |
25 | +#include "hash.h" | |
26 | +#include "user.h" | |
27 | +#include "auth/credential.h" | |
28 | + | |
29 | +#include "utils/memory.h" | |
30 | +#include "commons.h" | |
31 | + | |
32 | +int _controllerValidatePasswordRepeat(char *, size_t, char *, size_t); | |
33 | + | |
34 | + | |
35 | +int | |
36 | +_controllerProcessUserCreateArgs(Hash args, User * user, Credential * cred) | |
37 | +{ | |
38 | + HashValue email = hashGet(args, CSTRA("email")); | |
39 | + HashValue password = hashGet(args, CSTRA("password")); | |
40 | + HashValue pwrepeat = hashGet(args, CSTRA("pwrepeat")); | |
41 | + HashValue firstname = hashGet(args, CSTRA("firstname")); | |
42 | + HashValue surname = hashGet(args, CSTRA("surname")); | |
43 | + | |
44 | + if ( | |
45 | + NULL == email || | |
46 | + NULL == password || | |
47 | + NULL == pwrepeat || | |
48 | + NULL == firstname || | |
49 | + NULL == surname) | |
50 | + { | |
51 | + return FALSE; | |
52 | + } | |
53 | + | |
54 | + if (! _controllerValidatePasswordRepeat( | |
55 | + password->value, | |
56 | + password->nvalue, | |
57 | + pwrepeat->value, | |
58 | + pwrepeat->nvalue)) | |
59 | + { | |
60 | + return FALSE; | |
61 | + } | |
62 | + | |
63 | + *cred = new(Credential, | |
64 | + CRED_PASSWORD, | |
65 | + (char *)(email->value), email->nvalue, | |
66 | + (char *)(password->value), password->nvalue); | |
67 | + | |
68 | + *user = new(User, | |
69 | + (char *)(email->value), email->nvalue, | |
70 | + (char *)(firstname->value), firstname->nvalue, | |
71 | + (char *)(surname->value), surname->nvalue); | |
72 | + | |
73 | + return TRUE; | |
74 | +} | |
75 | + | |
76 | +// vim: set ts=4 sw=4: | ... | ... |
src/application/controller/_validate_email.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2013 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 | +#define _GNU_SOURCE | |
24 | + | |
25 | +#include "application/application.h" | |
26 | +#include "session.h" | |
27 | +#include "hash.h" | |
28 | +#include "auth/credential.h" | |
29 | +#include "user.h" | |
30 | + | |
31 | +#include "utils/memory.h" | |
32 | + | |
33 | +User | |
34 | +_controllerCreateUserFromArgs(Hash args) | |
35 | +{ | |
36 | + HashValue email; | |
37 | + HashValue firstname; | |
38 | + HashValue surname; | |
39 | + | |
40 | + email = hashGet(args, CSTRA("email")); | |
41 | + firstname = hashGet(args, CSTRA("firstname")); | |
42 | + surname = hashGet(args, CSTRA("surname")); | |
43 | + | |
44 | + if ( | |
45 | + NULL == email || | |
46 | + NULL == firstname || | |
47 | + NULL == surname) | |
48 | + { | |
49 | + return NULL; | |
50 | + } | |
51 | + | |
52 | + return new(User, | |
53 | + (char *)(email->value), email->nvalue, | |
54 | + (char *)(firstname->value), firstname->nvalue, | |
55 | + (char *)(surname->value), surname->nvalue); | |
56 | +} | |
57 | + | |
58 | +// vim: set ts=4 sw=4: | ... | ... |
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2013 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 "hash.h" | |
24 | +#include "auth/credential.h" | |
25 | + | |
26 | +#include "utils/memory.h" | |
27 | +#include "commons.h" | |
28 | + | |
29 | +int | |
30 | +_controllerValidatePassword( | |
31 | + char * password, | |
32 | + size_t npassword, | |
33 | + char * pwrepeat, | |
34 | + size_t npwrepeat, ) | |
35 | +{ | |
36 | + if ( | |
37 | + password->nvalue != pwrepeat->nvalue || | |
38 | + 0 != memcmp(password->value, pwrepeat->value, password->nvalue)) | |
39 | + { | |
40 | + return FALSE; | |
41 | + } | |
42 | + | |
43 | + return TRUE; | |
44 | +} | |
45 | + | |
46 | +// vim: set ts=4 sw=4: | ... | ... |
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2013 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 "hash.h" | |
24 | +#include "auth/credential.h" | |
25 | + | |
26 | +#include "utils/memory.h" | |
27 | +#include "commons.h" | |
28 | + | |
29 | +int | |
30 | +_controllerValidatePasswordRepeat( | |
31 | + char * password, | |
32 | + size_t npassword, | |
33 | + char * pwrepeat, | |
34 | + size_t npwrepeat) | |
35 | +{ | |
36 | + if ( | |
37 | + npassword != npwrepeat || | |
38 | + 0 != memcmp(password, pwrepeat, npassword)) | |
39 | + { | |
40 | + return FALSE; | |
41 | + } | |
42 | + | |
43 | + return TRUE; | |
44 | +} | |
45 | + | |
46 | +// vim: set ts=4 sw=4: | ... | ... |
src/application/controller/signup/create.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2013 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 | +#define _GNU_SOURCE | |
24 | + | |
25 | +#include "application/application.h" | |
26 | +#include "session.h" | |
27 | +#include "hash.h" | |
28 | +#include "auth/credential.h" | |
29 | +#include "user.h" | |
30 | + | |
31 | +#include "utils/memory.h" | |
32 | + | |
33 | +char * controllerCurrentuserRead(Application, Session, Hash); | |
34 | +int _controllerProcessUserCreateArgs(Hash, User *, Credential *); | |
35 | + | |
36 | + | |
37 | +char * | |
38 | +controllerSignupCreate( | |
39 | + Application application, | |
40 | + Session session, | |
41 | + Hash args) | |
42 | +{ | |
43 | + Credential credential; | |
44 | + User user; | |
45 | + char * response_data; | |
46 | + | |
47 | + _controllerProcessUserCreateArgs(args, &user, &credential); | |
48 | + | |
49 | + if (0 == uuidCompare( | |
50 | + uuidZero, | |
51 | + applicationCreateUser(application, credential, user))) | |
52 | + { | |
53 | + response_data = NULL; | |
54 | + } else { | |
55 | + applicationLogin(application, credential, session); | |
56 | + response_data = controllerCurrentuserRead(application, session, NULL); | |
57 | + } | |
58 | + | |
59 | + delete(credential); | |
60 | + delete(user); | |
61 | + | |
62 | + return response_data; | |
63 | + | |
64 | +} | |
65 | + | |
66 | +// vim: set ts=4 sw=4: | ... | ... |
... | ... | @@ -31,6 +31,7 @@ |
31 | 31 | #include "utils/memory.h" |
32 | 32 | |
33 | 33 | char * controllerCurrentuserRead(Application, Session, Hash); |
34 | +int _controllerProcessUserCreateArgs(Hash, User *, Credential *); | |
34 | 35 | |
35 | 36 | char * |
36 | 37 | controllerUserCreate( |
... | ... | @@ -38,54 +39,18 @@ controllerUserCreate( |
38 | 39 | Session session, |
39 | 40 | Hash args) |
40 | 41 | { |
41 | - HashValue email; | |
42 | - HashValue password; | |
43 | - HashValue pwrepeat; | |
44 | - HashValue firstname; | |
45 | - HashValue surname; | |
42 | + Credential credential; | |
43 | + User user; | |
44 | + char * response_data; | |
46 | 45 | |
47 | - Credential credential; | |
48 | - User user; | |
46 | + _controllerProcessUserCreateArgs(args, &user, &credential); | |
49 | 47 | |
50 | - char * response_data; | |
51 | - | |
52 | - email = hashGet(args, CSTRA("email")); | |
53 | - password = hashGet(args, CSTRA("password")); | |
54 | - pwrepeat = hashGet(args, CSTRA("pwrepeat")); | |
55 | - firstname = hashGet(args, CSTRA("firstname")); | |
56 | - surname = hashGet(args, CSTRA("surname")); | |
57 | - | |
58 | - if ( | |
59 | - NULL == email || | |
60 | - NULL == password || | |
61 | - NULL == pwrepeat || | |
62 | - NULL == firstname || | |
63 | - NULL == surname) | |
64 | - { | |
65 | - return NULL; | |
66 | - } | |
67 | - | |
68 | - if ( | |
69 | - password->nvalue != pwrepeat->nvalue || | |
70 | - 0 != memcmp(password->value, pwrepeat->value, password->nvalue)) | |
48 | + if (0 == uuidCompare( | |
49 | + uuidZero, | |
50 | + applicationCreateUser(application, credential, user))) | |
71 | 51 | { |
72 | - return NULL; | |
73 | - } | |
74 | - | |
75 | - credential = new(Credential, | |
76 | - CRED_PASSWORD, | |
77 | - (char *)(email->value), email->nvalue, | |
78 | - (char *)(password->value), password->nvalue); | |
79 | - | |
80 | - user = new(User, | |
81 | - (char *)(email->value), email->nvalue, | |
82 | - (char *)(firstname->value), firstname->nvalue, | |
83 | - (char *)(surname->value), surname->nvalue); | |
84 | - | |
85 | - if (! applicationSignup(application, credential, user, session)) { | |
86 | 52 | response_data = NULL; |
87 | 53 | } else { |
88 | - applicationLogin(application, credential, session); | |
89 | 54 | response_data = controllerCurrentuserRead(application, session, NULL); |
90 | 55 | } |
91 | 56 | ... | ... |
src/application/controller/user/read.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2013 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 | +#define _GNU_SOURCE | |
24 | + | |
25 | +#include <sys/types.h> | |
26 | +#include <stdio.h> | |
27 | + | |
28 | +#include "class.h" | |
29 | +#include "application/application.h" | |
30 | +#include "session.h" | |
31 | +#include "hash.h" | |
32 | + | |
33 | +#include "utils/memory.h" | |
34 | + | |
35 | + | |
36 | +#define USER_JSON \ | |
37 | + "{\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}" | |
38 | + | |
39 | +char * | |
40 | +controllerUserRead(Application app, Session sess, Hash args) | |
41 | +{ | |
42 | + char * buffer; | |
43 | + size_t nbuffer; | |
44 | + HashValue id = hashGet(args, CSTRA("id")); | |
45 | + Uuid search = uuidParse(id->value); | |
46 | + User user = applicationGetUser(app, search); | |
47 | + | |
48 | + nbuffer = snprintf(NULL, 0, USER_JSON, | |
49 | + user->email, | |
50 | + user->firstname, | |
51 | + user->surname); | |
52 | + buffer = memMalloc(nbuffer); | |
53 | + nbuffer = sprintf(buffer, USER_JSON, | |
54 | + user->email, | |
55 | + user->firstname, | |
56 | + user->surname); | |
57 | + | |
58 | + return buffer; | |
59 | +} | |
60 | + | |
61 | +// vim: set ts=4 sw=4: | ... | ... |
src/application/create_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 | +#define _GNU_SOURCE | |
24 | + | |
25 | +#include <stdio.h> | |
26 | +#include <stdlib.h> | |
27 | +#include <sys/types.h> | |
28 | + | |
29 | +#include "class.h" | |
30 | +#include "auth.h" | |
31 | +#include "user.h" | |
32 | +#include "uuid.h" | |
33 | +#include "storage/storage.h" | |
34 | +#include "application/application.h" | |
35 | + | |
36 | +#include "interface/serializable.h" | |
37 | +#include "interface/indexable.h" | |
38 | + | |
39 | +#include "utils/memory.h" | |
40 | +#include "commons.h" | |
41 | + | |
42 | +Uuid | |
43 | +applicationCreateUser( | |
44 | + Application this, | |
45 | + Credential cred, | |
46 | + User user) | |
47 | +{ | |
48 | + char * user_serialized; | |
49 | + size_t nuser_serialized; | |
50 | + Uuid index; | |
51 | + | |
52 | + index = indexUuid(user, this->user_namespace); | |
53 | + serialize(user, (unsigned char **)&user_serialized, &nuser_serialized); | |
54 | + | |
55 | + if (SPR_OK != storagePut( | |
56 | + this->users, | |
57 | + (char *)(index->uuid).value, | |
58 | + sizeof((index->uuid).value), | |
59 | + user_serialized, | |
60 | + nuser_serialized)) | |
61 | + { | |
62 | + return uuidZero; | |
63 | + } | |
64 | + | |
65 | + if (! applicationUpdatePassword(this, cred, user)) { | |
66 | + /** | |
67 | + * \todo | |
68 | + * error handling is missing here | |
69 | + */ | |
70 | + storageDelete( | |
71 | + this->users, | |
72 | + (char *)(index->uuid).value, | |
73 | + sizeof((index->uuid).value)); | |
74 | + | |
75 | + return uuidZero; | |
76 | + } | |
77 | + | |
78 | + return index; | |
79 | +} | |
80 | + | |
81 | +// vim: set ts=4 sw=4: | ... | ... |
src/application/get_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 <stdio.h> | |
24 | +#include <stdlib.h> | |
25 | +#include <sys/types.h> | |
26 | + | |
27 | +#include "class.h" | |
28 | +#include "auth.h" | |
29 | +#include "user.h" | |
30 | +#include "uuid.h" | |
31 | +#include "storage/storage.h" | |
32 | +#include "application/application.h" | |
33 | + | |
34 | +#include "interface/serializable.h" | |
35 | +#include "interface/indexable.h" | |
36 | + | |
37 | +#include "utils/memory.h" | |
38 | +#include "commons.h" | |
39 | + | |
40 | +User | |
41 | +applicationGetUser(Application this, Uuid uuid) | |
42 | +{ | |
43 | + char * user_serialized; | |
44 | + size_t nuser_serialized; | |
45 | + User user = NULL; | |
46 | + | |
47 | + storageGet( | |
48 | + this->users, | |
49 | + (char *)(uuid->uuid).value, | |
50 | + sizeof((uuid->uuid).value), | |
51 | + &user_serialized, | |
52 | + &nuser_serialized); | |
53 | + | |
54 | + if (NULL != user_serialized) { | |
55 | + unserialize( | |
56 | + user, | |
57 | + (unsigned char *)user_serialized, | |
58 | + nuser_serialized); | |
59 | + MEM_FREE(user_serialized); | |
60 | + } | |
61 | + | |
62 | + return user; | |
63 | +} | |
64 | + | |
65 | +// vim: set ts=4 sw=4: | ... | ... |
src/application/update_password.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 | +#define _GNU_SOURCE | |
24 | + | |
25 | +#include <stdio.h> | |
26 | +#include <stdlib.h> | |
27 | +#include <sys/types.h> | |
28 | + | |
29 | +#include "class.h" | |
30 | +#include "auth.h" | |
31 | +#include "user.h" | |
32 | +#include "storage/storage.h" | |
33 | +#include "application/application.h" | |
34 | + | |
35 | +#include "interface/indexable.h" | |
36 | + | |
37 | +#include "utils/memory.h" | |
38 | +#include "commons.h" | |
39 | + | |
40 | +int | |
41 | +applicationUpdatePassword( | |
42 | + Application this, | |
43 | + Credential cred, | |
44 | + User user) | |
45 | +{ | |
46 | + unsigned char hash_data[SALT_SIZE+HASH_SIZE]; | |
47 | + unsigned char * salt = NULL; | |
48 | + unsigned char * hash = hash_data+SALT_SIZE; | |
49 | + Uuid index; | |
50 | + | |
51 | + index = indexUuid(user, this->user_namespace); | |
52 | + | |
53 | + if (FALSE == hash_pw( | |
54 | + CRED_PWD(cred).pass, | |
55 | + CRED_PWD(cred).npass, | |
56 | + hash, | |
57 | + &salt)) { | |
58 | + return FALSE; | |
59 | + } | |
60 | + | |
61 | + memcpy(hash_data, salt, SALT_SIZE); | |
62 | + MEM_FREE(salt); | |
63 | + | |
64 | + storageUpdate( | |
65 | + this->passwords, | |
66 | + (char *)(index->uuid).value, | |
67 | + sizeof((index->uuid).value), | |
68 | + (char *)hash_data, | |
69 | + SALT_SIZE + HASH_SIZE); | |
70 | + | |
71 | + return TRUE; | |
72 | +} | |
73 | + | |
74 | +// vim: set ts=4 sw=4: | ... | ... |
... | ... | @@ -265,8 +265,12 @@ routerRoute( |
265 | 265 | break; |
266 | 266 | } |
267 | 267 | |
268 | - response = httpResponseJson(response_data, strlen(response_data)); | |
269 | - MEM_FREE(response_data); | |
268 | + if (NULL != response_data) { | |
269 | + response = httpResponseJson(response_data, strlen(response_data)); | |
270 | + MEM_FREE(response_data); | |
271 | + } else { | |
272 | + response = httpResponse404(); | |
273 | + } | |
270 | 274 | |
271 | 275 | return response; |
272 | 276 | } | ... | ... |
Please
register
or
login
to post a comment