diff --git a/.env.example b/.env.example index fc62f6571..b70fdc6d3 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,7 @@ APP_ENV=local APP_KEY= APP_DEBUG=true APP_URL=http://localhost -APP_LOCALE = +APP_LOCALE= LOG_CHANNEL=stack LOG_LEVEL=debug diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 69914e993..c7dc3746e 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -13,13 +13,11 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ - // ]; /** * Define the application's command schedule. * - * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3c1bec725..e4661318f 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -14,7 +14,6 @@ class Handler extends ExceptionHandler * @var array */ protected $dontReport = [ - // ]; /** @@ -35,7 +34,6 @@ class Handler extends ExceptionHandler public function register() { $this->reportable(function (Throwable $e) { - // }); $this->renderable(function (NotFoundException $e, $request) { diff --git a/app/Exceptions/LegacyExitException.php b/app/Exceptions/LegacyExitException.php index e3f853c74..ff0bb04d0 100644 --- a/app/Exceptions/LegacyExitException.php +++ b/app/Exceptions/LegacyExitException.php @@ -6,5 +6,4 @@ use Exception; class LegacyExitException extends Exception { - } diff --git a/app/Exceptions/LegacyRedirectException.php b/app/Exceptions/LegacyRedirectException.php index d61b66a9d..69589eb83 100644 --- a/app/Exceptions/LegacyRedirectException.php +++ b/app/Exceptions/LegacyRedirectException.php @@ -7,7 +7,7 @@ use Throwable; class LegacyRedirectException extends Exception { - public function __construct($message = "", $code = 0, Throwable $previous = null) + public function __construct($message = '', $code = 0, Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/app/Http/Controllers/Auth/AuthenticatedSessionController.php b/app/Http/Controllers/Auth/AuthenticatedSessionController.php index 97dc47dad..5cbc84194 100644 --- a/app/Http/Controllers/Auth/AuthenticatedSessionController.php +++ b/app/Http/Controllers/Auth/AuthenticatedSessionController.php @@ -23,7 +23,6 @@ class AuthenticatedSessionController extends Controller /** * Handle an incoming authentication request. * - * @param \App\Http\Requests\Auth\LoginRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store(LoginRequest $request) @@ -38,7 +37,6 @@ class AuthenticatedSessionController extends Controller /** * Destroy an authenticated session. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\RedirectResponse */ public function destroy(Request $request) diff --git a/app/Http/Controllers/Auth/ConfirmablePasswordController.php b/app/Http/Controllers/Auth/ConfirmablePasswordController.php index c211bdca7..5fa4c5c7f 100644 --- a/app/Http/Controllers/Auth/ConfirmablePasswordController.php +++ b/app/Http/Controllers/Auth/ConfirmablePasswordController.php @@ -13,7 +13,6 @@ class ConfirmablePasswordController extends Controller /** * Show the confirm password view. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\View\View */ public function show(Request $request) @@ -24,18 +23,15 @@ class ConfirmablePasswordController extends Controller /** * Confirm the user's password. * - * @param \Illuminate\Http\Request $request * @return mixed */ public function store(Request $request) { - if (! Auth::guard('web')->validate([ + if (!Auth::guard('web')->validate([ 'usernamen' => $request->user()->usernamen, 'password' => $request->password, ])) { - throw ValidationException::withMessages([ - 'password' => tr('auth.password'), - ]); + throw ValidationException::withMessages(['password' => tr('auth.password')]); } $request->session()->put('auth.password_confirmed_at', time()); diff --git a/app/Http/Controllers/Auth/EmailVerificationNotificationController.php b/app/Http/Controllers/Auth/EmailVerificationNotificationController.php index 79b3f434c..cdac56376 100644 --- a/app/Http/Controllers/Auth/EmailVerificationNotificationController.php +++ b/app/Http/Controllers/Auth/EmailVerificationNotificationController.php @@ -11,7 +11,6 @@ class EmailVerificationNotificationController extends Controller /** * Send a new email verification notification. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) diff --git a/app/Http/Controllers/Auth/EmailVerificationPromptController.php b/app/Http/Controllers/Auth/EmailVerificationPromptController.php index e247f95f2..f17620dad 100644 --- a/app/Http/Controllers/Auth/EmailVerificationPromptController.php +++ b/app/Http/Controllers/Auth/EmailVerificationPromptController.php @@ -11,7 +11,6 @@ class EmailVerificationPromptController extends Controller /** * Display the email verification prompt. * - * @param \Illuminate\Http\Request $request * @return mixed */ public function __invoke(Request $request) diff --git a/app/Http/Controllers/Auth/NewPasswordController.php b/app/Http/Controllers/Auth/NewPasswordController.php index 5aec26df2..5ddeee00d 100644 --- a/app/Http/Controllers/Auth/NewPasswordController.php +++ b/app/Http/Controllers/Auth/NewPasswordController.php @@ -24,10 +24,9 @@ class NewPasswordController extends Controller /** * Handle an incoming new password request. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\RedirectResponse - * * @throws \Illuminate\Validation\ValidationException + * + * @return \Illuminate\Http\RedirectResponse */ public function store(Request $request) { diff --git a/app/Http/Controllers/Auth/PasswordResetLinkController.php b/app/Http/Controllers/Auth/PasswordResetLinkController.php index 717cccda3..8b338bc02 100644 --- a/app/Http/Controllers/Auth/PasswordResetLinkController.php +++ b/app/Http/Controllers/Auth/PasswordResetLinkController.php @@ -21,10 +21,9 @@ class PasswordResetLinkController extends Controller /** * Handle an incoming password reset link request. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\RedirectResponse - * * @throws \Illuminate\Validation\ValidationException + * + * @return \Illuminate\Http\RedirectResponse */ public function store(Request $request) { diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 5399dea49..5adc34757 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -25,10 +25,9 @@ class RegisteredUserController extends Controller /** * Handle an incoming registration request. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\RedirectResponse - * * @throws \Illuminate\Validation\ValidationException + * + * @return \Illuminate\Http\RedirectResponse */ public function store(Request $request) { diff --git a/app/Http/Controllers/Auth/VerifyEmailController.php b/app/Http/Controllers/Auth/VerifyEmailController.php index 6baa9aa71..7729a5f68 100644 --- a/app/Http/Controllers/Auth/VerifyEmailController.php +++ b/app/Http/Controllers/Auth/VerifyEmailController.php @@ -12,7 +12,6 @@ class VerifyEmailController extends Controller /** * Mark the authenticated user's email address as verified. * - * @param \Illuminate\Foundation\Auth\EmailVerificationRequest $request * @return \Illuminate\Http\RedirectResponse */ public function __invoke(EmailVerificationRequest $request) diff --git a/app/Http/Controllers/ConfigurationController.php b/app/Http/Controllers/ConfigurationController.php index f27b90e66..0d9a28e1e 100644 --- a/app/Http/Controllers/ConfigurationController.php +++ b/app/Http/Controllers/ConfigurationController.php @@ -7,7 +7,7 @@ use Illuminate\Support\Facades\DB; class ConfigurationController extends Controller { - public static function isConfigCompleted() + public static function isConfigured() { try { $connection = DB::connection(); diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index a0a2a8a34..ce1176ddb 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -9,5 +9,7 @@ use Illuminate\Routing\Controller as BaseController; class Controller extends BaseController { - use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + use AuthorizesRequests; + use DispatchesJobs; + use ValidatesRequests; } diff --git a/app/Http/Controllers/InfoController.php b/app/Http/Controllers/InfoController.php index c147cb862..8664b284b 100644 --- a/app/Http/Controllers/InfoController.php +++ b/app/Http/Controllers/InfoController.php @@ -2,8 +2,6 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; - class InfoController extends Controller { /** @var int Lunghezza minima della password */ diff --git a/app/Http/Controllers/InitializationController.php b/app/Http/Controllers/InitializationController.php new file mode 100644 index 000000000..189e94bae --- /dev/null +++ b/app/Http/Controllers/InitializationController.php @@ -0,0 +1,165 @@ +fetchNum("SELECT `an_anagrafiche`.`idanagrafica` + FROM `an_anagrafiche` + LEFT JOIN `an_tipianagrafiche_anagrafiche` ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica` + LEFT JOIN `an_tipianagrafiche` ON `an_tipianagrafiche`.`idtipoanagrafica`=`an_tipianagrafiche_anagrafiche`.`idtipoanagrafica` + WHERE `an_tipianagrafiche`.`descrizione` = 'Azienda' AND `an_anagrafiche`.`deleted_at` IS NULL") != 0; + $has_user = $database->fetchNum('SELECT `id` FROM `zz_users`') != 0; + + $settings = [ + 'Regime Fiscale' => true, + 'Tipo Cassa Previdenziale' => false, + 'Conto predefinito fatture di vendita' => true, + 'Conto predefinito fatture di acquisto' => true, + "Percentuale ritenuta d'acconto" => false, + "Causale ritenuta d'acconto" => false, + 'Valuta' => true, + ]; + + if (!empty(setting("Percentuale ritenuta d'acconto"))) { + $settings["Causale ritenuta d'acconto"] = true; + } + + $has_settings = true; + foreach ($settings as $setting => $required) { + if (empty(setting($setting)) && $required) { + $has_settings = false; + break; + } + } + + self::$init = [ + 'has_user' => $has_user, + 'has_azienda' => $has_azienda, + 'has_settings' => $has_settings, + 'settings' => $settings, + ]; + } + + return self::$init; + } + + public function index(Request $request) + { + $database = database(); + $values = self::getInitValues(); + + $settings = []; + foreach ($values['settings'] as $setting => $required) { + if (empty(setting($setting))) { + $settings[] = Setting::pool($setting)->input($required); + } + } + + // Form dell'anagrafica Azienda + ob_start(); + $module_id = module('Anagrafiche')->id; + $idtipoanagrafica = $database->fetchOne("SELECT idtipoanagrafica AS id FROM an_tipianagrafiche WHERE descrizione='Azienda'")['id']; + $readonly_tipo = true; + $skip_permissions = true; + include base_path('legacy').'/modules/anagrafiche/add.php'; + $anagrafica = ob_get_clean(); + + $form = str_replace('', '', $anagrafica); + + $args = [ + 'has_user' => $values['has_user'], + 'has_azienda' => $values['has_azienda'], + 'has_settings' => $values['has_settings'], + 'settings' => $settings, + 'azienda_form' => $form, + ]; + + return view('config.initialization', $args); + } + + public function save(Request $request) + { + $database = database(); + $values = self::getInitValues(); + + $has_user = $values['has_user']; + $has_azienda = $values['has_azienda']; + $has_settings = $values['has_settings']; + $settings = $values['settings']; + + // Azienda predefinita + if (!$has_azienda) { + $this->saveAnagrafica(); + } + + // Utente amministratore + if (!$has_user) { + // Creazione utente Amministratore + $gruppo = Group::where('nome', '=', 'Amministratori')->first(); + + $username = $request->input('admin_username'); + $password = $request->input('admin_password'); + $email = $request->input('admin_email'); + + $user = User::build($gruppo, $username, $email, $password); + + $id_record = $database->selectOne('an_anagrafiche', ['idanagrafica'])['idanagrafica']; + $user->idanagrafica = isset($id_record) ? $id_record : 0; + $user->save(); + } + + if (!$has_settings) { + foreach ($settings as $setting => $required) { + $setting = Setting::pool($setting); + + $value = $request->input('setting.'.$setting['id']); + if (!empty($value)) { + Setting::pool($setting['nome'])->setValue($value); + } + } + } + + return redirect(route('initialization')); + } + + protected function saveAnagrafica() + { + $dbo = $database = database(); + + $this->filter->set('post', 'op', 'add'); + $id_module = module('Anagrafiche')['id']; + include base_path('legacy').'/modules/anagrafiche/actions.php'; + + // Logo stampe + if (!empty($_FILES) && !empty($_FILES['blob']['name'])) { + $file = Upload::build($_FILES['blob'], [ + 'name' => 'Logo stampe', + 'id_module' => $id_module, + 'id_record' => $id_record, + ]); + + Setting::pool('Logo stampe')->setValue($file); + } + } +} diff --git a/app/Http/Controllers/LegacyController.php b/app/Http/Controllers/LegacyController.php index 34d310193..a40d97561 100644 --- a/app/Http/Controllers/LegacyController.php +++ b/app/Http/Controllers/LegacyController.php @@ -12,7 +12,7 @@ class LegacyController extends Controller { public function index($path = 'index.php') { - $base_path = base_path('legacy/'); + $base_path = base_path('legacy'); $file = realpath($base_path.'/'.$path); if (strpos($file, $base_path) === false) { throw new NotFoundHttpException(); @@ -28,6 +28,13 @@ class LegacyController extends Controller $output = ob_get_clean(); - return new Response($output); + $response = response($output); + + // Fix content-type per contenuti non HTML + if (ends_with($path, '.js')) { + $response = $response->header('Content-Type', 'application/javascript'); + } + + return $response; } } diff --git a/app/Http/Controllers/Test.php b/app/Http/Controllers/Test.php index 887009a40..53d7ca9e7 100644 --- a/app/Http/Controllers/Test.php +++ b/app/Http/Controllers/Test.php @@ -2,12 +2,9 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; - class Test extends Controller { - // - public function index(){ - + public function index() + { } } diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php index 033136ad1..50d0fe796 100644 --- a/app/Http/Middleware/EncryptCookies.php +++ b/app/Http/Middleware/EncryptCookies.php @@ -12,6 +12,5 @@ class EncryptCookies extends Middleware * @var array */ protected $except = [ - // ]; } diff --git a/app/Http/Middleware/EnsureCalendarPeriod.php b/app/Http/Middleware/EnsureCalendarPeriod.php index fdc237836..0e95af5f9 100644 --- a/app/Http/Middleware/EnsureCalendarPeriod.php +++ b/app/Http/Middleware/EnsureCalendarPeriod.php @@ -10,8 +10,6 @@ class EnsureCalendarPeriod /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next) diff --git a/app/Http/Middleware/EnsureConfiguration.php b/app/Http/Middleware/EnsureConfiguration.php index 2512c7cb0..38e3da0e4 100644 --- a/app/Http/Middleware/EnsureConfiguration.php +++ b/app/Http/Middleware/EnsureConfiguration.php @@ -3,6 +3,7 @@ namespace App\Http\Middleware; use App\Http\Controllers\ConfigurationController; +use App\Http\Controllers\InitializationController; use Closure; use Illuminate\Http\Request; @@ -20,9 +21,32 @@ class EnsureConfiguration return $next($request); } + // Test della connessione al database + $result = $this->checkConfiguration($route); + if ($result !== null) { + return $result; + } + + // Verifiche sullo stato delle migrazioni + $result = $this->checkMigrations($route); + if ($result !== null) { + return $result; + } + + // Verifiche sullo stato delle impostazioni obbligatorie + $result = $this->checkInitialization($route); + if ($result !== null) { + return $result; + } + + return $next($request); + } + + protected function checkConfiguration($route) + { // Test della connessione al database $configuration_paths = ['configuration', 'configuration-save', 'configuration-test']; - $configuration_completed = ConfigurationController::isConfigCompleted(); + $configuration_completed = ConfigurationController::isConfigured(); if ($configuration_completed) { // Redirect nel caso in cui la configurazione sia correttamente funzionante @@ -36,10 +60,31 @@ class EnsureConfiguration } } - // Verifiche sullo stato delle migrazioni + return null; + } - // Verifiche sullo stato delle impostazioni obbligatorie + protected function checkInitialization($route) + { + $initialization_paths = ['initialization', 'initialization-save']; + $initialization_completed = InitializationController::isInitialized(); - return $next($request); + if ($initialization_completed) { + // Redirect nel caso in cui la configurazione sia correttamente funzionante + if (in_array($route->getName(), $initialization_paths)) { + return redirect(route('login')); + } + } else { + // Redirect per configurazione mancante + if (!in_array($route->getName(), $initialization_paths)) { + return redirect(route('initialization')); + } + } + + return null; + } + + protected function checkMigrations($route) + { + return null; } } diff --git a/app/Http/Middleware/EnsureEnvFile.php b/app/Http/Middleware/EnsureEnvFile.php index 9c2ceef1b..ecbb8a398 100644 --- a/app/Http/Middleware/EnsureEnvFile.php +++ b/app/Http/Middleware/EnsureEnvFile.php @@ -23,10 +23,8 @@ class EnsureEnvFile if (!file_exists($env_file)) { return response('Missing .env file'); } - } - // Generazione automatica delle key Laravel - if (empty(env('APP_KEY'))) { + // Generazione automatica delle key Laravel Artisan::call('key:generate'); header('Refresh: 0;'); diff --git a/app/Http/Middleware/PreventRequestsDuringMaintenance.php b/app/Http/Middleware/PreventRequestsDuringMaintenance.php index e4956d0bb..4cd20d56f 100644 --- a/app/Http/Middleware/PreventRequestsDuringMaintenance.php +++ b/app/Http/Middleware/PreventRequestsDuringMaintenance.php @@ -12,6 +12,5 @@ class PreventRequestsDuringMaintenance extends Middleware * @var array */ protected $except = [ - // ]; } diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 362b48b0d..77601d6cc 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -12,9 +12,8 @@ class RedirectIfAuthenticated /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @param string|null ...$guards + * @param string|null ...$guards + * * @return mixed */ public function handle(Request $request, Closure $next, ...$guards) diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 6a65a78ec..173185d6b 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware * @var array */ protected $except = [ - 'legacy' + 'legacy', ]; } diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index 9a6751f8e..437081285 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -37,20 +37,18 @@ class LoginRequest extends FormRequest /** * Attempt to authenticate the request's credentials. * - * @return void - * * @throws \Illuminate\Validation\ValidationException + * + * @return void */ public function authenticate() { $this->ensureIsNotRateLimited(); - if (! Auth::attempt($this->only('username', 'password'), $this->filled('remember'))) { + if (!Auth::attempt($this->only('username', 'password'), $this->filled('remember'))) { RateLimiter::hit($this->throttleKey()); - throw ValidationException::withMessages([ - 'username' => tr('auth.failed'), - ]); + throw ValidationException::withMessages(['username' => tr('auth.failed')]); } RateLimiter::clear($this->throttleKey()); @@ -59,13 +57,13 @@ class LoginRequest extends FormRequest /** * Ensure the login request is not rate limited. * - * @return void - * * @throws \Illuminate\Validation\ValidationException + * + * @return void */ public function ensureIsNotRateLimited() { - if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { + if (!RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { return; } @@ -73,12 +71,7 @@ class LoginRequest extends FormRequest $seconds = RateLimiter::availableIn($this->throttleKey()); - throw ValidationException::withMessages([ - 'username' => trans('auth.throttle', [ - 'seconds' => $seconds, - 'minutes' => ceil($seconds / 60), - ]), - ]); + throw ValidationException::withMessages(['username' => trans('auth.throttle', ['seconds' => $seconds, 'minutes' => ceil($seconds / 60)])]); } /** diff --git a/app/Models/User.php b/app/Models/User.php index 0c1ed48dd..3ecc3be00 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,7 @@ use Common\SimpleModelTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Facades\Hash; use Intervention\Image\ImageManagerStatic; use Models\Group; use Models\Log; @@ -136,7 +137,7 @@ class User extends Authenticatable public function setPasswordAttribute($value) { - $this->attributes['password'] = \auth()->hashPassword($value); + $this->attributes['password'] = Hash::make($value); } public function getPhotoAttribute() diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ee8ca5bcd..0de818494 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -13,7 +13,6 @@ class AppServiceProvider extends ServiceProvider */ public function register() { - // } /** @@ -23,6 +22,5 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - // } } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index ce7449164..94252270f 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -3,7 +3,6 @@ namespace App\Providers; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; -use Illuminate\Support\Facades\Gate; class AuthServiceProvider extends ServiceProvider { @@ -24,7 +23,5 @@ class AuthServiceProvider extends ServiceProvider public function boot() { $this->registerPolicies(); - - // } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index a9f10a631..5bcd955ad 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -27,6 +27,5 @@ class EventServiceProvider extends ServiceProvider */ public function boot() { - // } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 809bc4ab1..3fba27369 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider * * @var string */ - public const HOME = '/home'; + public const HOME = '/'; /** * The controller namespace for the application. diff --git a/composer.json b/composer.json index 9366150bb..ef350d127 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "league/csv": "^8.2", "mpdf/mpdf": "^v8.0.7", "mpociot/vat-calculator": "^2.3", + "nwidart/laravel-modules": "^8.2", "owasp/csrf-protector-php": "^1.0", "phpmailer/phpmailer": "^6.0", "respect/validation": "^1.1", diff --git a/config/app.php b/config/app.php index 7e1fb6b96..02aab37b2 100644 --- a/config/app.php +++ b/config/app.php @@ -12,7 +12,7 @@ return [ | */ - 'name' => env('APP_NAME', 'Laravel'), + 'name' => env('APP_NAME', 'OpenSTAManager'), /* |-------------------------------------------------------------------------- diff --git a/config/auth.php b/config/auth.php index ba1a4d8cb..d97282db5 100644 --- a/config/auth.php +++ b/config/auth.php @@ -1,7 +1,6 @@ 10800, - ]; diff --git a/config/broadcasting.php b/config/broadcasting.php index ef2085985..5cf71f00b 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -1,7 +1,6 @@ [ - 'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_KEY'), @@ -58,7 +56,5 @@ return [ 'null' => [ 'driver' => 'null', ], - ], - ]; diff --git a/config/cache.php b/config/cache.php index 9473acc98..37144356c 100644 --- a/config/cache.php +++ b/config/cache.php @@ -3,7 +3,6 @@ use Illuminate\Support\Str; return [ - /* |-------------------------------------------------------------------------- | Default Cache Store @@ -32,7 +31,6 @@ return [ */ 'stores' => [ - 'apc' => [ 'driver' => 'apc', ], @@ -85,7 +83,6 @@ return [ 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 'endpoint' => env('DYNAMODB_ENDPOINT'), ], - ], /* @@ -100,5 +97,4 @@ return [ */ 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'), - ]; diff --git a/config/cors.php b/config/cors.php index 8a39e6daa..9a2fcfb49 100644 --- a/config/cors.php +++ b/config/cors.php @@ -1,7 +1,6 @@ 0, 'supports_credentials' => false, - ]; diff --git a/config/database.php b/config/database.php index 93cb853b7..9ad6adee1 100644 --- a/config/database.php +++ b/config/database.php @@ -3,7 +3,6 @@ use Illuminate\Support\Str; return [ - /* |-------------------------------------------------------------------------- | Default Database Connection Name @@ -80,7 +79,6 @@ return [ */ 'redis' => [ - 'client' => env('REDIS_CLIENT', 'phpredis'), 'options' => [ @@ -103,7 +101,5 @@ return [ 'port' => env('REDIS_PORT', '6379'), 'database' => env('REDIS_CACHE_DB', '1'), ], - ], - ]; diff --git a/config/debugbar.php b/config/debugbar.php index 37c2f6891..fa570f58b 100644 --- a/config/debugbar.php +++ b/config/debugbar.php @@ -1,7 +1,6 @@ [ - 'enabled' => true, - 'driver' => 'file', // redis, file, pdo, socket, custom - 'path' => storage_path('debugbar'), // For file driver + 'enabled' => true, + 'driver' => 'file', // redis, file, pdo, socket, custom + 'path' => storage_path('debugbar'), // For file driver 'connection' => null, // Leave null for default connection (Redis/PDO) - 'provider' => '', // Instance of StorageInterface for custom driver - 'hostname' => '127.0.0.1', // Hostname to use with the "socket" driver - 'port' => 2304, // Port to use with the "socket" driver + 'provider' => '', // Instance of StorageInterface for custom driver + 'hostname' => '127.0.0.1', // Hostname to use with the "socket" driver + 'port' => 2304, // Port to use with the "socket" driver ], /* @@ -104,29 +103,29 @@ return [ */ 'collectors' => [ - 'phpinfo' => true, // Php version - 'messages' => true, // Messages - 'time' => true, // Time Datalogger - 'memory' => true, // Memory usage - 'exceptions' => true, // Exception displayer - 'log' => true, // Logs from Monolog (merged in messages if enabled) - 'db' => true, // Show database (PDO) queries and bindings - 'views' => true, // Views with their data - 'route' => true, // Current route information - 'auth' => false, // Display Laravel authentication status - 'gate' => true, // Display Laravel Gate checks - 'session' => true, // Display session data + 'phpinfo' => true, // Php version + 'messages' => true, // Messages + 'time' => true, // Time Datalogger + 'memory' => true, // Memory usage + 'exceptions' => true, // Exception displayer + 'log' => true, // Logs from Monolog (merged in messages if enabled) + 'db' => true, // Show database (PDO) queries and bindings + 'views' => true, // Views with their data + 'route' => true, // Current route information + 'auth' => false, // Display Laravel authentication status + 'gate' => true, // Display Laravel Gate checks + 'session' => true, // Display session data 'symfony_request' => true, // Only one can be enabled.. - 'mail' => true, // Catch mail messages - 'laravel' => false, // Laravel version and environment - 'events' => false, // All events fired + 'mail' => true, // Catch mail messages + 'laravel' => false, // Laravel version and environment + 'events' => false, // All events fired 'default_request' => false, // Regular or special Symfony request logger - 'logs' => false, // Add the latest log messages - 'files' => false, // Show the included files - 'config' => false, // Display config settings - 'cache' => false, // Display cache events - 'models' => true, // Display models - 'livewire' => true, // Display Livewire (when available) + 'logs' => false, // Add the latest log messages + 'files' => false, // Show the included files + 'config' => false, // Display config settings + 'cache' => false, // Display cache events + 'models' => true, // Display models + 'livewire' => true, // Display Livewire (when available) ], /* @@ -143,16 +142,16 @@ return [ 'show_name' => true, // Also show the users name/email in the debugbar ], 'db' => [ - 'with_params' => true, // Render SQL with the parameters substituted - 'backtrace' => true, // Use a backtrace to find the origin of the query in your files. + 'with_params' => true, // Render SQL with the parameters substituted + 'backtrace' => true, // Use a backtrace to find the origin of the query in your files. 'backtrace_exclude_paths' => [], // Paths to exclude from backtrace. (in addition to defaults) - 'timeline' => false, // Add the queries to the timeline + 'timeline' => false, // Add the queries to the timeline 'explain' => [ // Show EXPLAIN output on queries 'enabled' => false, 'types' => ['SELECT'], // Deprecated setting, is always only SELECT ], - 'hints' => false, // Show hints for common mistakes - 'show_copy' => false, // Show copy button next to the query + 'hints' => false, // Show hints for common mistakes + 'show_copy' => false, // Show copy button next to the query ], 'mail' => [ 'full_log' => false, diff --git a/config/filesystems.php b/config/filesystems.php index 10c9d9be2..6f5f5b5e8 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -1,7 +1,6 @@ [ - 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), @@ -51,7 +49,6 @@ return [ 'url' => env('AWS_URL'), 'endpoint' => env('AWS_ENDPOINT'), ], - ], /* @@ -68,5 +65,4 @@ return [ 'links' => [ public_path('storage') => storage_path('app/public'), ], - ]; diff --git a/config/hashing.php b/config/hashing.php index 842577087..a5ffb2836 100644 --- a/config/hashing.php +++ b/config/hashing.php @@ -1,7 +1,6 @@ 2, 'time' => 2, ], - ]; diff --git a/config/image.php b/config/image.php index 2b1d2c3e1..7c2f5b5cb 100644 --- a/config/image.php +++ b/config/image.php @@ -1,7 +1,6 @@ 'gd' - + 'driver' => 'gd', ]; diff --git a/config/logging.php b/config/logging.php index 6aa77fe28..2f3187e01 100644 --- a/config/logging.php +++ b/config/logging.php @@ -5,7 +5,6 @@ use Monolog\Handler\StreamHandler; use Monolog\Handler\SyslogUdpHandler; return [ - /* |-------------------------------------------------------------------------- | Default Log Channel @@ -100,5 +99,4 @@ return [ 'path' => storage_path('logs/laravel.log'), ], ], - ]; diff --git a/config/mail.php b/config/mail.php index 54299aabf..c8c25ffc5 100644 --- a/config/mail.php +++ b/config/mail.php @@ -1,7 +1,6 @@ [ 'enabled' => false, - 'path' => base_path() . '/vendor/nwidart/laravel-modules/src/Commands/stubs', + 'path' => base_path().'/vendor/nwidart/laravel-modules/src/Commands/stubs', 'files' => [ 'routes/web' => 'Routes/web.php', 'routes/api' => 'Routes/api.php', @@ -241,7 +240,7 @@ return [ */ 'register' => [ 'translations' => true, - /** + /* * load files on boot or register method * * Note: boot not compatible with asgardcms diff --git a/config/queue.php b/config/queue.php index 122229666..7e54f29c1 100644 --- a/config/queue.php +++ b/config/queue.php @@ -1,7 +1,6 @@ [ - 'sync' => [ 'driver' => 'sync', ], @@ -66,7 +64,6 @@ return [ 'retry_after' => 90, 'block_for' => null, ], - ], /* @@ -85,5 +82,4 @@ return [ 'database' => env('DB_CONNECTION', 'mysql'), 'table' => 'failed_jobs', ], - ]; diff --git a/config/services.php b/config/services.php index 2a1d616c7..7cc99c506 100644 --- a/config/services.php +++ b/config/services.php @@ -1,7 +1,6 @@ env('AWS_SECRET_ACCESS_KEY'), 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), ], - ]; diff --git a/config/session.php b/config/session.php index 4e0f66cda..95a6d9c92 100644 --- a/config/session.php +++ b/config/session.php @@ -3,7 +3,6 @@ use Illuminate\Support\Str; return [ - /* |-------------------------------------------------------------------------- | Default Session Driver @@ -197,5 +196,4 @@ return [ */ 'same_site' => 'lax', - ]; diff --git a/config/tinker.php b/config/tinker.php index c187942d0..92c831cf1 100644 --- a/config/tinker.php +++ b/config/tinker.php @@ -1,7 +1,6 @@ [ - // ], /* @@ -46,5 +44,4 @@ return [ 'dont_alias' => [ 'App\Nova', ], - ]; diff --git a/config/trustedproxy.php b/config/trustedproxy.php index e618ae247..019784326 100644 --- a/config/trustedproxy.php +++ b/config/trustedproxy.php @@ -1,7 +1,6 @@ Illuminate\Http\Request::HEADER_X_FORWARDED_ALL, - ]; diff --git a/config/vat_calculator.php b/config/vat_calculator.php index 05097da4a..2c3481144 100644 --- a/config/vat_calculator.php +++ b/config/vat_calculator.php @@ -7,7 +7,6 @@ */ return [ - /* |-------------------------------------------------------------------------- | VAT rules diff --git a/config/view.php b/config/view.php index 22b8a18d3..24dea7a4a 100644 --- a/config/view.php +++ b/config/view.php @@ -1,7 +1,6 @@
- {{ __('This is a secure area of the application. Please confirm your password before continuing.') }} + {{ tr('This is a secure area of the application. Please confirm your password before continuing.') }}
@@ -18,7 +18,7 @@
- + - {{ __('Confirm') }} + {{ tr('Confirm') }}
diff --git a/resources/views/auth/forgot-password.blade.php b/resources/views/auth/forgot-password.blade.php index 0642fa882..c2a27b0c9 100644 --- a/resources/views/auth/forgot-password.blade.php +++ b/resources/views/auth/forgot-password.blade.php @@ -7,7 +7,7 @@
- {{ __('Forgot your password? No problem. Just let us know your email address and we will email you a password reset link that will allow you to choose a new one.') }} + {{ tr('Forgot your password? No problem. Just let us know your email address and we will email you a password reset link that will allow you to choose a new one.') }}
@@ -21,14 +21,14 @@
- +
- {{ __('Email Password Reset Link') }} + {{ tr('Email Password Reset Link') }}
diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 35878f321..8710121ae 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -1,7 +1,7 @@ @extends('layouts.base') -@section('body_class', 'hold-transition login-page') -@section('title', __("Login")) +@section('body_class', 'bg-light') +@section('title', tr("Login")) @section('body')
@@ -16,23 +16,23 @@
@@ -43,7 +43,7 @@ @if (Update::isBeta())
 
- {{ __('Attenzione!') }} {{ __('Stai utilizzando una versione non stabile di OSM.') }} + {{ tr('Attenzione!') }} {!! tr('Stai utilizzando una versione non stabile di OSM.') !!}
@@ -52,12 +52,12 @@ @if (false)
-

{{ __('Attenzione') }}

+

{{ tr('Attenzione') }}

-

{{ __('Sono stati effettuati troppi tentativi di accesso consecutivi!') }}

-

{{ __('Tempo rimanente (in secondi)') }}: {{ brute.timeout + 1 }}

+

{{ tr('Sono stati effettuati troppi tentativi di accesso consecutivi!') }}

+

{{ tr('Tempo rimanente (in secondi)') }}: {{ brute.timeout + 1 }}

+ @endif + + @if(!$has_azienda) +
+
+

{{ tr('Azienda predefinita') }}

+
+ +
+ {!! azienda_form !!} + +
+
+

{{ tr('Logo stampe') }}

+
+ +
+
+
+ +
+ {[ "type": "file", "placeholder": "{{ tr('File') }}", "name": "blob" ]} +
+ +

 

{{ tr('Per impostare il logo delle stampe, caricare un file ".jpg". Risoluzione consigliata 302x111 pixel') }}.
+ +
+
+ +
+
+ @endif + + @if(!$has_settings) +
+
+

