Browse Source
generalise user handling more so that not only signup and login is possible but also password or userdata changes and further administration.
v0.1.8
generalise user handling more so that not only signup and login is possible but also password or userdata changes and further administration.
v0.1.8
14 changed files with 599 additions and 47 deletions
-
2assets/js/init.js
-
3include/application/application.h
-
9src/application/Makefile.am
-
76src/application/controller/_process_user_create_args.c
-
58src/application/controller/_validate_email.c
-
46src/application/controller/_validate_password.c
-
46src/application/controller/_validate_password_repeat.c
-
66src/application/controller/signup/create.c
-
51src/application/controller/user/create.c
-
61src/application/controller/user/read.c
-
81src/application/create_user.c
-
65src/application/get_user.c
-
74src/application/update_password.c
-
8src/router/route.c
@ -0,0 +1,76 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2013 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#define _GNU_SOURCE |
|||
|
|||
#include "hash.h" |
|||
#include "user.h" |
|||
#include "auth/credential.h" |
|||
|
|||
#include "utils/memory.h" |
|||
#include "commons.h" |
|||
|
|||
int _controllerValidatePasswordRepeat(char *, size_t, char *, size_t); |
|||
|
|||
|
|||
int |
|||
_controllerProcessUserCreateArgs(Hash args, User * user, Credential * cred) |
|||
{ |
|||
HashValue email = hashGet(args, CSTRA("email")); |
|||
HashValue password = hashGet(args, CSTRA("password")); |
|||
HashValue pwrepeat = hashGet(args, CSTRA("pwrepeat")); |
|||
HashValue firstname = hashGet(args, CSTRA("firstname")); |
|||
HashValue surname = hashGet(args, CSTRA("surname")); |
|||
|
|||
if ( |
|||
NULL == email || |
|||
NULL == password || |
|||
NULL == pwrepeat || |
|||
NULL == firstname || |
|||
NULL == surname) |
|||
{ |
|||
return FALSE; |
|||
} |
|||
|
|||
if (! _controllerValidatePasswordRepeat( |
|||
password->value, |
|||
password->nvalue, |
|||
pwrepeat->value, |
|||
pwrepeat->nvalue)) |
|||
{ |
|||
return FALSE; |
|||
} |
|||
|
|||
*cred = new(Credential, |
|||
CRED_PASSWORD, |
|||
(char *)(email->value), email->nvalue, |
|||
(char *)(password->value), password->nvalue); |
|||
|
|||
*user = new(User, |
|||
(char *)(email->value), email->nvalue, |
|||
(char *)(firstname->value), firstname->nvalue, |
|||
(char *)(surname->value), surname->nvalue); |
|||
|
|||
return TRUE; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,58 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2013 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#define _GNU_SOURCE |
|||
|
|||
#include "application/application.h" |
|||
#include "session.h" |
|||
#include "hash.h" |
|||
#include "auth/credential.h" |
|||
#include "user.h" |
|||
|
|||
#include "utils/memory.h" |
|||
|
|||
User |
|||
_controllerCreateUserFromArgs(Hash args) |
|||
{ |
|||
HashValue email; |
|||
HashValue firstname; |
|||
HashValue surname; |
|||
|
|||
email = hashGet(args, CSTRA("email")); |
|||
firstname = hashGet(args, CSTRA("firstname")); |
|||
surname = hashGet(args, CSTRA("surname")); |
|||
|
|||
if ( |
|||
NULL == email || |
|||
NULL == firstname || |
|||
NULL == surname) |
|||
{ |
|||
return NULL; |
|||
} |
|||
|
|||
return new(User, |
|||
(char *)(email->value), email->nvalue, |
|||
(char *)(firstname->value), firstname->nvalue, |
|||
(char *)(surname->value), surname->nvalue); |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,46 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2013 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "hash.h" |
|||
#include "auth/credential.h" |
|||
|
|||
#include "utils/memory.h" |
|||
#include "commons.h" |
|||
|
|||
int |
|||
_controllerValidatePassword( |
|||
char * password, |
|||
size_t npassword, |
|||
char * pwrepeat, |
|||
size_t npwrepeat, ) |
|||
{ |
|||
if ( |
|||
password->nvalue != pwrepeat->nvalue || |
|||
0 != memcmp(password->value, pwrepeat->value, password->nvalue)) |
|||
{ |
|||
return FALSE; |
|||
} |
|||
|
|||
return TRUE; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,46 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2013 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "hash.h" |
|||
#include "auth/credential.h" |
|||
|
|||
#include "utils/memory.h" |
|||
#include "commons.h" |
|||
|
|||
int |
|||
_controllerValidatePasswordRepeat( |
|||
char * password, |
|||
size_t npassword, |
|||
char * pwrepeat, |
|||
size_t npwrepeat) |
|||
{ |
|||
if ( |
|||
npassword != npwrepeat || |
|||
0 != memcmp(password, pwrepeat, npassword)) |
|||
{ |
|||
return FALSE; |
|||
} |
|||
|
|||
return TRUE; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,66 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2013 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#define _GNU_SOURCE |
|||
|
|||
#include "application/application.h" |
|||
#include "session.h" |
|||
#include "hash.h" |
|||
#include "auth/credential.h" |
|||
#include "user.h" |
|||
|
|||
#include "utils/memory.h" |
|||
|
|||
char * controllerCurrentuserRead(Application, Session, Hash); |
|||
int _controllerProcessUserCreateArgs(Hash, User *, Credential *); |
|||
|
|||
|
|||
char * |
|||
controllerSignupCreate( |
|||
Application application, |
|||
Session session, |
|||
Hash args) |
|||
{ |
|||
Credential credential; |
|||
User user; |
|||
char * response_data; |
|||
|
|||
_controllerProcessUserCreateArgs(args, &user, &credential); |
|||
|
|||
if (0 == uuidCompare( |
|||
uuidZero, |
|||
applicationCreateUser(application, credential, user))) |
|||
{ |
|||
response_data = NULL; |
|||
} else { |
|||
applicationLogin(application, credential, session); |
|||
response_data = controllerCurrentuserRead(application, session, NULL); |
|||
} |
|||
|
|||
delete(credential); |
|||
delete(user); |
|||
|
|||
return response_data; |
|||
|
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,61 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2013 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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#define _GNU_SOURCE |
|||
|
|||
#include <sys/types.h> |
|||
#include <stdio.h> |
|||
|
|||
#include "class.h" |
|||
#include "application/application.h" |
|||
#include "session.h" |
|||
#include "hash.h" |
|||
|
|||
#include "utils/memory.h" |
|||
|
|||
|
|||
#define USER_JSON \ |
|||
"{\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}" |
|||
|
|||
char * |
|||
controllerUserRead(Application app, Session sess, Hash args) |
|||
{ |
|||
char * buffer; |
|||
size_t nbuffer; |
|||
HashValue id = hashGet(args, CSTRA("id")); |
|||
Uuid search = uuidParse(id->value); |
|||
User user = applicationGetUser(app, search); |
|||
|
|||
nbuffer = snprintf(NULL, 0, USER_JSON, |
|||
user->email, |
|||
user->firstname, |
|||
user->surname); |
|||
buffer = memMalloc(nbuffer); |
|||
nbuffer = sprintf(buffer, USER_JSON, |
|||
user->email, |
|||
user->firstname, |
|||
user->surname); |
|||
|
|||
return buffer; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,81 @@ |
|||
/** |
|||
* \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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#define _GNU_SOURCE |
|||
|
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <sys/types.h> |
|||
|
|||
#include "class.h" |
|||
#include "auth.h" |
|||
#include "user.h" |
|||
#include "uuid.h" |
|||
#include "storage/storage.h" |
|||
#include "application/application.h" |
|||
|
|||
#include "interface/serializable.h" |
|||
#include "interface/indexable.h" |
|||
|
|||
#include "utils/memory.h" |
|||
#include "commons.h" |
|||
|
|||
Uuid |
|||
applicationCreateUser( |
|||
Application this, |
|||
Credential cred, |
|||
User user) |
|||
{ |
|||
char * user_serialized; |
|||
size_t nuser_serialized; |
|||
Uuid index; |
|||
|
|||
index = indexUuid(user, this->user_namespace); |
|||
serialize(user, (unsigned char **)&user_serialized, &nuser_serialized); |
|||
|
|||
if (SPR_OK != storagePut( |
|||
this->users, |
|||
(char *)(index->uuid).value, |
|||
sizeof((index->uuid).value), |
|||
user_serialized, |
|||
nuser_serialized)) |
|||
{ |
|||
return uuidZero; |
|||
} |
|||
|
|||
if (! applicationUpdatePassword(this, cred, user)) { |
|||
/** |
|||
* \todo |
|||
* error handling is missing here |
|||
*/ |
|||
storageDelete( |
|||
this->users, |
|||
(char *)(index->uuid).value, |
|||
sizeof((index->uuid).value)); |
|||
|
|||
return uuidZero; |
|||
} |
|||
|
|||
return index; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,65 @@ |
|||
/** |
|||
* \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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <sys/types.h> |
|||
|
|||
#include "class.h" |
|||
#include "auth.h" |
|||
#include "user.h" |
|||
#include "uuid.h" |
|||
#include "storage/storage.h" |
|||
#include "application/application.h" |
|||
|
|||
#include "interface/serializable.h" |
|||
#include "interface/indexable.h" |
|||
|
|||
#include "utils/memory.h" |
|||
#include "commons.h" |
|||
|
|||
User |
|||
applicationGetUser(Application this, Uuid uuid) |
|||
{ |
|||
char * user_serialized; |
|||
size_t nuser_serialized; |
|||
User user = NULL; |
|||
|
|||
storageGet( |
|||
this->users, |
|||
(char *)(uuid->uuid).value, |
|||
sizeof((uuid->uuid).value), |
|||
&user_serialized, |
|||
&nuser_serialized); |
|||
|
|||
if (NULL != user_serialized) { |
|||
unserialize( |
|||
user, |
|||
(unsigned char *)user_serialized, |
|||
nuser_serialized); |
|||
MEM_FREE(user_serialized); |
|||
} |
|||
|
|||
return user; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,74 @@ |
|||
/** |
|||
* \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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#define _GNU_SOURCE |
|||
|
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <sys/types.h> |
|||
|
|||
#include "class.h" |
|||
#include "auth.h" |
|||
#include "user.h" |
|||
#include "storage/storage.h" |
|||
#include "application/application.h" |
|||
|
|||
#include "interface/indexable.h" |
|||
|
|||
#include "utils/memory.h" |
|||
#include "commons.h" |
|||
|
|||
int |
|||
applicationUpdatePassword( |
|||
Application this, |
|||
Credential cred, |
|||
User user) |
|||
{ |
|||
unsigned char hash_data[SALT_SIZE+HASH_SIZE]; |
|||
unsigned char * salt = NULL; |
|||
unsigned char * hash = hash_data+SALT_SIZE; |
|||
Uuid index; |
|||
|
|||
index = indexUuid(user, this->user_namespace); |
|||
|
|||
if (FALSE == hash_pw( |
|||
CRED_PWD(cred).pass, |
|||
CRED_PWD(cred).npass, |
|||
hash, |
|||
&salt)) { |
|||
return FALSE; |
|||
} |
|||
|
|||
memcpy(hash_data, salt, SALT_SIZE); |
|||
MEM_FREE(salt); |
|||
|
|||
storageUpdate( |
|||
this->passwords, |
|||
(char *)(index->uuid).value, |
|||
sizeof((index->uuid).value), |
|||
(char *)hash_data, |
|||
SALT_SIZE + HASH_SIZE); |
|||
|
|||
return TRUE; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue