GlisWeb framework
_account.registrazione.php
Vai alla documentazione di questo file.
1 <?php
2 
3  // debug
4  // echo 'REGISTRAZIONE';
5  // print_r( $_REQUEST );
6 
7  // se non è impostato uno username, assumo che sia uguale alla mail
8  if( ! isset( $_REQUEST['__signup__']['username'] ) && isset( $_REQUEST['__signup__']['email'] ) ) {
9  $_REQUEST['__signup__']['username'] = $_REQUEST['__signup__']['email'];
10  }
11 
12  // ho ricevuto i dati per la registrazione
13  if( isset( $_REQUEST['__signup__']['username'] ) && ! empty( $_REQUEST['__signup__']['username'] ) ) {
14 
15  // verifico che il nome utente non sia già in uso
16  $utente = mysqlSelectValue( $cf['mysql']['connection'], 'SELECT * FROM account_view WHERE username = ? ',
17  array( array( 's' => $_REQUEST['__signup__']['username'] ) ) );
18 
19  // verifico che la mail non sia già in uso
20  $mail = mysqlSelectValue( $cf['mysql']['connection'], 'SELECT * FROM mail_view WHERE indirizzo = ? ',
21  array( array( 's' => $_REQUEST['__signup__']['email'] ) ) );
22 
23  // se l'utente non esiste già...
24  if( ! $utente & ! $mail ) {
25 
26  // creo il token
27  $tk = $_REQUEST['__signup__']['tk'] = md5( $_REQUEST['__signup__']['username'].$_REQUEST['__signup__']['password'] );
28 
29  // debug
30  // echo $tk;
31 
32  // invio la mail con il link e il token
33  $_REQUEST['__signup__']['activation']['mail']['id'] = queueMailFromTemplate(
34  $cf['mysql']['connection'],
35 # $cf['mail']['tpl']['DEFAULT_REGISTRAZIONE_ACCOUNT'],
36 # $cf['mail']['tpl']['NUOVO_ACCOUNT'],
37  $cf['mail']['tpl']['DEFAULT_NUOVO_ACCOUNT'],
38  array( 'dati' => array_replace_recursive( $_REQUEST['__signup__'], array( 'tk' => $tk ) ), 'ct' => $ct ),
39  strtotime( '+5 minutes' ),
40  array( $_REQUEST['__signup__']['nome'] . ' ' . $_REQUEST['__signup__']['cognome'] => $_REQUEST['__signup__']['email'] ),
41  $cf['localization']['language']['ietf']
42  );
43 
44  // se la mail è stata accodata, imposto il flag per il modulo
45  if( ! empty( $_REQUEST['__signup__']['activation']['mail']['id'] ) ) {
46 
47  $_REQUEST['__signup__']['__tk_sent__']['testo'] = array(
48  'it-IT' => '<p>grazie per esserti registrato! controlla la mail fra qualche minuto per confermare il tuo account</p><p class="mb-0">ora puoi chiudere questa finestra</p>'
49  );
50 
51  } else {
52 
53  $_REQUEST['__signup__']['__err__'][0]['testo'] = array( 'it-IT' => 'abbiamo riscontrato un problema nella creazione del tuo account, prova più tardi' );
54 
55  }
56 
57  } else {
58 
59  // TODO errore
60  if( $utente ) { $_REQUEST['__signup__']['__err__'][0]['testo'] = array('it-IT' => 'errore nome utente già in uso'); }
61  if( $mail ) { $_REQUEST['__signup__']['__err__'][1]['testo'] = array('it-IT' =>'mail già in uso'); }
62  }
63 
64  // scrivo i dati di registrazione su un file temporaneo
65  writeToFile( serialize( $_REQUEST['__signup__'] ), 'var/log/signup/' . $tk . '.txt' );
66 
67  } elseif( isset( $_REQUEST['tk'] ) ) {
68 
69  // se il token è valido
70  if( file_exists( DIRECTORY_BASE . 'var/log/signup/' . $_REQUEST['tk'] . '.txt' ) ) {
71 
72  // recupero i dati
73  $dati = unserialize( readFromFile( 'var/log/signup/' . $_REQUEST['tk'] . '.txt', READ_FILE_AS_STRING ) );
74 
75  // TODO verificare $dati['privacy']['policy'] e $dati['privacy']['account'] e $dati['privacy']['condizioni']
76 
77  // creo l'anagrafica
78  $idAnagrafica = mysqlQuery( $cf['mysql']['connection'], 'INSERT INTO anagrafica ( nome, cognome ) VALUES ( ?, ? )', array( array( 's' => $dati['nome'] ), array( 's' => $dati['cognome'] ) ) );
79 
80  // creo la mail
81  $idMail = mysqlQuery( $cf['mysql']['connection'], 'INSERT INTO mail ( id_anagrafica, indirizzo ) VALUES ( ?, ? )', array( array( 's' => $idAnagrafica ), array( 's' => $dati['email'] ) ) );
82 
83  // associo alle categorie
84  foreach( $cf['registrazione']['default']['categorie'] as $categoria ) {
85 
86  // recupero l'id della categoria
87  $idCategoria = mysqlSelectValue( $cf['mysql']['connection'], 'SELECT id FROM categorie_anagrafica WHERE nome = ?', array( array( 's' => $categoria ) ) );
88 
89  // associo l'account
90  if( ! empty( $idCategoria ) ) {
91  $idAnagraficaCategoria[] = mysqlQuery( $cf['mysql']['connection'], 'INSERT INTO anagrafica_categorie ( id_anagrafica, id_categoria ) VALUES ( ?, ? )', array( array( 's' => $idAnagrafica ), array( 's' => $idCategoria ) ) );
92  }
93 
94  }
95 
96  // creo l'account
97  $idAccount = mysqlQuery( $cf['mysql']['connection'], 'INSERT INTO account ( id_anagrafica, username, password, id_mail, se_attivo ) VALUES ( ?, ?, ?, ?, ? )', array( array( 's' => $idAnagrafica ), array( 's' => $dati['username'] ), array( 's' => md5( $dati['password'] ) ), array( 's' => $idMail ), array( 's' => ( ( $cf['registrazione']['default']['attivo'] === true ) ? 1 : NULL ) ) ) );
98 
99  // associo ai gruppi
100  foreach( $cf['registrazione']['default']['gruppi'] as $gruppo ) {
101 
102  // recupero l'id del gruppo
103  $idGruppo = mysqlSelectValue( $cf['mysql']['connection'], 'SELECT id FROM gruppi WHERE nome = ?', array( array( 's' => $gruppo ) ) );
104 
105  // associo l'account
106  if( ! empty( $idGruppo ) ) {
107  $idAccountGruppo[] = mysqlQuery( $cf['mysql']['connection'], 'INSERT INTO account_gruppi ( id_account, id_gruppo ) VALUES ( ?, ? )', array( array( 's' => $idAccount ), array( 's' => $idGruppo ) ) );
108  }
109 
110  }
111 
112  // debug
113  // echo $idAnagrafica.'/'.$idMail.'/'.$idAccount.'/'.implode( '|', $idAccountGruppo );
114 
115  // se la registrazione è andata a buon fine, imposto il flag per il modulo
116  if( true ) {
117 
118  // imposto il flag per il modulo
119  $_REQUEST['__signup__']['__tk_ok__']['testo'] = array(
120  'it-IT' => '<p>grazie per aver confermato il tuo account! ora puoi effettuare il login</p>'
121  );
122 
123  // associo il carrello della sessione alla persona che ha appena fatto il login
124  if( isset( $dati['carrello'] ) && ! empty( $dati['carrello'] ) ) {
125 
126  //
127  if( isset( $_SESSION['account']['id_anagrafica'] ) && ! empty( $_SESSION['account']['id_anagrafica'] ) ) {
128 
129  // salvataggio di sicurezza
130  $f = 'var/log/carts/cart.' . sprintf( '%08d', $dati['carrello'] ) . '.' . date('Yh') . '.signup.log';
131  appendToFile( $dati['carrello'] . ' -> ' . $_SESSION['account']['id_anagrafica'], $f );
132 
133  // associo
134  mysqlQuery( $cf['mysql']['connection'], 'UPDATE carrelli SET intestazione_id_anagrafica = ? WHERE id = ?',
135  array(
136  array( 's' => $_SESSION['account']['id_anagrafica'] ),
137  array( 's' => $dati['carrello'] )
138  )
139  );
140 
141  }
142 
143  }
144 
145  } else {
146 
147  // TODO errore
148 
149  }
150 
151  } else {
152 
153  // messaggio
154  $_REQUEST['__signup__']['__err__']['testo'] = array(
155  'it-IT' => 'il token non è valido'
156  );
157 
158  }
159 
160  }
161 
162 ?>
const READ_FILE_AS_STRING
appendToFile( $t, $f, &$e=NULL)
aggiunge una stringa a un file
if(isset( $cx['contatti'])) if(isset( $cf['site']['contatti'])) $ct['contatti']
Definition: _035.common.php:24
$f
Definition: _filesystem.php:21
mysqlQuery( $c, $q, $p=false, &$e=array())
$cf['ricerca']['template']
Definition: _030.common.php:7
writeToFile( $t, $f, &$e=NULL)
scrive una stringa su un file
mysqlSelectValue( $c, $q, $p=false, &$e=array())
const DIRECTORY_BASE
Definition: _osm.php:3
if(isset( $_REQUEST['amazonCheckoutSessionId'])) $_SESSION['carrello']
readFromFile( $f, $m=READ_FILE_AS_ARRAY)
legge il contenuto di un file in una stringa o in un array di stringhe
if(! isset( $_REQUEST['__view__'][ $ct['view']['id']]['__extra__']['assegnato'])|| $_REQUEST['__view__'][ $ct['view']['id']]['__extra__']['assegnato']=='__me__') elseif($_REQUEST[ '__view__'][$ct[ 'view'][ 'id']][ '__extra__'][ 'assegnato']=='__nessuno__')
queueMailFromTemplate( $c, $t, $d, $timestamp_invio, $to, $l='it-IT', $to_cc=array(), $to_bcc=array(), $headers=array(), $server=NULL)
accoda una mail utilizzando un template
$_REQUEST['__view__'][ $ct['view']['id']]['__restrict__']['id_progetto']['EQ']