{{ tr('Impostazioni di base') }}

+
+ +
+ + @foreach($settings as $setting) +
+ {!! $setting !!} +
+ @endforeach + +
+
+ @endif + + +
+
+ *{{ tr('Campi obbligatori') }} +
+
+ +
+
+ + + + +
+@endsection diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php index dfd302fac..be1e4fbc1 100644 --- a/resources/views/errors/404.blade.php +++ b/resources/views/errors/404.blade.php @@ -9,7 +9,7 @@ @section('error_info', tr('Non siamo riusciti a trovare la pagina che stavi cercando')) @section('js') - @if(!auth()->check()) + @if(\App\Http\Controllers\ConfigurationController::isConfigured() && !auth()->check()) diff --git a/resources/views/info/info.blade.php b/resources/views/info/info.blade.php new file mode 100644 index 000000000..ba972b852 --- /dev/null +++ b/resources/views/info/info.blade.php @@ -0,0 +1,145 @@ +@extends('layouts.app') + +@section('title', tr("Informazioni")) + +@section('content') +

{{ tr('Informazioni sul software') }}

+ +
+
+

{{ tr("Il gestionale OpenSTAManager è un software open-source e web based, sviluppato dall'azienda informatica DevCode di Este per gestire ed archiviare il servizio di assistenza tecnica e la relativa fatturazione") }}. {{ tr("Il nome del progetto deriva dalla parziale traduzione in inglese degli elementi principali che lo compongono: la natura open-source e il suo obiettivo quale Gestore del Servizio Tecnico di Assistenza") }}.

