From a8d1b3f4e268d179c8d18d5251f37d1956af7b59 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 7 Aug 2010 17:07:39 +0200 Subject: [PATCH] Changed fields names. Added new fields to completly manage the user. --- data/autedb.sql | 22 ++++++++++++++-------- src/aute_db.c | 31 ++++++++++++++++--------------- tests/test.c | 2 +- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/data/autedb.sql b/data/autedb.sql index e1fcc83..2efe6ab 100644 --- a/data/autedb.sql +++ b/data/autedb.sql @@ -1,10 +1,16 @@ -CREATE TABLE utenti -( - codice varchar(20) NOT NULL DEFAULT '', - "password" varchar(32) DEFAULT '', - status char(1) DEFAULT '', - CONSTRAINT utenti_pkey PRIMARY KEY (codice) +CREATE TABLE users ( + code varchar(20) NOT NULL DEFAULT '', + password varchar(32) DEFAULT '', + surname varchar(100) DEFAULT '', + name varchar(100) DEFAULT '', + enabled bool, + last_access time, + password_expiration time, + description text DEFAULT '', + status varchar(1) DEFAULT '', + CONSTRAINT users_pkey PRIMARY KEY (code) ); -/* utente iniziale con password 'root' */ -INSERT INTO utenti VALUES ('root', '63a9f0ea7bb98050796b649e85481845', ''); +/* initial user with password 'root' */ +INSERT INTO utenti (codice, password, cognome, abilitato, status) +VALUES ('root', '63a9f0ea7bb98050796b649e85481845', 'Root', TRUE, ''); diff --git a/src/aute_db.c b/src/aute_db.c index d7c7b40..e00aa4e 100644 --- a/src/aute_db.c +++ b/src/aute_db.c @@ -132,10 +132,11 @@ static gchar gdaex = gdaex_new_from_string (cnc_string); if (gdaex == NULL) return NULL; - sql = g_strdup_printf ("SELECT codice FROM utenti " - "WHERE codice = '%s' AND " - "password = '%s' AND " - "status <> 'E'", + sql = g_strdup_printf ("SELECT code" + " FROM users" + " WHERE code = '%s'" + " AND password = '%s'" + " AND status <> 'E'", gdaex_strescape (utente, NULL), gdaex_strescape (cifra_password (password), NULL)); dm = gdaex_query (gdaex, sql); @@ -145,7 +146,7 @@ static gchar return NULL; } - utente = g_strstrip (g_strdup (gdaex_data_model_get_field_value_stringify_at (dm, 0, "codice"))); + utente = g_strstrip (g_strdup (gdaex_data_model_get_field_value_stringify_at (dm, 0, "code"))); if (strcmp (utente, "") != 0 && gtk_expander_get_expanded (GTK_EXPANDER (exp_cambio))) @@ -164,9 +165,9 @@ static gchar else { /* cambio la password */ - sql = g_strdup_printf ("UPDATE utenti " - "SET password = '%s' " - "WHERE codice = '%s'", + sql = g_strdup_printf ("UPDATE users" + " SET password = '%s'" + " WHERE code = '%s'", gdaex_strescape (cifra_password (password_nuova), NULL), gdaex_strescape (utente, NULL)); if (gdaex_execute (gdaex, sql) == -1) @@ -312,20 +313,20 @@ crea_utente (GSList *parameters, const gchar *codice, const gchar *password) if (gdaex == NULL) return FALSE; /* controllo se esiste gia' */ - sql = g_strdup_printf ("SELECT codice FROM utenti WHERE codice = '%s'", + sql = g_strdup_printf ("SELECT code FROM users WHERE code = '%s'", gdaex_strescape (codice_, NULL)); dm = gdaex_query (gdaex, sql); if (dm != NULL && gda_data_model_get_n_rows (dm) > 0) { /* aggiorno l'utente */ - sql = g_strdup_printf ("UPDATE utenti SET password = '%s' WHERE codice = '%s'", + sql = g_strdup_printf ("UPDATE users SET password = '%s' WHERE code = '%s'", gdaex_strescape (cifra_password (password_), NULL), gdaex_strescape (codice_, NULL)); } else { /* creo l'utente */ - sql = g_strdup_printf ("INSERT INTO utenti VALUES ('%s', '%s', '')", + sql = g_strdup_printf ("INSERT INTO users VALUES ('%s', '%s', '')", gdaex_strescape (codice_, NULL), gdaex_strescape (cifra_password (password_), NULL)); } @@ -402,20 +403,20 @@ modifica_utente (GSList *parameters, const gchar *codice, const gchar *password) if (gdaex == NULL) return FALSE; /* controllo se non esiste */ - sql = g_strdup_printf ("SELECT codice FROM utenti WHERE codice = '%s'", + sql = g_strdup_printf ("SELECT code FROM users WHERE code = '%s'", gdaex_strescape (codice_, NULL)); dm = gdaex_query (gdaex, sql); if (dm == NULL || gda_data_model_get_n_rows (dm) <= 0) { /* creo l'utente */ - sql = g_strdup_printf ("INSERT INTO utenti VALUES ('%s', '%s', '')", + sql = g_strdup_printf ("INSERT INTO users VALUES ('%s', '%s', '')", gdaex_strescape (codice_, NULL), gdaex_strescape (cifra_password (password_), NULL)); } else { /* aggiorno l'utente */ - sql = g_strdup_printf ("UPDATE utenti SET password = '%s' WHERE codice = '%s'", + sql = g_strdup_printf ("UPDATE users SET password = '%s' WHERE code = '%s'", gdaex_strescape (cifra_password (password_), NULL), gdaex_strescape (codice_, NULL)); } @@ -488,7 +489,7 @@ elimina_utente (GSList *parameters, const gchar *codice) if (gdaex == NULL) return FALSE; /* elimino _logicamente_ l'utente */ - sql = g_strdup_printf ("UPDATE utenti SET status = 'E' WHERE codice = '%s'", + sql = g_strdup_printf ("UPDATE users SET status = 'E' WHERE code = '%s'", gdaex_strescape (codice_, NULL)); return (gdaex_execute (gdaex, sql) >= 0); diff --git a/tests/test.c b/tests/test.c index 46d470d..d299560 100644 --- a/tests/test.c +++ b/tests/test.c @@ -35,7 +35,7 @@ main (int argc, char **argv) aute_set_config (aute, params); - g_fprintf (stderr, "Utente %s\n", aute_autentica (aute)); + g_message ("User %s\n", aute_autentica (aute)); return 0; } -- 2.49.0