diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index af2cebea..3bf4ab8c 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -49,6 +49,11 @@ class Kernel extends HttpKernel \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, ], + 'installer' => [ + \App\Http\Middleware\EncryptCookies::class, + \Illuminate\Session\Middleware\StartSession::class, + \Illuminate\View\Middleware\ShareErrorsFromSession::class, + ], 'api' => [ // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, diff --git a/beike/Installer/Controllers/DatabaseController.php b/beike/Installer/Controllers/DatabaseController.php new file mode 100644 index 00000000..71102f37 --- /dev/null +++ b/beike/Installer/Controllers/DatabaseController.php @@ -0,0 +1,35 @@ +databaseManager = $databaseManager; + } + + /** + * Migrate and seed the database. + * + * @return \Illuminate\View\View + */ + public function index() + { + $response = $this->databaseManager->migrateAndSeed(); + + return redirect()->route('installer.final') + ->with(['message' => $response]); + } +} diff --git a/beike/Installer/Controllers/EnvironmentController.php b/beike/Installer/Controllers/EnvironmentController.php new file mode 100644 index 00000000..1e4f04c7 --- /dev/null +++ b/beike/Installer/Controllers/EnvironmentController.php @@ -0,0 +1,112 @@ +EnvironmentManager = $environmentManager; + } + + /** + * Display the Environment page. + * + * @return \Illuminate\View\View + */ + public function index() + { + return view('installer::environment-wizard'); + } + + /** + * Processes the newly saved environment configuration (Form Wizard). + * + * @param Request $request + * @param Redirector $redirect + * @return \Illuminate\Http\RedirectResponse + */ + public function saveWizard(Request $request, Redirector $redirect) + { + $rules = config('installer.environment.form.rules'); + $messages = [ + 'environment_custom.required_if' => trans('installer_messages.environment.wizard.form.name_required'), + ]; + + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return $redirect->route('installer.environment')->withInput()->withErrors($validator->errors()); + } + + if (! $this->checkDatabaseConnection($request)) { + return $redirect->route('installer.environment')->withInput()->withErrors([ + 'database_connection' => trans('installer_messages.environment.wizard.form.db_connection_failed'), + ]); + } + + $results = $this->EnvironmentManager->saveFileWizard($request); + + event(new EnvironmentSaved($request)); + + return $redirect->route('installer.database') + ->with(['results' => $results]); + } + + /** + * TODO: We can remove this code if PR will be merged: https://github.com/RachidLaasri/LaravelInstaller/pull/162 + * Validate database connection with user credentials (Form Wizard). + * + * @param Request $request + * @return bool + */ + private function checkDatabaseConnection(Request $request) + { + $connection = $request->input('database_connection'); + + $settings = config("database.connections.$connection"); + + config([ + 'database' => [ + 'default' => $connection, + 'connections' => [ + $connection => array_merge($settings, [ + 'driver' => $connection, + 'host' => $request->input('database_hostname'), + 'port' => $request->input('database_port'), + 'database' => $request->input('database_name'), + 'username' => $request->input('database_username'), + 'password' => $request->input('database_password'), + ]), + ], + ], + ]); + + DB::purge(); + + try { + DB::connection()->getPdo(); + + return true; + } catch (Exception $e) { + return false; + } + } +} diff --git a/beike/Installer/Controllers/FinalController.php b/beike/Installer/Controllers/FinalController.php new file mode 100644 index 00000000..f743ecd0 --- /dev/null +++ b/beike/Installer/Controllers/FinalController.php @@ -0,0 +1,31 @@ +runFinal(); + $finalStatusMessage = $fileManager->update(); + $finalEnvFile = $environment->getEnvContent(); + + event(new LaravelInstallerFinished); + + return view('installer::finished', compact('finalMessages', 'finalStatusMessage', 'finalEnvFile')); + } +} diff --git a/beike/Installer/Controllers/PermissionsController.php b/beike/Installer/Controllers/PermissionsController.php new file mode 100644 index 00000000..fa0a2238 --- /dev/null +++ b/beike/Installer/Controllers/PermissionsController.php @@ -0,0 +1,36 @@ +permissions = $checker; + } + + /** + * Display the permissions check page. + * + * @return \Illuminate\View\View + */ + public function index() + { + $permissions = $this->permissions->check( + config('installer.permissions') + ); + + return view('installer::permissions', compact('permissions')); + } +} diff --git a/beike/Installer/Controllers/RequirementsController.php b/beike/Installer/Controllers/RequirementsController.php new file mode 100644 index 00000000..e606b9fa --- /dev/null +++ b/beike/Installer/Controllers/RequirementsController.php @@ -0,0 +1,39 @@ +requirements = $checker; + } + + /** + * Display the requirements page. + * + * @return \Illuminate\View\View + */ + public function index() + { + $phpSupportInfo = $this->requirements->checkPHPversion( + config('installer.core.minPhpVersion') + ); + $requirements = $this->requirements->check( + config('installer.requirements') + ); + + return view('installer::requirements', compact('requirements', 'phpSupportInfo')); + } +} diff --git a/beike/Installer/Controllers/WelcomeController.php b/beike/Installer/Controllers/WelcomeController.php new file mode 100644 index 00000000..d263674b --- /dev/null +++ b/beike/Installer/Controllers/WelcomeController.php @@ -0,0 +1,23 @@ + + * @created 2022-08-12 20:17:04 + * @modified 2022-08-12 20:17:04 + */ + +namespace Beike\Installer\Controllers; + +use App\Http\Controllers\Controller; +use Illuminate\Http\Request; + +class WelcomeController extends Controller +{ + public function index() + { + return view('installer::welcome'); + } +} diff --git a/beike/Installer/Helpers/DatabaseManager.php b/beike/Installer/Helpers/DatabaseManager.php new file mode 100644 index 00000000..349527ff --- /dev/null +++ b/beike/Installer/Helpers/DatabaseManager.php @@ -0,0 +1,95 @@ +sqlite($outputLog); + + return $this->migrate($outputLog); + } + + /** + * Run the migration and call the seeder. + * + * @param \Symfony\Component\Console\Output\BufferedOutput $outputLog + * @return array + */ + private function migrate(BufferedOutput $outputLog) + { + try { + Artisan::call('migrate', ['--force'=> true], $outputLog); + } catch (Exception $e) { + return $this->response($e->getMessage(), 'error', $outputLog); + } + + return $this->seed($outputLog); + } + + /** + * Seed the database. + * + * @param \Symfony\Component\Console\Output\BufferedOutput $outputLog + * @return array + */ + private function seed(BufferedOutput $outputLog) + { + try { + Artisan::call('db:seed', ['--force' => true], $outputLog); + } catch (Exception $e) { + return $this->response($e->getMessage(), 'error', $outputLog); + } + + return $this->response(trans('installer_messages.final.finished'), 'success', $outputLog); + } + + /** + * Return a formatted error messages. + * + * @param string $message + * @param string $status + * @param \Symfony\Component\Console\Output\BufferedOutput $outputLog + * @return array + */ + private function response($message, $status, BufferedOutput $outputLog) + { + return [ + 'status' => $status, + 'message' => $message, + 'dbOutputLog' => $outputLog->fetch(), + ]; + } + + /** + * Check database type. If SQLite, then create the database file. + * + * @param \Symfony\Component\Console\Output\BufferedOutput $outputLog + */ + private function sqlite(BufferedOutput $outputLog) + { + if (DB::connection() instanceof SQLiteConnection) { + $database = DB::connection()->getDatabaseName(); + if (! file_exists($database)) { + touch($database); + DB::reconnect(Config::get('database.default')); + } + $outputLog->write('Using SqlLite database: '.$database, 1); + } + } +} diff --git a/beike/Installer/Helpers/EnvironmentManager.php b/beike/Installer/Helpers/EnvironmentManager.php new file mode 100644 index 00000000..53af9e09 --- /dev/null +++ b/beike/Installer/Helpers/EnvironmentManager.php @@ -0,0 +1,135 @@ +envPath = base_path('.env'); + $this->envExamplePath = base_path('.env.example'); + } + + /** + * Get the content of the .env file. + * + * @return string + */ + public function getEnvContent() + { + if (! file_exists($this->envPath)) { + if (file_exists($this->envExamplePath)) { + copy($this->envExamplePath, $this->envPath); + } else { + touch($this->envPath); + } + } + + return file_get_contents($this->envPath); + } + + /** + * Get the the .env file path. + * + * @return string + */ + public function getEnvPath() + { + return $this->envPath; + } + + /** + * Get the the .env.example file path. + * + * @return string + */ + public function getEnvExamplePath() + { + return $this->envExamplePath; + } + + /** + * Save the edited content to the .env file. + * + * @param Request $input + * @return string + */ + public function saveFileClassic(Request $input) + { + $message = trans('installer_messages.environment.success'); + + try { + file_put_contents($this->envPath, $input->get('envConfig')); + } catch (Exception $e) { + $message = trans('installer_messages.environment.errors'); + } + + return $message; + } + + /** + * Save the form content to the .env file. + * + * @param Request $request + * @return string + */ + public function saveFileWizard(Request $request) + { + $results = trans('installer_messages.environment.success'); + + $envFileData = + 'APP_NAME=\''.$request->app_name."'\n". + 'APP_ENV='.$request->environment."\n". + 'APP_KEY='.'base64:'.base64_encode(Str::random(32))."\n". + 'APP_DEBUG='.$request->app_debug."\n". + 'APP_LOG_LEVEL='.$request->app_log_level."\n". + 'APP_URL='.$request->app_url."\n\n". + 'DB_CONNECTION='.$request->database_connection."\n". + 'DB_HOST='.$request->database_hostname."\n". + 'DB_PORT='.$request->database_port."\n". + 'DB_DATABASE='.$request->database_name."\n". + 'DB_USERNAME='.$request->database_username."\n". + 'DB_PASSWORD='.$request->database_password."\n\n". + 'BROADCAST_DRIVER='.$request->broadcast_driver."\n". + 'CACHE_DRIVER='.$request->cache_driver."\n". + 'SESSION_DRIVER='.$request->session_driver."\n". + 'QUEUE_DRIVER='.$request->queue_driver."\n\n". + 'REDIS_HOST='.$request->redis_hostname."\n". + 'REDIS_PASSWORD='.$request->redis_password."\n". + 'REDIS_PORT='.$request->redis_port."\n\n". + 'MAIL_DRIVER='.$request->mail_driver."\n". + 'MAIL_HOST='.$request->mail_host."\n". + 'MAIL_PORT='.$request->mail_port."\n". + 'MAIL_USERNAME='.$request->mail_username."\n". + 'MAIL_PASSWORD='.$request->mail_password."\n". + 'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". + 'PUSHER_APP_ID='.$request->pusher_app_id."\n". + 'PUSHER_APP_KEY='.$request->pusher_app_key."\n". + 'PUSHER_APP_SECRET='.$request->pusher_app_secret; + + try { + file_put_contents($this->envPath, $envFileData); + } catch (Exception $e) { + $results = trans('installer_messages.environment.errors'); + } + + return $results; + } +} diff --git a/beike/Installer/Helpers/FinalInstallManager.php b/beike/Installer/Helpers/FinalInstallManager.php new file mode 100644 index 00000000..0b05190b --- /dev/null +++ b/beike/Installer/Helpers/FinalInstallManager.php @@ -0,0 +1,79 @@ +generateKey($outputLog); + $this->publishVendorAssets($outputLog); + + return $outputLog->fetch(); + } + + /** + * Generate New Application Key. + * + * @param \Symfony\Component\Console\Output\BufferedOutput $outputLog + * @return \Symfony\Component\Console\Output\BufferedOutput|array + */ + private static function generateKey(BufferedOutput $outputLog) + { + try { + if (config('installer.final.key')) { + Artisan::call('key:generate', ['--force'=> true], $outputLog); + } + } catch (Exception $e) { + return static::response($e->getMessage(), $outputLog); + } + + return $outputLog; + } + + /** + * Publish vendor assets. + * + * @param \Symfony\Component\Console\Output\BufferedOutput $outputLog + * @return \Symfony\Component\Console\Output\BufferedOutput|array + */ + private static function publishVendorAssets(BufferedOutput $outputLog) + { + try { + if (config('installer.final.publish')) { + Artisan::call('vendor:publish', ['--all' => true], $outputLog); + } + } catch (Exception $e) { + return static::response($e->getMessage(), $outputLog); + } + + return $outputLog; + } + + /** + * Return a formatted error messages. + * + * @param $message + * @param \Symfony\Component\Console\Output\BufferedOutput $outputLog + * @return array + */ + private static function response($message, BufferedOutput $outputLog) + { + return [ + 'status' => 'error', + 'message' => $message, + 'dbOutputLog' => $outputLog->fetch(), + ]; + } +} diff --git a/beike/Installer/Helpers/InstalledFileManager.php b/beike/Installer/Helpers/InstalledFileManager.php new file mode 100644 index 00000000..f1e48c3e --- /dev/null +++ b/beike/Installer/Helpers/InstalledFileManager.php @@ -0,0 +1,40 @@ +create(); + } +} diff --git a/beike/Installer/Helpers/MigrationsHelper.php b/beike/Installer/Helpers/MigrationsHelper.php new file mode 100644 index 00000000..96ddb100 --- /dev/null +++ b/beike/Installer/Helpers/MigrationsHelper.php @@ -0,0 +1,31 @@ +get()->pluck('migration'); + } +} diff --git a/beike/Installer/Helpers/PermissionsChecker.php b/beike/Installer/Helpers/PermissionsChecker.php new file mode 100644 index 00000000..07aa9f82 --- /dev/null +++ b/beike/Installer/Helpers/PermissionsChecker.php @@ -0,0 +1,83 @@ +results['permissions'] = []; + + $this->results['errors'] = null; + } + + /** + * Check for the folders permissions. + * + * @param array $folders + * @return array + */ + public function check(array $folders) + { + foreach ($folders as $folder => $permission) { + if (! ($this->getPermission($folder) >= $permission)) { + $this->addFileAndSetErrors($folder, $permission, false); + } else { + $this->addFile($folder, $permission, true); + } + } + + return $this->results; + } + + /** + * Get a folder permission. + * + * @param $folder + * @return string + */ + private function getPermission($folder) + { + return substr(sprintf('%o', fileperms(base_path($folder))), -4); + } + + /** + * Add the file to the list of results. + * + * @param $folder + * @param $permission + * @param $isSet + */ + private function addFile($folder, $permission, $isSet) + { + array_push($this->results['permissions'], [ + 'folder' => $folder, + 'permission' => $permission, + 'isSet' => $isSet, + ]); + } + + /** + * Add the file and set the errors. + * + * @param $folder + * @param $permission + * @param $isSet + */ + private function addFileAndSetErrors($folder, $permission, $isSet) + { + $this->addFile($folder, $permission, $isSet); + + $this->results['errors'] = true; + } +} diff --git a/beike/Installer/Helpers/RequirementsChecker.php b/beike/Installer/Helpers/RequirementsChecker.php new file mode 100644 index 00000000..fe6b158b --- /dev/null +++ b/beike/Installer/Helpers/RequirementsChecker.php @@ -0,0 +1,114 @@ + $requirement) { + switch ($type) { + // check php requirements + case 'php': + foreach ($requirements[$type] as $requirement) { + $results['requirements'][$type][$requirement] = true; + + if (! extension_loaded($requirement)) { + $results['requirements'][$type][$requirement] = false; + + $results['errors'] = true; + } + } + break; + // check apache requirements + case 'apache': + foreach ($requirements[$type] as $requirement) { + // if function doesn't exist we can't check apache modules + if (function_exists('apache_get_modules')) { + $results['requirements'][$type][$requirement] = true; + + if (! in_array($requirement, apache_get_modules())) { + $results['requirements'][$type][$requirement] = false; + + $results['errors'] = true; + } + } + } + break; + } + } + + return $results; + } + + /** + * Check PHP version requirement. + * + * @return array + */ + public function checkPHPversion(string $minPhpVersion = null) + { + $minVersionPhp = $minPhpVersion; + $currentPhpVersion = $this->getPhpVersionInfo(); + $supported = false; + + if ($minPhpVersion == null) { + $minVersionPhp = $this->getMinPhpVersion(); + } + + if (version_compare($currentPhpVersion['version'], $minVersionPhp) >= 0) { + $supported = true; + } + + $phpStatus = [ + 'full' => $currentPhpVersion['full'], + 'current' => $currentPhpVersion['version'], + 'minimum' => $minVersionPhp, + 'supported' => $supported, + ]; + + return $phpStatus; + } + + /** + * Get current Php version information. + * + * @return array + */ + private static function getPhpVersionInfo() + { + $currentVersionFull = PHP_VERSION; + preg_match("#^\d+(\.\d+)*#", $currentVersionFull, $filtered); + $currentVersion = $filtered[0]; + + return [ + 'full' => $currentVersionFull, + 'version' => $currentVersion, + ]; + } + + /** + * Get minimum PHP version ID. + * + * @return string _minPhpVersion + */ + protected function getMinPhpVersion() + { + return $this->_minPhpVersion; + } +} diff --git a/beike/Installer/Helpers/functions.php b/beike/Installer/Helpers/functions.php new file mode 100644 index 00000000..c3634e2b --- /dev/null +++ b/beike/Installer/Helpers/functions.php @@ -0,0 +1,23 @@ + 'Laravel Installer', + 'next' => 'Next Step', + 'back' => 'Previous', + 'finish' => 'Install', + 'forms' => [ + 'errorTitle' => 'The Following errors occurred:', + ], + + /* + * + * Home page translations. + * + */ + 'welcome' => [ + 'templateTitle' => 'Welcome', + 'title' => 'Laravel Installer', + 'message' => 'Easy Installation and Setup Wizard.', + 'next' => 'Check Requirements', + ], + + /* + * + * Requirements page translations. + * + */ + 'requirements' => [ + 'templateTitle' => 'Step 1 | Server Requirements', + 'title' => 'Server Requirements', + 'next' => 'Check Permissions', + ], + + /* + * + * Permissions page translations. + * + */ + 'permissions' => [ + 'templateTitle' => 'Step 2 | Permissions', + 'title' => 'Permissions', + 'next' => 'Configure Environment', + ], + + /* + * + * Environment page translations. + * + */ + 'environment' => [ + 'menu' => [ + 'templateTitle' => 'Step 3 | Environment Settings', + 'title' => 'Environment Settings', + 'desc' => 'Please select how you want to configure the apps .env file.', + 'wizard-button' => 'Form Wizard Setup', + 'classic-button' => 'Classic Text Editor', + ], + 'wizard' => [ + 'templateTitle' => 'Step 3 | Environment Settings | Guided Wizard', + 'title' => 'Guided .env Wizard', + 'tabs' => [ + 'environment' => 'Environment', + 'database' => 'Database', + 'application' => 'Application', + ], + 'form' => [ + 'name_required' => 'An environment name is required.', + 'app_name_label' => 'App Name', + 'app_name_placeholder' => 'App Name', + 'app_environment_label' => 'App Environment', + 'app_environment_label_local' => 'Local', + 'app_environment_label_developement' => 'Development', + 'app_environment_label_qa' => 'Qa', + 'app_environment_label_production' => 'Production', + 'app_environment_label_other' => 'Other', + 'app_environment_placeholder_other' => 'Enter your environment...', + 'app_debug_label' => 'App Debug', + 'app_debug_label_true' => 'True', + 'app_debug_label_false' => 'False', + 'app_log_level_label' => 'App Log Level', + 'app_log_level_label_debug' => 'debug', + 'app_log_level_label_info' => 'info', + 'app_log_level_label_notice' => 'notice', + 'app_log_level_label_warning' => 'warning', + 'app_log_level_label_error' => 'error', + 'app_log_level_label_critical' => 'critical', + 'app_log_level_label_alert' => 'alert', + 'app_log_level_label_emergency' => 'emergency', + 'app_url_label' => 'App Url', + 'app_url_placeholder' => 'App Url', + 'db_connection_failed' => 'Could not connect to the database.', + 'db_connection_label' => 'Database Connection', + 'db_connection_label_mysql' => 'mysql', + 'db_connection_label_sqlite' => 'sqlite', + 'db_connection_label_pgsql' => 'pgsql', + 'db_connection_label_sqlsrv' => 'sqlsrv', + 'db_host_label' => 'Database Host', + 'db_host_placeholder' => 'Database Host', + 'db_port_label' => 'Database Port', + 'db_port_placeholder' => 'Database Port', + 'db_name_label' => 'Database Name', + 'db_name_placeholder' => 'Database Name', + 'db_username_label' => 'Database User Name', + 'db_username_placeholder' => 'Database User Name', + 'db_password_label' => 'Database Password', + 'db_password_placeholder' => 'Database Password', + + 'app_tabs' => [ + 'more_info' => 'More Info', + 'broadcasting_title' => 'Broadcasting, Caching, Session, & Queue', + 'broadcasting_label' => 'Broadcast Driver', + 'broadcasting_placeholder' => 'Broadcast Driver', + 'cache_label' => 'Cache Driver', + 'cache_placeholder' => 'Cache Driver', + 'session_label' => 'Session Driver', + 'session_placeholder' => 'Session Driver', + 'queue_label' => 'Queue Driver', + 'queue_placeholder' => 'Queue Driver', + 'redis_label' => 'Redis Driver', + 'redis_host' => 'Redis Host', + 'redis_password' => 'Redis Password', + 'redis_port' => 'Redis Port', + + 'mail_label' => 'Mail', + 'mail_driver_label' => 'Mail Driver', + 'mail_driver_placeholder' => 'Mail Driver', + 'mail_host_label' => 'Mail Host', + 'mail_host_placeholder' => 'Mail Host', + 'mail_port_label' => 'Mail Port', + 'mail_port_placeholder' => 'Mail Port', + 'mail_username_label' => 'Mail Username', + 'mail_username_placeholder' => 'Mail Username', + 'mail_password_label' => 'Mail Password', + 'mail_password_placeholder' => 'Mail Password', + 'mail_encryption_label' => 'Mail Encryption', + 'mail_encryption_placeholder' => 'Mail Encryption', + + 'pusher_label' => 'Pusher', + 'pusher_app_id_label' => 'Pusher App Id', + 'pusher_app_id_palceholder' => 'Pusher App Id', + 'pusher_app_key_label' => 'Pusher App Key', + 'pusher_app_key_palceholder' => 'Pusher App Key', + 'pusher_app_secret_label' => 'Pusher App Secret', + 'pusher_app_secret_palceholder' => 'Pusher App Secret', + ], + 'buttons' => [ + 'setup_database' => 'Setup Database', + 'setup_application' => 'Setup Application', + 'install' => 'Install', + ], + ], + ], + 'classic' => [ + 'templateTitle' => 'Step 3 | Environment Settings | Classic Editor', + 'title' => 'Classic Environment Editor', + 'save' => 'Save .env', + 'back' => 'Use Form Wizard', + 'install' => 'Save and Install', + ], + 'success' => 'Your .env file settings have been saved.', + 'errors' => 'Unable to save the .env file, Please create it manually.', + ], + + 'install' => 'Install', + + /* + * + * Installed Log translations. + * + */ + 'installed' => [ + 'success_log_message' => 'Laravel Installer successfully INSTALLED on ', + ], + + /* + * + * Final page translations. + * + */ + 'final' => [ + 'title' => 'Installation Finished', + 'templateTitle' => 'Installation Finished', + 'finished' => 'Application has been successfully installed.', + 'migration' => 'Migration & Seed Console Output:', + 'console' => 'Application Console Output:', + 'log' => 'Installation Log Entry:', + 'env' => 'Final .env File:', + 'exit' => 'Click here to exit', + ], + + /* + * + * Update specific translations + * + */ + 'updater' => [ + /* + * + * Shared translations. + * + */ + 'title' => 'Laravel Updater', + + /* + * + * Welcome page translations for update feature. + * + */ + 'welcome' => [ + 'title' => 'Welcome To The Updater', + 'message' => 'Welcome to the update wizard.', + ], + + /* + * + * Welcome page translations for update feature. + * + */ + 'overview' => [ + 'title' => 'Overview', + 'message' => 'There is 1 update.|There are :number updates.', + 'install_updates' => 'Install Updates', + ], + + /* + * + * Final page translations. + * + */ + 'final' => [ + 'title' => 'Finished', + 'finished' => 'Application\'s database has been successfully updated.', + 'exit' => 'Click here to exit', + ], + + 'log' => [ + 'success_message' => 'Laravel Installer successfully UPDATED on ', + ], + ], +]; diff --git a/beike/Installer/Lang/zh-CN/installer_messages.php b/beike/Installer/Lang/zh-CN/installer_messages.php new file mode 100644 index 00000000..8d735d01 --- /dev/null +++ b/beike/Installer/Lang/zh-CN/installer_messages.php @@ -0,0 +1,64 @@ + 'Laravel安装程序', + 'next' => '下一步', + 'finish' => '安装', + + /* + * + * Home page translations. + * + */ + 'welcome' => [ + 'title' => '欢迎来到Laravel安装程序', + 'message' => '欢迎来到安装向导.', + ], + + /* + * + * Requirements page translations. + * + */ + 'requirements' => [ + 'title' => '环境要求', + ], + + /* + * + * Permissions page translations. + * + */ + 'permissions' => [ + 'title' => '权限', + ], + + /* + * + * Environment page translations. + * + */ + 'environment' => [ + 'title' => '环境设置', + 'save' => '保存 .env', + 'success' => '.env 文件保存成功.', + 'errors' => '无法保存 .env 文件, 请手动创建它.', + ], + + /* + * + * Final page translations. + * + */ + 'final' => [ + 'title' => '完成', + 'finished' => '应用已成功安装.', + 'exit' => '点击退出', + ], +]; diff --git a/beike/Installer/Providers/InstallerServiceProvider.php b/beike/Installer/Providers/InstallerServiceProvider.php new file mode 100644 index 00000000..6024ebb4 --- /dev/null +++ b/beike/Installer/Providers/InstallerServiceProvider.php @@ -0,0 +1,29 @@ +loadRoutesFrom(__DIR__ . '/../Routes/installer.php'); + + $uri = request()->getRequestUri(); + if (!Str::startsWith($uri, "/installer")) { + return; + } + + $this->mergeConfigFrom(__DIR__ . '/../config.php', 'installer'); + $this->loadViewsFrom(__DIR__ . '/../views', 'installer'); + + $pathInstaller = base_path('installer'); + $this->loadTranslationsFrom("{$pathInstaller}/Lang", ''); + } +} diff --git a/beike/Installer/Routes/installer.php b/beike/Installer/Routes/installer.php new file mode 100644 index 00000000..870ba5cf --- /dev/null +++ b/beike/Installer/Routes/installer.php @@ -0,0 +1,22 @@ +name('installer.') + ->middleware(['installer']) + ->group(function () { + Route::get('/', [WelcomeController::class, 'index'])->name('welcome'); + Route::get('requirements', [RequirementsController::class, 'index'])->name('requirements'); + Route::get('permissions', [PermissionsController::class, 'index'])->name('permissions'); + Route::get('environment', [EnvironmentController::class, 'index'])->name('environment'); + Route::post('environment/save', [EnvironmentController::class, 'saveWizard'])->name('environment.save'); + Route::get('database', [DatabaseController::class, 'index'])->name('database'); + Route::get('final', [FinalController::class, 'index'])->name('final'); + + }); diff --git a/beike/Installer/Views/environment-wizard.blade.php b/beike/Installer/Views/environment-wizard.blade.php new file mode 100644 index 00000000..2ace0028 --- /dev/null +++ b/beike/Installer/Views/environment-wizard.blade.php @@ -0,0 +1,167 @@ +@extends('vendor.installer.layouts.master') + +@section('template_title') + {{ trans('installer_messages.environment.wizard.templateTitle') }} +@endsection + +@section('title') + + {!! trans('installer_messages.environment.wizard.title') !!} +@endsection + +@section('container') +
+ + + + + + + +
+
+ + +
+ + + @if ($errors->has('app_url')) + + + {{ $errors->first('app_url') }} + + @endif +
+ +
+ +
+
+
+ +
+ + + @if ($errors->has('database_connection')) + + + {{ $errors->first('database_connection') }} + + @endif +
+ +
+ + + @if ($errors->has('database_hostname')) + + + {{ $errors->first('database_hostname') }} + + @endif +
+ +
+ + + @if ($errors->has('database_port')) + + + {{ $errors->first('database_port') }} + + @endif +
+ +
+ + + @if ($errors->has('database_name')) + + + {{ $errors->first('database_name') }} + + @endif +
+ +
+ + + @if ($errors->has('database_username')) + + + {{ $errors->first('database_username') }} + + @endif +
+ +
+ + + @if ($errors->has('database_password')) + + + {{ $errors->first('database_password') }} + + @endif +
+ +
+ +
+
+
+ +
+@endsection + +@section('scripts') + +@endsection diff --git a/beike/Installer/Views/finished.blade.php b/beike/Installer/Views/finished.blade.php new file mode 100644 index 00000000..73ac9126 --- /dev/null +++ b/beike/Installer/Views/finished.blade.php @@ -0,0 +1,32 @@ +@extends('vendor.installer.layouts.master') + +@section('template_title') + {{ trans('installer_messages.final.templateTitle') }} +@endsection + +@section('title') + + {{ trans('installer_messages.final.title') }} +@endsection + +@section('container') + + @if(session('message')['dbOutputLog']) +

{{ trans('installer_messages.final.migration') }}

+
{{ session('message')['dbOutputLog'] }}
+ @endif + +

{{ trans('installer_messages.final.console') }}

+
{{ $finalMessages }}
+ +

{{ trans('installer_messages.final.log') }}

+
{{ $finalStatusMessage }}
+ +

{{ trans('installer_messages.final.env') }}

+
{{ $finalEnvFile }}
+ +
+ {{ trans('installer_messages.final.exit') }} +
+ +@endsection diff --git a/beike/Installer/Views/layouts/master-update.blade.php b/beike/Installer/Views/layouts/master-update.blade.php new file mode 100644 index 00000000..00ff410b --- /dev/null +++ b/beike/Installer/Views/layouts/master-update.blade.php @@ -0,0 +1,46 @@ + + + + + + + @if (trim($__env->yieldContent('template_title')))@yield('template_title') | @endif {{ trans('installer_messages.updater.title') }} + + + + + @yield('style') + + + +
+
+
+

@yield('title')

+
+ +
+ @yield('container') +
+
+
+ + diff --git a/beike/Installer/Views/layouts/master.blade.php b/beike/Installer/Views/layouts/master.blade.php new file mode 100644 index 00000000..fc3e98ce --- /dev/null +++ b/beike/Installer/Views/layouts/master.blade.php @@ -0,0 +1,114 @@ + + + + + + + + @if (trim($__env->yieldContent('template_title')))@yield('template_title') | @endif {{ trans('installer_messages.title') }} + + + + + @yield('style') + + + +
+
+
+

@yield('title')

+
+ +
+ @if (session('message')) +

+ + @if(is_array(session('message'))) + {{ session('message')['message'] }} + @else + {{ session('message') }} + @endif + +

+ @endif + @if(session()->has('errors')) +
+ +

+ + {{ trans('installer_messages.forms.errorTitle') }} +

+
    + @foreach($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + @yield('container') +
+
+
+ @yield('scripts') + + + diff --git a/beike/Installer/Views/permissions.blade.php b/beike/Installer/Views/permissions.blade.php new file mode 100644 index 00000000..11563559 --- /dev/null +++ b/beike/Installer/Views/permissions.blade.php @@ -0,0 +1,35 @@ +@extends('installer::layouts.master') + +@section('template_title') + {{ trans('installer_messages.permissions.templateTitle') }} +@endsection + +@section('title') + + {{ trans('installer_messages.permissions.title') }} +@endsection + +@section('container') + + + + @if ( ! isset($permissions['errors'])) +
+ + {{ trans('installer_messages.permissions.next') }} + + +
+ @endif + +@endsection diff --git a/beike/Installer/Views/requirements.blade.php b/beike/Installer/Views/requirements.blade.php new file mode 100644 index 00000000..240d3aea --- /dev/null +++ b/beike/Installer/Views/requirements.blade.php @@ -0,0 +1,50 @@ +@extends('installer::layouts.master') + +@section('template_title') + {{ trans('installer_messages.requirements.templateTitle') }} +@endsection + +@section('title') + + {{ trans('installer_messages.requirements.title') }} +@endsection + +@section('container') + + @foreach($requirements['requirements'] as $type => $requirement) + + @endforeach + + @if ( ! isset($requirements['errors']) && $phpSupportInfo['supported'] ) +
+ + {{ trans('installer_messages.requirements.next') }} + + +
+ @endif + +@endsection diff --git a/beike/Installer/Views/welcome.blade.php b/beike/Installer/Views/welcome.blade.php new file mode 100644 index 00000000..393b086b --- /dev/null +++ b/beike/Installer/Views/welcome.blade.php @@ -0,0 +1,21 @@ +@extends('installer::layouts.master') + +@section('template_title') + {{ trans('installer_messages.welcome.templateTitle') }} +@endsection + +@section('title') + {{ trans('installer_messages.welcome.title') }} +@endsection + +@section('container') +

+ {{ trans('installer_messages.welcome.message') }} +

+

+ + {{ trans('installer_messages.welcome.next') }} + + +

+@endsection diff --git a/beike/Installer/config.php b/beike/Installer/config.php new file mode 100644 index 00000000..4e8cf0b1 --- /dev/null +++ b/beike/Installer/config.php @@ -0,0 +1,129 @@ + [ + 'minPhpVersion' => '7.0.0', + ], + 'final' => [ + 'key' => true, + 'publish' => false, + ], + 'requirements' => [ + 'php' => [ + 'openssl', + 'pdo', + 'mbstring', + 'tokenizer', + 'JSON', + 'cURL', + ], + 'apache' => [ + 'mod_rewrite', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Folders Permissions + |-------------------------------------------------------------------------- + | + | This is the default Laravel folders permissions, if your application + | requires more permissions just add them to the array list bellow. + | + */ + 'permissions' => [ + 'storage/framework/' => '775', + 'storage/logs/' => '775', + 'bootstrap/cache/' => '775', + ], + + /* + |-------------------------------------------------------------------------- + | Environment Form Wizard Validation Rules & Messages + |-------------------------------------------------------------------------- + | + | This are the default form field validation rules. Available Rules: + | https://laravel.com/docs/5.4/validation#available-validation-rules + | + */ + 'environment' => [ + 'form' => [ + 'rules' => [ + 'app_url' => 'required|url', + 'database_connection' => 'required|string|max:50', + 'database_hostname' => 'required|string|max:50', + 'database_port' => 'required|numeric', + 'database_name' => 'required|string|max:50', + 'database_username' => 'required|string|max:50', + 'database_password' => 'nullable|string|max:50', + 'mail_driver' => 'required|string|max:50', + 'mail_host' => 'required|string|max:50', + 'mail_port' => 'required|string|max:50', + 'mail_username' => 'required|string|max:50', + 'mail_password' => 'required|string|max:50', + 'mail_encryption' => 'required|string|max:50', + 'pusher_app_id' => 'max:50', + 'pusher_app_key' => 'max:50', + 'pusher_app_secret' => 'max:50', + ], + ], + ], + + /* + |-------------------------------------------------------------------------- + | Installed Middleware Options + |-------------------------------------------------------------------------- + | Different available status switch configuration for the + | canInstall middleware located in `canInstall.php`. + | + */ + 'installed' => [ + 'redirectOptions' => [ + 'route' => [ + 'name' => 'welcome', + 'data' => [], + ], + 'abort' => [ + 'type' => '404', + ], + 'dump' => [ + 'data' => 'Dumping a not found message.', + ], + ], + ], + + /* + |-------------------------------------------------------------------------- + | Selected Installed Middleware Option + |-------------------------------------------------------------------------- + | The selected option fo what happens when an installer instance has been + | Default output is to `/resources/views/error/404.blade.php` if none. + | The available middleware options include: + | route, abort, dump, 404, default, '' + | + */ + 'installedAlreadyAction' => '', + + /* + |-------------------------------------------------------------------------- + | Updater Enabled + |-------------------------------------------------------------------------- + | Can the application run the '/update' route with the migrations. + | The default option is set to False if none is present. + | Boolean value + | + */ + 'updaterEnabled' => 'true', + +]; diff --git a/beike/Shop/Http/Controllers/LoginController.php b/beike/Shop/Http/Controllers/LoginController.php new file mode 100644 index 00000000..22addc6d --- /dev/null +++ b/beike/Shop/Http/Controllers/LoginController.php @@ -0,0 +1,39 @@ + + * @created 2022-06-22 20:22:54 + * @modified 2022-06-22 20:22:54 + */ + +namespace Beike\Shop\Http\Controllers; + +use Beike\Models\Customer; +use Illuminate\Http\Request; + +class LoginController extends Controller +{ + public function index() + { + return view('login'); + } + + public function store(Request $request) + { + $credentials = $request->validate([ + 'email' => ['required', 'email'], + 'password' => ['required'], + ]); + + if (auth(Customer::AUTH_GUARD)->attempt($credentials)) { + return redirect(route('home')); + } + + return back()->withErrors([ + 'email' => 'The provided credentials do not match our records.', + ]); + } +} diff --git a/config/app.php b/config/app.php index 7f3e6f58..517967c8 100644 --- a/config/app.php +++ b/config/app.php @@ -178,6 +178,7 @@ return [ Beike\Admin\Providers\AdminServiceProvider::class, Beike\Shop\Providers\ShopServiceProvider::class, Beike\Shop\Providers\PluginServiceProvider::class, + Beike\Installer\Providers\InstallerServiceProvider::class, ], diff --git a/themes/default/login.blade.php b/themes/default/login.blade.php new file mode 100644 index 00000000..481ca6d5 --- /dev/null +++ b/themes/default/login.blade.php @@ -0,0 +1,41 @@ +@extends('layout.master') + +@section('content') +

Login

+
+ @csrf + +
+
+
+ 邮箱 +
+ +
+ @error('email') + + @enderror +
+ +
+
+
+ 密码 +
+ +
+ @error('password') + + @enderror +
+ + @if (session('error')) +
+ {{ session('error') }} +
+ @endif + + +
+ +@endsection