+
+
+ +
+
+

{{ tr('Sito web') }}: www.openstamanager.com

+
+ +
+

{{ tr('Versione') }}: {{ Update::getVersion() }} ({{ Update::getRevision() ?: tr('In sviluppo') }})

+
+ +
+

{{ tr('Licenza') }}: GPLv3

+
+
+ +
+ +
+
+
+
+

{{ tr('Perchè software libero') }}

+
+ +
+

{{ tr("Il progetto è software libero perchè permette a tutti di conoscere come funziona avendo il codice sorgente del programma e fornisce così la possibilità di studiare come funziona, modificarlo, adattarlo alle proprie esigenze e, in ambito commerciale, non obbliga l'utilizzatore ad essere legato allo stesso fornitore di assistenza") }}.

+ +

{{ tr("E' altrettanto importante sapere come funziona per conoscere come vengono trattati i VOSTRI dati, proteggendo così la vostra privacy") }}.

+ +

{{ tr('OpenSTAManager è inoltre stato progettato utilizzando altro software libero, tra cui principalmente') }}:

+ +
+
+
+ +
+
+
+

{{ tr('Community') }}

+
+ +
+

{{ tr('La community è un componente importante in un progetto open-source perchè mette in contatto le persone tra di loro, utenti e programmatori') }}.

