Created
October 1, 2024 18:09
-
-
Save namncn/37d2e77e5b2d9c4c86a10091f404e93b to your computer and use it in GitHub Desktop.
- resources/views/installer/license.blade.php - app/Services/InstallerService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services; | |
use App\Libraries\AppLibrary; | |
use Dipokhalder\EnvEditor\EnvEditor; | |
use Exception; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Artisan; | |
use Illuminate\Support\Facades\DB; | |
use Illuminate\Support\Facades\Http; | |
class InstallerService | |
{ | |
public function siteSetup(Request $request): void | |
{ | |
$envService = new EnvEditor(); | |
$envService->addData([ | |
'APP_NAME' => $request->app_name, | |
'APP_URL' => rtrim($request->app_url, '/') | |
]); | |
Artisan::call('optimize:clear'); | |
} | |
public function databaseSetup(Request $request): bool | |
{ | |
$connection = $this->checkDatabaseConnection($request); | |
if ($connection) { | |
$envService = new EnvEditor(); | |
$envService->addData([ | |
'DB_HOST' => $request->database_host, | |
'DB_PORT' => $request->database_port, | |
'DB_DATABASE' => $request->database_name, | |
'DB_USERNAME' => $request->database_username, | |
'DB_PASSWORD' => $request->database_password, | |
]); | |
Artisan::call('config:cache'); | |
Artisan::call('migrate:fresh', ['--force' => true]); | |
if(Artisan::call('db:seed', ['--force' => true])) { | |
Artisan::call('optimize:clear'); | |
Artisan::call('config:clear'); | |
} | |
return true; | |
} | |
return false; | |
} | |
private function checkDatabaseConnection(Request $request): bool | |
{ | |
$connection = 'mysql'; | |
$settings = config("database.connections.$connection"); | |
config([ | |
'database' => [ | |
'default' => $connection, | |
'connections' => [ | |
$connection => array_merge($settings, [ | |
'driver' => $connection, | |
'host' => $request->input('database_host'), | |
'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; | |
} | |
} | |
public function licenseCodeChecker($array) | |
{ | |
// success response without contacting the license server. | |
return (object)[ | |
'status' => true, // successful license check. | |
'message' => 'License verification skipped for development.' | |
]; | |
} | |
public function finalSetup(): void | |
{ | |
$installedLogFile = storage_path('installed'); | |
$dateStamp = date('Y-m-d h:i:s A'); | |
if (!file_exists($installedLogFile)) { | |
$message = trans('installer.installed.success_log_message') . $dateStamp . "\n"; | |
file_put_contents($installedLogFile, $message); | |
} else { | |
$message = trans('installer.installed.update_log_message') . $dateStamp; | |
file_put_contents($installedLogFile, $message . PHP_EOL, FILE_APPEND | LOCK_EX); | |
} | |
Artisan::call('storage:link', ['--force' => true]); | |
$envService = new EnvEditor(); | |
$envService->addData([ | |
'APP_ENV' => 'production', | |
'APP_DEBUG' => 'false' | |
]); | |
Artisan::call('optimize:clear'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('installer.layouts.master') | |
@section('template_title') | |
{{ trans('installer.license.templateTitle') }} | |
@endsection | |
@section('title') | |
{{ trans('For Babiato') }} | |
@endsection | |
@section('container') | |
<ul class="installer-track"> | |
<li onclick="handleLinkForInstaller('{{ route('installer.index') }}')" class="done"> | |
<i class="fa-solid fa-house"></i> | |
</li> | |
<li onclick="handleLinkForInstaller('{{ route('installer.requirement') }}')" class="done"> | |
<i class="fa-solid fa-server"></i> | |
</li> | |
<li onclick="handleLinkForInstaller('{{ route('installer.permission') }}')" class="done"> | |
<i class="fa-sharp fa-solid fa-unlock"></i> | |
</li> | |
<li class="active"><i class="fa-solid fa-key"></i></li> | |
<li><i class="fa-solid fa-gear"></i></li> | |
<li><i class="fa-solid fa-database"></i></li> | |
<li><i class="fa-solid fa-unlock-keyhole"></i></li> | |
</ul> | |
<span class="my-6 w-full h-[1px] bg-[#EFF0F6]"></span> | |
<form method="post" action="{{ route('installer.licenseStore') }}"> | |
<input type="hidden" name="_token" value="{{ csrf_token() }}"> | |
<div class="mb-4"> | |
<label class="text-sm font-medium block mb-1.5 text-heading"> | |
Put anything and click the button<span class="text-[#E93C3C]">*</span><br> | |
<font color="red">By Andrew, Babiato.</font> | |
</label> | |
<input name="license_key" type="text" value="{{ old('license_key') }}" | |
class="w-full h-12 rounded-lg px-4 border border-[#D9DBE9]"> | |
@if ($errors->has('license_key')) | |
<small class="block mt-2 text-sm font-medium text-[#E93C3C]">{{ $errors->first('license_key') }}</small> | |
@endif | |
@if($errors->has('global')) | |
<small class="block mt-2 text-sm font-medium text-[#E93C3C]">{{ $errors->first('global') }}</small> | |
@endif | |
</div> | |
<button type="submit" | |
class="w-fit mx-auto p-3 px-6 rounded-lg flex items-center justify-center gap-3 bg-primary text-white"> | |
<span class="text-sm font-medium capitalize">{{ trans('installer.license.next') }}</span> | |
<i class="fa-solid fa-angle-right text-sm"></i> | |
</button> | |
</form> | |
<div id="installer-modal" class="modal"> | |
<div class="modal-dialog"> | |
<div class="modal-header"> | |
<h3 class="modal-title">{{ trans('installer.license.active_process') }}</h3> | |
<button class="modal-close fa-solid fa-xmark text-xl text-slate-400 hover:text-red-500"></button> | |
</div> | |
<div class="modal-body"> | |
<section class="mb-5"> | |
<h4 class="mb-2 font-bold">{{ __('Step1: ') }} <a href="{{ config('product.officialSite') }}" target="_blank">{{ __(' Go to iNilabs') }}</a></h4> | |
<picture> | |
<img src="{{asset('images/installer/home.png')}}" class="img-fluid img-thumbnail image-css" alt="..."> | |
</picture> | |
</section> | |
<section class="mb-5"> | |
<h4 class="mb-2 font-bold">{{ __('Step2: ') }} <a href="{{ config('product.loginUrl') }}" target="_blank">{{ __(' Login to iNilabs') }}</a></h4> | |
<picture> | |
<img src="{{asset('images/installer/login.png')}}" class="img-fluid img-thumbnail image-css" alt="..."> | |
</picture> | |
</section> | |
<section class="mb-5"> | |
<h4 class="mb-2 font-bold">{{ __('Step3: ') }} <a href="{{ config('product.activeLicense') }}" target="_blank">{{ __(' Active your license code') }} </a></h4> | |
<h6>{{ __('You can easily get the activation code and try to install your product by this code.') }}</h6> | |
<picture class="mt-1"> | |
<img src="{{asset('images/installer/active.png')}}" class="img-fluid img-thumbnail image-css" alt="..."> | |
</picture> | |
</section> | |
</div> | |
</div> | |
</div> | |
@endsection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simply replace all code of these files.