@@ -43,7 +43,9 @@ class User extends Model implements Authenticatable
4343 * @var array
4444 */
4545 protected $ fillable = [
46- 'name ' , 'email ' , 'password ' ,
46+ 'name ' ,
47+ 'email ' ,
48+ 'password ' ,
4749 ];
4850
4951 protected $ is_admin ;
@@ -56,7 +58,8 @@ class User extends Model implements Authenticatable
5658 * @var array
5759 */
5860 protected $ hidden = [
59- 'password ' , 'remember_token ' ,
61+ 'password ' ,
62+ 'remember_token ' ,
6063 ];
6164
6265 /**
@@ -127,11 +130,11 @@ public function getSediAttribute()
127130 $ database = database ();
128131
129132 // Estraggo le sedi dell'utente loggato
130- $ sedi = $ database ->fetchArray ('SELECT idsede FROM zz_user_sedi WHERE id_user= ' . prepare ($ this ->id ));
133+ $ sedi = $ database ->fetchArray ('SELECT idsede FROM zz_user_sedi WHERE id_user= ' . prepare ($ this ->id ));
131134
132135 // Se l'utente non ha sedi, è come se ce le avesse tutte disponibili per retrocompatibilità
133136 if (empty ($ sedi )) {
134- $ sedi = $ database ->fetchArray ('SELECT "0" AS idsede UNION SELECT id AS idsede FROM an_sedi WHERE idanagrafica= ' . prepare ($ this ->idanagrafica ));
137+ $ sedi = $ database ->fetchArray ('SELECT "0" AS idsede UNION SELECT id AS idsede FROM an_sedi WHERE idanagrafica= ' . prepare ($ this ->idanagrafica ));
135138 }
136139
137140 return array_column ($ sedi , 'idsede ' );
@@ -150,7 +153,7 @@ public function getPhotoAttribute()
150153
151154 $ image = Upload::find ($ this ->image_file_id );
152155
153- return base_path_osm (). '/files/ ' . $ image ->module ->directory . '/ ' . $ image ->filename ;
156+ return base_path_osm () . '/files/ ' . $ image ->module ->directory . '/ ' . $ image ->filename ;
154157 }
155158
156159 public function setPhotoAttribute ($ value )
@@ -168,7 +171,7 @@ public function setPhotoAttribute($value)
168171 // Informazioni sull'immagine
169172 $ filepath = is_array ($ value ) ? $ value ['tmp_name ' ] : $ value ;
170173 $ info = Upload::getInfo (is_array ($ value ) ? $ value ['name ' ] : $ value );
171- $ file = base_dir (). '/files/temp_photo. ' . $ info ['extension ' ];
174+ $ file = base_dir () . '/files/temp_photo. ' . $ info ['extension ' ];
172175
173176 // Ridimensionamento
174177 $ img = getImageManager ()->read ($ filepath )->scaleDown (100 , 100 );
@@ -195,16 +198,16 @@ public function getNomeCompletoAttribute()
195198 return $ this ->username ;
196199 }
197200
198- return $ anagrafica ->ragione_sociale . ' ( ' . $ this ->username . ') ' ;
201+ return $ anagrafica ->ragione_sociale . ' ( ' . $ this ->username . ') ' ;
199202 }
200203
201204 public function getApiTokens ()
202205 {
203- $ query = 'SELECT * FROM `zz_tokens` WHERE `enabled` = 1 AND `id_utente` = ' . prepare ($ this ->id );
206+ $ query = 'SELECT * FROM `zz_tokens` WHERE `enabled` = 1 AND `id_utente` = ' . prepare ($ this ->id );
204207 $ database = database ();
205208
206209 // Generazione del token per l'utente
207- $ query_utenti = 'SELECT * FROM `zz_tokens` WHERE `id_utente` = ' . prepare ($ this ->id );
210+ $ query_utenti = 'SELECT * FROM `zz_tokens` WHERE `id_utente` = ' . prepare ($ this ->id );
208211 $ tokens = $ database ->fetchArray ($ query_utenti );
209212 if (empty ($ tokens )) {
210213 $ token = secure_random_string ();
@@ -230,7 +233,18 @@ public function isOnline(): int
230233 ':timeout ' => $ session_timeout ,
231234 ]);
232235
233- return !empty ($ recent_operations ) && $ recent_operations [0 ]['count ' ] != 0 ? 1 : 0 ;
236+ if (!empty ($ recent_operations ) && $ recent_operations [0 ]['count ' ] != 0 ) {
237+ return 1 ;
238+ }
239+
240+ $ recent_logs = $ database ->fetchArray ('SELECT COUNT(*) as count FROM zz_logs
241+ WHERE id_utente = :user_id
242+ AND DATE_ADD(created_at, INTERVAL :timeout MINUTE) >= NOW() ' , [
243+ ':user_id ' => $ this ->id ,
244+ ':timeout ' => $ session_timeout ,
245+ ]);
246+
247+ return !empty ($ recent_logs ) && $ recent_logs [0 ]['count ' ] != 0 ? 1 : 0 ;
234248 }
235249
236250 /* Relazioni Eloquent */
@@ -290,9 +304,7 @@ public function getRememberToken(): string
290304 return '' ;
291305 }
292306
293- public function setRememberToken ($ value )
294- {
295- }
307+ public function setRememberToken ($ value ) {}
296308
297309 public function getRememberTokenName (): string
298310 {
0 commit comments