+ +

{{ tr('Con OpenSTAManager siamo presenti su') }}:

+ + +
+
+ +
+
+

{{ tr('Aggiornamenti e nuove versioni') }}

+
+ +
+

{{ tr("Tutti gli aggiornamenti e le nuove versioni sono disponibili all'indirizzo") }}:

+ www.openstamanager.com/downloads/ +
+
+
+
+ +
+
+
+
+

{{ tr('Supporta il progetto') }}

+
+ +
+

{{ tr('OpenSTAManager è software libero ed è nato e cresciuto con il lavoro volontario di alcuni programmatori') }}.

+ +

{{ tr('La filosofia del software libero fa sì che il progetto sia accessibile a tutti e nel nostro caso specifico lo è, anche dal punto di vista della gratuità') }}.

+ +

{{ tr('Offriamo supporto a pagamento professionale a chi fosse interessato, ma a chi non interessa il supporto a pagamento e sta comunque utilizzando il software chiediamo una donazione per il lavoro svolto finora e per la possibilità di continuare questo progetto con lo stesso spirito con cui è nato') }}. {{ tr('Le donazioni non ci rendono ricchi, ma sono un grande simbolo di apprezzamento') }}.

+ + {{ tr('Supporta questo progetto') }} +
+
+
+ + +
+
+
+

