From 04ff4439ed233f8cd0965083d0e6c226cda1c625 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Sat, 20 Feb 2021 17:37:57 +0100 Subject: [PATCH] Introduzione pagine di base Aggiornamento pagine di segnalazione bug, informazioni utente e log degli accessi. --- app/Http/Controllers/InfoController.php | 124 +++++----------------- app/Http/Controllers/UserController.php | 67 ++++++++++++ legacy | 2 +- resources/views/bug.blade.php | 107 +++++++++++++++++++ resources/views/{info => }/info.blade.php | 0 resources/views/layouts/app.blade.php | 12 ++- resources/views/user/info.blade.php | 95 +++++++++++++++++ resources/views/user/logs.blade.php | 36 +++++++ routes/web.php | 17 +-- 9 files changed, 348 insertions(+), 112 deletions(-) create mode 100644 app/Http/Controllers/UserController.php create mode 100644 resources/views/bug.blade.php rename resources/views/{info => }/info.blade.php (100%) create mode 100644 resources/views/user/info.blade.php create mode 100644 resources/views/user/logs.blade.php diff --git a/app/Http/Controllers/InfoController.php b/app/Http/Controllers/InfoController.php index 7b16a6a25..ffffffa53 100644 --- a/app/Http/Controllers/InfoController.php +++ b/app/Http/Controllers/InfoController.php @@ -2,107 +2,34 @@ namespace App\Http\Controllers; +use Backup; +use Illuminate\Http\Request; +use Modules\Emails\Account; +use Notifications\EmailNotification; +use Update; + class InfoController extends Controller { - /** @var int Lunghezza minima della password */ - public static $min_length_password = 8; - protected static $bugEmail = 'info@openstamanager.com'; public function info() { - return view('info.info'); - } - - public function logs() - { - $user = auth()->getUser(); - - $query = 'SELECT * FROM `zz_logs`'; - if (!Auth::admin()) { - $query .= ' WHERE `id_utente`='.prepare($user['id']); - } - $query .= ' ORDER BY `created_at` DESC LIMIT 0, 100'; - - $results = $this->database->fetchArray($query); - - $status = Auth::getStatus(); - $data = []; - foreach ($status as $state) { - $color = 'warning'; - - $color = $state['code'] == $status['success']['code'] ? 'success' : $color; - $color = $state['code'] == $status['failed']['code'] ? 'danger' : $color; - - $data[$state['code']] = [ - 'message' => $state['message'], - 'color' => $color, - ]; - } - - $args['status'] = $data; - $args['results'] = $results; - - $response = $this->twig->render($response, '@resources/info/logs.twig', $args); - - return $response; - } - - public function user() - { - $user = auth()->user(); - - $tokens = $user->getApiTokens(); - $token = $tokens[0]['token']; - - $api = BASEURL.'/api/?token='.$token; - - $args['api'] = $api; - $args['token'] = $token; - $args['sync_link'] = $api.'&resource=sync'; - - $response = $this->twig->render($response, '@resources/user/user.twig', $args); - - return $response; - } - - public function password() - { - $args['min_length_password'] = self::$min_length_password; - - $response = $this->twig->render($response, '@resources/user/password.twig', $args); - - return $response; - } - - public function passwordPost() - { - $user = auth()->getUser(); - $password = post('password'); - - $user->password = $password; - $user->save(); - - flash()->info(tr('Password aggiornata!')); - - $response = $response->withRedirect($this->router->urlFor('user')); - - return $response; + return view('info'); } public function bug() { - $args['mail'] = Account::where('predefined', true)->first(); - $args['bug_email'] = self::$bugEmail; + $account = Account::where('predefined', true)->first(); - $response = $this->twig->render($response, '@resources/info/bug.twig', $args); - - return $response; + return view('bug', [ + 'mail' => $account, + 'bug_email' => self::$bugEmail, + ]); } - public function bugSend() + public function send(Request $request) { - $user = auth()->getUser(); + $user = auth()->user(); $bug_email = self::$bugEmail; // Preparazione email @@ -112,16 +39,17 @@ class InfoController extends Controller $mail->AddAddress($bug_email); // Oggetto - $mail->Subject = 'Segnalazione bug OSM '.$args['version']; + $mail->Subject = 'Segnalazione bug OSM '.Update::getVersion(); // Aggiunta dei file di log (facoltativo) - if (!empty(post('log')) && file_exists(DOCROOT.'/logs/error.log')) { - $mail->AddAttachment(DOCROOT.'/logs/error.log'); + $log_file = base_path('/logs/error.log'); + if (!empty($request->input('log')) && file_exists($log_file)) { + $mail->AddAttachment($log_file); } // Aggiunta della copia del database (facoltativo) - if (!empty(post('sql'))) { - $backup_file = DOCROOT.'/Backup OSM '.date('Y-m-d').' '.date('H_i_s').'.sql'; + if (!empty($request->input('sql'))) { + $backup_file = base_path('backup/Backup OSM '.date('Y-m-d').' '.date('H_i_s').'.sql'); Backup::database($backup_file); $mail->AddAttachment($backup_file); @@ -133,17 +61,17 @@ class InfoController extends Controller $infos = [ 'Utente' => $user['username'], 'IP' => get_client_ip(), - 'Versione OSM' => $args['version'].' ('.($args['revision'] ? $args['revision'] : 'In sviluppo').')', + 'Versione OSM' => Update::getVersion().' ('.(Update::getRevision() ?: tr('In sviluppo')).')', 'PHP' => phpversion(), ]; // Aggiunta delle informazioni sul sistema (facoltativo) - if (!empty(post('info'))) { + if (!empty($request->input('info'))) { $infos['Sistema'] = $_SERVER['HTTP_USER_AGENT'].' - '.getOS(); } // Completamento del body - $body = post('body').'
'; + $body = $request->input('body').'
'; foreach ($infos as $key => $value) { $body .= '

'.$key.': '.$value.'

'; } @@ -160,12 +88,10 @@ class InfoController extends Controller } // Rimozione del dump del database - if (!empty(post('sql'))) { + if (!empty($request->input('sql'))) { delete($backup_file); } - $response = $response->withRedirect($this->router->urlFor('bug')); - - return $response; + return redirect(route('bug')); } } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 000000000..55e13819b --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,67 @@ +user(); + + $tokens = $user->getApiTokens(); + $token = $tokens[0]['token']; + + $api = base_url().'/api/?token='.$token; + + $args = [ + 'user' => $user, + 'api' => $api, + 'token' => $token, + 'sync_link' => $api.'&resource=sync', + ]; + + return view('user.info', $args); + } + + public function password() + { + $args['min_length_password'] = self::$min_length_password; + + return view('user.password', $args); + } + + public function save(Request $request) + { + $user = auth()->user(); + $password = $request->input('password'); + + $user->password = $password; + $user->save(); + + flash()->info(tr('Password aggiornata!')); + + return redirect(route('user-info')); + } + + public function logs() + { + $user = auth()->user(); + + $logs = Log::orderBy('created_at')->limit(100); + if (!$user->isAdmin()) { + $logs = $logs->where('id_utente', '=', $user->id); + } + + $logs = $logs->get(); + + return view('user.logs', [ + 'logs' => $logs, + ]); + } +} diff --git a/legacy b/legacy index 0b21ecf08..a4c7c2c56 160000 --- a/legacy +++ b/legacy @@ -1 +1 @@ -Subproject commit 0b21ecf084f81a8c4178fce4808c4026d937d12c +Subproject commit a4c7c2c560cc34d7d48b81158db3795650968c8b diff --git a/resources/views/bug.blade.php b/resources/views/bug.blade.php new file mode 100644 index 000000000..25faa98ee --- /dev/null +++ b/resources/views/bug.blade.php @@ -0,0 +1,107 @@ +@extends('layouts.app') + +@section('title', tr("Bug")) + +@section('content') + @if(empty($mail['from_address']) or empty($mail['server'])) +
+ + {{ tr('Attenzione!') }} {{ tr('Per utilizzare correttamente il modulo di segnalazione bug devi configurare alcuni parametri riguardanti le impostazione delle email') }}. + + {!! module('Account email')->link($mail['id'], tr('Correggi account'), null, 'class="btn btn-warning pull-right"') !!} +
+
+ @endif + +
+
+

{{ tr('Segnalazione bug') }}

+
+ +
+
+ @csrf + + + + + + + + + + + + + + + + + + +
{{ tr('Da') }}:{{ $mail['from_address'] }}
{{ tr('A') }}:{{ $bug_email }}
{{ tr('Versione OSM') }}:{{ Update::getVersion() }} ({{ Update::getRevision() ?: tr('In sviluppo') }})
+ +
+
+ {[ "type": "checkbox", "label": "{{ tr('Allega file di log') }}", "name": "log", "value": "1" ]} +
+ +
+ {[ "type": "checkbox", "label": "{{ tr('Allega copia del database') }}", "name": "sql" ]} +
+ +
+ {[ "type": "checkbox", "label": "{{ tr('Allega informazioni sul PC') }}", "name": "info", "value": "1" ]} +
+
+ +
+
+ + {[ "type": "ckeditor", "label": "{{ tr('Descrizione del bug') }}", "name": "body" ]} + + +
+
+ +
+
+
+
+
+ + +@endsection diff --git a/resources/views/info/info.blade.php b/resources/views/info.blade.php similarity index 100% rename from resources/views/info/info.blade.php rename to resources/views/info.blade.php diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index a41d648f8..18adc08e9 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -5,6 +5,8 @@ $module = \Models\Module::getCurrent(); $id_module = $module ? $module->id : null; $id_record = isset($id_record) ? $id_record : null; + + $user = auth()->user(); @endphp @section('js') @@ -70,7 +72,7 @@ 'hookMultiple': "{{ tr('Hai _NUM_ notifiche') }}", 'hookSingle': "{{ tr('Hai 1 notifica') }}", 'hookNone': "{{ tr('Nessuna notifica') }}", - 'singleCalendar': {{ tr("E' presente un solo periodo!") }}", + 'singleCalendar': "{{ tr("E' presente un solo periodo!") }}", ajax: { "missing": { "title": "{{ tr('Errore') }}", @@ -239,17 +241,17 @@