{{ tr('Servizi a pagamento') }}

+
+ +
+

{{ tr('Per le aziende che hanno necessità di essere seguite da supporto professionale è disponibile un servizio di assistenza e supporto a pagamento') }}.

+ +

{{ tr("E' disponibile anche un servizio cloud su cui poter installare OpenSTAManager, in modo da non doverti più preoccupare di backup e gestione dei dati") }}.

+ +

{{ tr('Ottieni supporto professionale') }}

+
+
+
+
+@endsection( diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php index 2e0ec113a..b480c3e3e 100644 --- a/resources/views/layouts/base.blade.php +++ b/resources/views/layouts/base.blade.php @@ -45,7 +45,7 @@ decimals: "{{ formatter()->getNumberSeparators()['decimals'] }}", thousands: "{{ formatter()->getNumberSeparators()['thousands'] }}", - locale: '{{ app()->getLocale() }}', + locale: '{{ substr(app()->getLocale(), 0, strpos(app()->getLocale(), "_")) }}', full_locale: '{{ app()->getLocale() }}', translations: { diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php deleted file mode 100644 index e305e336f..000000000 --- a/resources/views/welcome.blade.php +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - Laravel - - - - - - - - - - -
- @if (Route::has('login')) - - @endif - -
-
- - - - - -
- -
-
-
- - -
-
- Laravel has wonderful, thorough documentation covering every aspect of the framework. Whether you are new to the framework or have previous experience with Laravel, we recommend reading all of the documentation from beginning to end. -
-
-
- -
-
- - -
- -
-
- Laracasts offers thousands of video tutorials on Laravel, PHP, and JavaScript development. Check them out, see for yourself, and massively level up your development skills in the process. -
-
-
- -
-
- - -
- -
-
- Laravel News is a community driven portal and newsletter aggregating all of the latest and most important news in the Laravel ecosystem, including new package releases and tutorials. -
-
-
- -
-
- -
Vibrant Ecosystem
-
- -
-
- Laravel's robust library of first-party tools and libraries, such as Forge, Vapor, Nova, and Envoyer help you take your projects to the next level. Pair them with powerful open source libraries like Cashier, Dusk, Echo, Horizon, Sanctum, Telescope, and more. -
-
-
-
-
- -
-
-
- - - - - - Shop - - - - - - - - Sponsor - -
-
- -
- Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }}) -
-
-
-
- - diff --git a/routes/auth.php b/routes/auth.php index 3ddf8c023..bf3898148 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -10,47 +10,47 @@ use App\Http\Controllers\Auth\VerifyEmailController; use Illuminate\Support\Facades\Route; Route::get('/login', [AuthenticatedSessionController::class, 'create']) - ->middleware('guest') - ->name('login'); + ->middleware('guest') + ->name('login'); Route::post('/login', [AuthenticatedSessionController::class, 'store']) - ->middleware('guest'); + ->middleware('guest'); Route::get('/forgot-password', [PasswordResetLinkController::class, 'create']) - ->middleware('guest') - ->name('password.request'); + ->middleware('guest') + ->name('password.request'); Route::post('/forgot-password', [PasswordResetLinkController::class, 'store']) - ->middleware('guest') - ->name('password.email'); + ->middleware('guest') + ->name('password.email'); Route::get('/reset-password/{token}', [NewPasswordController::class, 'create']) - ->middleware('guest') - ->name('password.reset'); + ->middleware('guest') + ->name('password.reset'); Route::post('/reset-password', [NewPasswordController::class, 'store']) - ->middleware('guest') - ->name('password.update'); + ->middleware('guest') + ->name('password.update'); Route::get('/verify-email', [EmailVerificationPromptController::class, '__invoke']) - ->middleware('auth') - ->name('verification.notice'); + ->middleware('auth') + ->name('verification.notice'); Route::get('/verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke']) - ->middleware(['auth', 'signed', 'throttle:6,1']) - ->name('verification.verify'); + ->middleware(['auth', 'signed', 'throttle:6,1']) + ->name('verification.verify'); Route::post('/email/verification-notification', [EmailVerificationNotificationController::class, 'store']) - ->middleware(['auth', 'throttle:6,1']) - ->name('verification.send'); + ->middleware(['auth', 'throttle:6,1']) + ->name('verification.send'); Route::get('/confirm-password', [ConfirmablePasswordController::class, 'show']) - ->middleware('auth') - ->name('password.confirm'); + ->middleware('auth') + ->name('password.confirm'); Route::post('/confirm-password', [ConfirmablePasswordController::class, 'store']) - ->middleware('auth'); + ->middleware('auth'); Route::post('/logout', [AuthenticatedSessionController::class, 'destroy']) - ->middleware('auth') - ->name('logout'); + ->middleware('auth') + ->name('logout'); diff --git a/routes/web.php b/routes/web.php index 19b0446a9..d8d5628ca 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\ConfigurationController; use App\Http\Controllers\InfoController; +use App\Http\Controllers\InitializationController; use App\Http\Controllers\Test; use Illuminate\Support\Facades\Route; @@ -19,6 +20,14 @@ use Illuminate\Support\Facades\Route; // Percorsi di autenticazione e gestione utenza require __DIR__.'/auth.php'; +// Redirect predefinito a seguito del login +Route::get('/', function (){ + $module = module('Dashboard'); + + return redirect('controller.php?id_module='.$module->id); +}) + ->middleware('auth'); + // Sezione di configurazione Route::get('/config', [ConfigurationController::class, 'index']) ->name('configuration'); @@ -27,6 +36,12 @@ Route::get('/config-test', [ConfigurationController::class, 'test']) Route::post('/config', [ConfigurationController::class, 'save']) ->name('configuration-save'); +// Inizializzazione del gestionale +Route::get('/init', [InitializationController::class, 'index']) + ->name('initialization'); +Route::post('/init', [InitializationController::class, 'save']) + ->name('initialization-save'); + // Messaggi flash Route::get('/messages', [Test::class, 'index']) ->name('messages'); @@ -91,7 +106,3 @@ Route::get('/user', [Test::class, 'index']) Route::get('/password', [Test::class, 'index']) ->name('user-password'); Route::post('/password', [Test::class, 'index']); - -Route::get('/dashboard', function () { - return view('dashboard'); -})->middleware(['auth'])->name('dashboard'); diff --git a/server.php b/server.php index 5fb6379e7..20bc389f0 100644 --- a/server.php +++ b/server.php @@ -1,12 +1,10 @@ */ - $uri = urldecode( parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ); diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php new file mode 100644 index 000000000..e26984771 --- /dev/null +++ b/tests/Feature/AuthenticationTest.php @@ -0,0 +1,45 @@ +get('/login'); + + $response->assertStatus(200); + } + + public function testUsersCanAuthenticateUsingTheLoginScreen() + { + $user = User::factory()->create(); + + $response = $this->post('/login', [ + 'email' => $user->email, + 'password' => 'password', + ]); + + $this->assertAuthenticated(); + $response->assertRedirect(RouteServiceProvider::HOME); + } + + public function testUsersCanNotAuthenticateWithInvalidPassword() + { + $user = User::factory()->create(); + + $this->post('/login', [ + 'email' => $user->email, + 'password' => 'wrong-password', + ]); + + $this->assertGuest(); + } +} diff --git a/tests/Feature/EmailVerificationTest.php b/tests/Feature/EmailVerificationTest.php new file mode 100644 index 000000000..962ac9b80 --- /dev/null +++ b/tests/Feature/EmailVerificationTest.php @@ -0,0 +1,65 @@ +create([ + 'email_verified_at' => null, + ]); + + $response = $this->actingAs($user)->get('/verify-email'); + + $response->assertStatus(200); + } + + public function testEmailCanBeVerified() + { + Event::fake(); + + $user = User::factory()->create([ + 'email_verified_at' => null, + ]); + + $verificationUrl = URL::temporarySignedRoute( + 'verification.verify', + now()->addMinutes(60), + ['id' => $user->id, 'hash' => sha1($user->email)] + ); + + $response = $this->actingAs($user)->get($verificationUrl); + + Event::assertDispatched(Verified::class); + $this->assertTrue($user->fresh()->hasVerifiedEmail()); + $response->assertRedirect(RouteServiceProvider::HOME.'?verified=1'); + } + + public function testEmailIsNotVerifiedWithInvalidHash() + { + $user = User::factory()->create([ + 'email_verified_at' => null, + ]); + + $verificationUrl = URL::temporarySignedRoute( + 'verification.verify', + now()->addMinutes(60), + ['id' => $user->id, 'hash' => sha1('wrong-email')] + ); + + $this->actingAs($user)->get($verificationUrl); + + $this->assertFalse($user->fresh()->hasVerifiedEmail()); + } +} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index cdb511193..8fbf37067 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature; -use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; class ExampleTest extends TestCase diff --git a/tests/Feature/PasswordConfirmationTest.php b/tests/Feature/PasswordConfirmationTest.php new file mode 100644 index 000000000..0a96cdbed --- /dev/null +++ b/tests/Feature/PasswordConfirmationTest.php @@ -0,0 +1,44 @@ +create(); + + $response = $this->actingAs($user)->get('/confirm-password'); + + $response->assertStatus(200); + } + + public function testPasswordCanBeConfirmed() + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->post('/confirm-password', [ + 'password' => 'password', + ]); + + $response->assertRedirect(); + $response->assertSessionHasNoErrors(); + } + + public function testPasswordIsNotConfirmedWithInvalidPassword() + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->post('/confirm-password', [ + 'password' => 'wrong-password', + ]); + + $response->assertSessionHasErrors(); + } +} diff --git a/tests/Feature/PasswordResetTest.php b/tests/Feature/PasswordResetTest.php new file mode 100644 index 000000000..7ec5b0f99 --- /dev/null +++ b/tests/Feature/PasswordResetTest.php @@ -0,0 +1,71 @@ +get('/forgot-password'); + + $response->assertStatus(200); + } + + public function testResetPasswordLinkCanBeRequested() + { + Notification::fake(); + + $user = User::factory()->create(); + + $this->post('/forgot-password', ['email' => $user->email]); + + Notification::assertSentTo($user, ResetPassword::class); + } + + public function testResetPasswordScreenCanBeRendered() + { + Notification::fake(); + + $user = User::factory()->create(); + + $this->post('/forgot-password', ['email' => $user->email]); + + Notification::assertSentTo($user, ResetPassword::class, function ($notification) { + $response = $this->get('/reset-password/'.$notification->token); + + $response->assertStatus(200); + + return true; + }); + } + + public function testPasswordCanBeResetWithValidToken() + { + Notification::fake(); + + $user = User::factory()->create(); + + $this->post('/forgot-password', ['email' => $user->email]); + + Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { + $response = $this->post('/reset-password', [ + 'token' => $notification->token, + 'email' => $user->email, + 'password' => 'password', + 'password_confirmation' => 'password', + ]); + + $response->assertSessionHasNoErrors(); + + return true; + }); + } +} diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php new file mode 100644 index 000000000..468cf94c9 --- /dev/null +++ b/tests/Feature/RegistrationTest.php @@ -0,0 +1,32 @@ +get('/register'); + + $response->assertStatus(200); + } + + public function testNewUsersCanRegister() + { + $response = $this->post('/register', [ + 'name' => 'Test User', + 'email' => 'test@example.com', + 'password' => 'password', + 'password_confirmation' => 'password', + ]); + + $this->assertAuthenticated(); + $response->assertRedirect(RouteServiceProvider::HOME); + } +}