mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
Setup wizard update
This commit is contained in:
@@ -63,9 +63,6 @@ class SetupProductionEnvironment extends Command
|
||||
public function migrateDatabase()
|
||||
{
|
||||
$this->call('migrate:fresh');
|
||||
$this->call('db:seed', [
|
||||
'--class' => 'PaymentGatewaysSeeder'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -171,8 +171,6 @@ class UserController extends Controller
|
||||
{
|
||||
// Store avatar
|
||||
if ($request->hasFile('avatar')) {
|
||||
|
||||
// Update avatar
|
||||
$avatar = store_avatar($request->file('avatar'), 'avatars');
|
||||
}
|
||||
|
||||
|
||||
@@ -20,20 +20,22 @@ class AuthController extends Controller
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function check_account(CheckAccountRequest $request) {
|
||||
public function check_account(CheckAccountRequest $request)
|
||||
{
|
||||
|
||||
// Get User
|
||||
$user = User::where('email', $request->input('email'))->select(['name', 'avatar'])->first();
|
||||
|
||||
// Return user info
|
||||
if ($user) return [
|
||||
'name' => $user->name,
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
];
|
||||
|
||||
// Abort with 404, user not found
|
||||
return abort('404', __('vuefilemanager.user_not_fount'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Login user
|
||||
*
|
||||
@@ -42,17 +44,16 @@ class AuthController extends Controller
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$response = Route::dispatch(self::make_request($request));
|
||||
$response = Route::dispatch(self::make_login_request($request));
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
|
||||
$data = json_decode($response->content(), true);
|
||||
|
||||
return response('Login Successfull!', 200)->cookie('access_token', $data['access_token'], 43200);
|
||||
} else {
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,11 +65,11 @@ class AuthController extends Controller
|
||||
public function register(Request $request)
|
||||
{
|
||||
// Check if account registration is enabled
|
||||
if (! config('vuefilemanager.registration') ) abort(401);
|
||||
if (!config('vuefilemanager.registration')) abort(401);
|
||||
|
||||
// Validate request
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:6', 'confirmed'],
|
||||
]);
|
||||
@@ -81,21 +82,22 @@ class AuthController extends Controller
|
||||
]);
|
||||
|
||||
// Create settings
|
||||
// TODO: set default storage capacity
|
||||
$settings = UserSettings::create([
|
||||
'user_id' => $user->id
|
||||
'user_id' => $user->id,
|
||||
'storage_capacity' => 5,
|
||||
]);
|
||||
|
||||
$response = Route::dispatch(self::make_request($request));
|
||||
$response = Route::dispatch(self::make_login_request($request));
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
|
||||
$data = json_decode($response->content(), true);
|
||||
|
||||
return response('Register Successfull!', 200)->cookie('access_token', $data['access_token'], 43200);
|
||||
} else {
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +108,7 @@ class AuthController extends Controller
|
||||
public function logout()
|
||||
{
|
||||
// Demo preview
|
||||
if (is_demo( Auth::id())) {
|
||||
if (is_demo(Auth::id())) {
|
||||
return response('Logout successfull', 204)
|
||||
->cookie('access_token', '', -1);
|
||||
}
|
||||
@@ -118,18 +120,17 @@ class AuthController extends Controller
|
||||
$token->delete();
|
||||
});
|
||||
|
||||
return response('Logout successfull', 204)
|
||||
return response('Logout successful', 204)
|
||||
->cookie('access_token', '', -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make request for get user token
|
||||
* Make login request for get access token
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $provider
|
||||
* @return Request
|
||||
*/
|
||||
private static function make_request($request)
|
||||
private static function make_login_request($request)
|
||||
{
|
||||
$request->request->add([
|
||||
'grant_type' => 'password',
|
||||
|
||||
607
app/Http/Controllers/General/SetupWizardController.php
Normal file
607
app/Http/Controllers/General/SetupWizardController.php
Normal file
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\General;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\SetupWizard\CreateAdminRequest;
|
||||
use App\Http\Requests\SetupWizard\StoreAppSetupRequest;
|
||||
use App\Http\Requests\SetupWizard\StoreDatabaseCredentialsRequest;
|
||||
use App\Http\Requests\SetupWizard\StoreEnvironmentSetupRequest;
|
||||
use App\Http\Requests\SetupWizard\StoreStripeBillingRequest;
|
||||
use App\Http\Requests\SetupWizard\StoreStripeCredentialsRequest;
|
||||
use App\Http\Requests\SetupWizard\StoreStripePlansRequest;
|
||||
use App\Services\StripeService;
|
||||
use App\Setting;
|
||||
use App\User;
|
||||
use App\UserSettings;
|
||||
use Artisan;
|
||||
use Cartalyst\Stripe\Exception\UnauthorizedException;
|
||||
use Doctrine\DBAL\Driver\PDOException;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Stripe;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class SetupWizardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Inject Stripe Service
|
||||
*/
|
||||
public function __construct(StripeService $stripe)
|
||||
{
|
||||
$this->stripe = $stripe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify Envato purchase code
|
||||
*
|
||||
* @param Request $request
|
||||
* @return ResponseFactory|\Illuminate\Http\Response|mixed
|
||||
*/
|
||||
public function verify_purchase_code(Request $request)
|
||||
{
|
||||
// Author API token
|
||||
$token = 'X3kPkRnIHqauwE7vle3Gvhx6PTY9bvLr';
|
||||
// e3420e63-ce6f-4d04-9b3e-f7f5cc6af7c6
|
||||
|
||||
// Verify purchase code
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => 'Bearer ' . $token
|
||||
])->get('https://api.envato.com/v3/market/author/sale?code=' . $request->purchaseCode);
|
||||
|
||||
if ($response->successful()) {
|
||||
return $response['license'];
|
||||
}
|
||||
|
||||
return response('Purchase code is invalid.', 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up database credentials
|
||||
*
|
||||
* @param StoreDatabaseCredentialsRequest $request
|
||||
* @return ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function setup_database(StoreDatabaseCredentialsRequest $request)
|
||||
{
|
||||
// Set temporary database connection
|
||||
config(['database.connections.test.driver' => $request->connection]);
|
||||
config(['database.connections.test.host' => $request->host]);
|
||||
config(['database.connections.test.port' => $request->port]);
|
||||
config(['database.connections.test.database' => $request->name]);
|
||||
config(['database.connections.test.username' => $request->username]);
|
||||
config(['database.connections.test.password' => $request->password]);
|
||||
|
||||
// Test database connection
|
||||
try {
|
||||
\DB::connection('test')->getPdo();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
throw new HttpException(500, $e->getMessage());
|
||||
}
|
||||
|
||||
$database_credentials = collect([
|
||||
[
|
||||
'name' => 'DB_CONNECTION',
|
||||
'value' => $request->connection,
|
||||
],
|
||||
[
|
||||
'name' => 'DB_HOST',
|
||||
'value' => $request->host,
|
||||
],
|
||||
[
|
||||
'name' => 'DB_PORT',
|
||||
'value' => $request->port,
|
||||
],
|
||||
[
|
||||
'name' => 'DB_DATABASE',
|
||||
'value' => $request->name,
|
||||
],
|
||||
[
|
||||
'name' => 'DB_USERNAME',
|
||||
'value' => $request->username,
|
||||
],
|
||||
[
|
||||
'name' => 'DB_PASSWORD',
|
||||
'value' => $request->password,
|
||||
],
|
||||
]);
|
||||
|
||||
// Store database credentials
|
||||
$database_credentials->each(function ($col) {
|
||||
$this->setEnvironmentValue($col['name'], $col['value']);
|
||||
});
|
||||
|
||||
// Set up application
|
||||
$this->set_up_application();
|
||||
|
||||
return response('Done', 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate database and generate necessary things
|
||||
*/
|
||||
private function set_up_application()
|
||||
{
|
||||
// Clear Cache
|
||||
Artisan::call('cache:clear');
|
||||
Artisan::call('config:clear');
|
||||
|
||||
// Generate app key
|
||||
Artisan::call('key:generate');
|
||||
|
||||
// Migrate database
|
||||
Artisan::call('migrate:fresh');
|
||||
|
||||
// Create Passport Keys
|
||||
Artisan::call('passport:keys', [
|
||||
'--force' => true
|
||||
]);
|
||||
|
||||
// Create Password grant client
|
||||
Artisan::call('passport:client', [
|
||||
'--password' => true,
|
||||
'--name' => 'vuefilemanager',
|
||||
]);
|
||||
|
||||
// Create Personal access client
|
||||
Artisan::call('passport:client', [
|
||||
'--personal' => true,
|
||||
'--name' => 'shared',
|
||||
]);
|
||||
|
||||
// Get generated client
|
||||
$client = \DB::table('oauth_clients')->where('name', '=', 'vuefilemanager')->first();
|
||||
|
||||
// Set passport client to .env
|
||||
$this->setEnvironmentValue('PASSPORT_CLIENT_ID', $client->id);
|
||||
$this->setEnvironmentValue('PASSPORT_CLIENT_SECRET', $client->secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store and test stripe credentials
|
||||
*
|
||||
* @param StoreStripeCredentialsRequest $request
|
||||
* @return ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function store_stripe_credentials(StoreStripeCredentialsRequest $request)
|
||||
{
|
||||
// Create stripe instance
|
||||
$stripe = Stripe::make($request->secret, '2020-03-02');
|
||||
|
||||
// Try to get stripe account details
|
||||
try {
|
||||
$stripe->account()->details();
|
||||
} catch (UnauthorizedException $e) {
|
||||
throw new HttpException(401, $e->getMessage());
|
||||
}
|
||||
|
||||
// Get options
|
||||
$settings = collect([
|
||||
[
|
||||
'name' => 'stripe_currency',
|
||||
'value' => $request->currency,
|
||||
],
|
||||
[
|
||||
'name' => 'stripe_webhook_secret',
|
||||
'value' => $request->webhookSecret,
|
||||
],
|
||||
[
|
||||
'name' => 'stripe_secret_key',
|
||||
'value' => $request->secret,
|
||||
],
|
||||
[
|
||||
'name' => 'stripe_publishable_key',
|
||||
'value' => $request->key,
|
||||
],
|
||||
]);
|
||||
|
||||
// Set stripe credentials to .env
|
||||
$this->setEnvironmentValue('CASHIER_CURRENCY', $request->currency);
|
||||
$this->setEnvironmentValue('STRIPE_KEY', $request->key);
|
||||
$this->setEnvironmentValue('STRIPE_SECRET', $request->secret);
|
||||
$this->setEnvironmentValue('STRIPE_WEBHOOK_SECRET', $request->webhookSecret);
|
||||
|
||||
// Store options
|
||||
$settings->each(function ($col) {
|
||||
Setting::updateOrCreate(['name' => $col['name']], $col);
|
||||
});
|
||||
|
||||
return response('Done', 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store Stripe billings
|
||||
*
|
||||
* @param StoreStripeBillingRequest $request
|
||||
* @return ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function store_stripe_billings(StoreStripeBillingRequest $request)
|
||||
{
|
||||
// Get options
|
||||
$settings = collect([
|
||||
[
|
||||
'name' => 'billing_phone_number',
|
||||
'value' => $request->billing_phone_number,
|
||||
],
|
||||
[
|
||||
'name' => 'billing_postal_code',
|
||||
'value' => $request->billing_postal_code,
|
||||
],
|
||||
[
|
||||
'name' => 'billing_vat_number',
|
||||
'value' => $request->billing_vat_number,
|
||||
],
|
||||
[
|
||||
'name' => 'billing_address',
|
||||
'value' => $request->billing_address,
|
||||
],
|
||||
[
|
||||
'name' => 'billing_country',
|
||||
'value' => $request->billing_country,
|
||||
],
|
||||
[
|
||||
'name' => 'billing_state',
|
||||
'value' => $request->billing_state,
|
||||
],
|
||||
[
|
||||
'name' => 'billing_city',
|
||||
'value' => $request->billing_city,
|
||||
],
|
||||
[
|
||||
'name' => 'billing_name',
|
||||
'value' => $request->billing_name,
|
||||
],
|
||||
]);
|
||||
|
||||
// Store options
|
||||
$settings->each(function ($col) {
|
||||
Setting::updateOrCreate(['name' => $col['name']], $col);
|
||||
});
|
||||
|
||||
return response('Done', 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Stripe subscription plan
|
||||
*
|
||||
* @param StoreStripePlansRequest $request
|
||||
*/
|
||||
public function store_stripe_plans(StoreStripePlansRequest $request)
|
||||
{
|
||||
foreach ($request->input('plans') as $plan) {
|
||||
$this->stripe->createPlan($plan);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store environment setup
|
||||
*
|
||||
* @param StoreEnvironmentSetupRequest $request
|
||||
* @return string
|
||||
*/
|
||||
public function store_environment_setup(StoreEnvironmentSetupRequest $request)
|
||||
{
|
||||
$storage_driver = $request->input('storage.driver');
|
||||
|
||||
if ($storage_driver === 'local') {
|
||||
|
||||
$storage = collect([
|
||||
[
|
||||
'name' => 'FILESYSTEM_DRIVER',
|
||||
'value' => 'local',
|
||||
],
|
||||
]);
|
||||
|
||||
} else if ($storage_driver === 's3') {
|
||||
|
||||
$storage = collect([
|
||||
[
|
||||
'name' => 'FILESYSTEM_DRIVER',
|
||||
'value' => $request->input('storage.driver'),
|
||||
],
|
||||
[
|
||||
'name' => 'AWS_ACCESS_KEY_ID',
|
||||
'value' => $request->input('storage.key'),
|
||||
],
|
||||
[
|
||||
'name' => 'AWS_SECRET_ACCESS_KEY',
|
||||
'value' => $request->input('storage.secret'),
|
||||
],
|
||||
[
|
||||
'name' => 'AWS_DEFAULT_REGION',
|
||||
'value' => $request->input('storage.region'),
|
||||
],
|
||||
[
|
||||
'name' => 'AWS_BUCKET',
|
||||
'value' => $request->input('storage.bucket'),
|
||||
],
|
||||
]);
|
||||
|
||||
} else if ($storage_driver === 'spaces') {
|
||||
|
||||
$storage = collect([
|
||||
[
|
||||
'name' => 'FILESYSTEM_DRIVER',
|
||||
'value' => $request->input('storage.driver'),
|
||||
],
|
||||
[
|
||||
'name' => 'DO_SPACES_KEY',
|
||||
'value' => $request->input('storage.key'),
|
||||
],
|
||||
[
|
||||
'name' => 'DO_SPACES_SECRET',
|
||||
'value' => $request->input('storage.secret'),
|
||||
],
|
||||
[
|
||||
'name' => 'DO_SPACES_ENDPOINT',
|
||||
'value' => $request->input('storage.endpoint'),
|
||||
],
|
||||
[
|
||||
'name' => 'DO_SPACES_REGION',
|
||||
'value' => $request->input('storage.region'),
|
||||
],
|
||||
[
|
||||
'name' => 'DO_SPACES_BUCKET',
|
||||
'value' => $request->input('storage.bucket'),
|
||||
],
|
||||
]);
|
||||
|
||||
} else if ($storage_driver === 'wasabi') {
|
||||
|
||||
$storage = collect([
|
||||
[
|
||||
'name' => 'FILESYSTEM_DRIVER',
|
||||
'value' => $request->input('storage.driver'),
|
||||
],
|
||||
[
|
||||
'name' => 'WASABI_KEY',
|
||||
'value' => $request->input('storage.key'),
|
||||
],
|
||||
[
|
||||
'name' => 'WASABI_SECRET',
|
||||
'value' => $request->input('storage.secret'),
|
||||
],
|
||||
[
|
||||
'name' => 'WASABI_ENDPOINT',
|
||||
'value' => $request->input('storage.endpoint'),
|
||||
],
|
||||
[
|
||||
'name' => 'WASABI_REGION',
|
||||
'value' => $request->input('storage.region'),
|
||||
],
|
||||
[
|
||||
'name' => 'WASABI_BUCKET',
|
||||
'value' => $request->input('storage.bucket'),
|
||||
],
|
||||
]);
|
||||
|
||||
} else if ($storage_driver === 'backblaze') {
|
||||
|
||||
$storage = collect([
|
||||
[
|
||||
'name' => 'FILESYSTEM_DRIVER',
|
||||
'value' => $request->input('storage.driver'),
|
||||
],
|
||||
[
|
||||
'name' => 'BACKBLAZE_KEY',
|
||||
'value' => $request->input('storage.key'),
|
||||
],
|
||||
[
|
||||
'name' => 'BACKBLAZE_SECRET',
|
||||
'value' => $request->input('storage.secret'),
|
||||
],
|
||||
[
|
||||
'name' => 'BACKBLAZE_ENDPOINT',
|
||||
'value' => $request->input('storage.endpoint'),
|
||||
],
|
||||
[
|
||||
'name' => 'BACKBLAZE_REGION',
|
||||
'value' => $request->input('storage.region'),
|
||||
],
|
||||
[
|
||||
'name' => 'BACKBLAZE_BUCKET',
|
||||
'value' => $request->input('storage.bucket'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// Store storage driver options
|
||||
$storage->each(function ($col) {
|
||||
$this->setEnvironmentValue($col['name'], $col['value']);
|
||||
});
|
||||
|
||||
// Get options
|
||||
$mail = collect([
|
||||
[
|
||||
'name' => 'MAIL_DRIVER',
|
||||
'value' => $request->input('mail.driver'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_HOST',
|
||||
'value' => $request->input('mail.host'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_PORT',
|
||||
'value' => $request->input('mail.port'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_USERNAME',
|
||||
'value' => $request->input('mail.username'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_PASSWORD',
|
||||
'value' => $request->input('mail.password'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_ENCRYPTION',
|
||||
'value' => $request->input('mail.encryption'),
|
||||
],
|
||||
]);
|
||||
|
||||
// Store mail options
|
||||
$mail->each(function ($col) {
|
||||
$this->setEnvironmentValue($col['name'], $col['value']);
|
||||
});
|
||||
|
||||
return response('Done', 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store app settings
|
||||
* @param StoreAppSetupRequest $request
|
||||
* @return ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function store_app_settings(StoreAppSetupRequest $request)
|
||||
{
|
||||
// Store Logo
|
||||
if ($request->hasFile('logo')) {
|
||||
$logo = store_system_image($request->file('logo'), 'system');
|
||||
}
|
||||
|
||||
// Store favicon
|
||||
if ($request->hasFile('favicon')) {
|
||||
$favicon = store_system_image($request->file('favicon'), 'system');
|
||||
}
|
||||
|
||||
// Get options
|
||||
$settings = collect([
|
||||
[
|
||||
'name' => 'app_title',
|
||||
'value' => $request->title,
|
||||
],
|
||||
[
|
||||
'name' => 'app_description',
|
||||
'value' => $request->description,
|
||||
],
|
||||
[
|
||||
'name' => 'app_logo',
|
||||
'value' => $request->hasFile('logo') ? $logo : null,
|
||||
],
|
||||
[
|
||||
'name' => 'app_favicon',
|
||||
'value' => $request->hasFile('favicon') ? $favicon : null,
|
||||
],
|
||||
[
|
||||
'name' => 'google_analytics',
|
||||
'value' => $request->googleAnalytics,
|
||||
],
|
||||
[
|
||||
'name' => 'contact_email',
|
||||
'value' => $request->contactMail,
|
||||
],
|
||||
[
|
||||
'name' => 'registration',
|
||||
'value' => $request->userRegistration,
|
||||
],
|
||||
[
|
||||
'name' => 'storage_limitation',
|
||||
'value' => $request->storageLimitation,
|
||||
],
|
||||
[
|
||||
'name' => 'storage_default',
|
||||
'value' => $request->defaultStorage,
|
||||
],
|
||||
]);
|
||||
|
||||
// Store options
|
||||
$settings->each(function ($col) {
|
||||
Setting::updateOrCreate(['name' => $col['name']], $col);
|
||||
});
|
||||
|
||||
return response('Done', 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and login admin account
|
||||
*
|
||||
* @param Request $request
|
||||
* @return ResponseFactory|\Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function create_admin_account(Request $request)
|
||||
{
|
||||
// Validate request
|
||||
$request->validate([
|
||||
'email' => 'required|string|email|unique:users',
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
'name' => 'required|string',
|
||||
'avatar' => 'sometimes|file',
|
||||
]);
|
||||
|
||||
// Store avatar
|
||||
if ($request->hasFile('avatar')) {
|
||||
$avatar = store_avatar($request->file('avatar'), 'avatars');
|
||||
}
|
||||
|
||||
// Create user
|
||||
$user = User::create([
|
||||
'avatar' => $request->hasFile('avatar') ? $avatar : null,
|
||||
'name' => $request->name,
|
||||
'role' => 'admin',
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
// Create settings
|
||||
// TODO: set default storage capacity
|
||||
UserSettings::create([
|
||||
'user_id' => $user->id,
|
||||
'storage_capacity' => 1,
|
||||
]);
|
||||
|
||||
// Retrieve access token
|
||||
$response = Route::dispatch(self::make_login_request($request));
|
||||
|
||||
// Send access token to user if request is successful
|
||||
if ($response->isSuccessful()) {
|
||||
|
||||
$data = json_decode($response->content(), true);
|
||||
|
||||
return response('Admin was created', 200)->cookie('access_token', $data['access_token'], 43200);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make login request for get access token
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Request
|
||||
*/
|
||||
private static function make_login_request($request)
|
||||
{
|
||||
$request->request->add([
|
||||
'grant_type' => 'password',
|
||||
'client_id' => config('services.passport.client_id'),
|
||||
'client_secret' => config('services.passport.client_secret'),
|
||||
'username' => $request->email,
|
||||
'password' => $request->password,
|
||||
'scope' => 'master',
|
||||
]);
|
||||
|
||||
return Request::create(url('/oauth/token'), 'POST', $request->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set environment value
|
||||
*
|
||||
* @param $key
|
||||
* @param $value
|
||||
*/
|
||||
public function setEnvironmentValue($key, $value)
|
||||
{
|
||||
$env_path = app()->environmentFilePath();
|
||||
|
||||
$escaped = preg_quote('=' . env($key), '/');
|
||||
|
||||
file_put_contents($env_path, preg_replace(
|
||||
"/^{$key}{$escaped}/m",
|
||||
$key . '=' . $value,
|
||||
file_get_contents($env_path)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -179,6 +179,28 @@ function store_avatar($image, $path)
|
||||
return $path . '/' . $image_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store system image
|
||||
*
|
||||
* @param $image
|
||||
* @param $path
|
||||
* @return string
|
||||
*/
|
||||
function store_system_image($image, $path)
|
||||
{
|
||||
// Get directory
|
||||
$path = check_directory($path);
|
||||
|
||||
// Store avatar
|
||||
$image_path = Str::random(8) . '-' . str_replace(' ', '', $image->getClientOriginalName());
|
||||
|
||||
// Store image to disk
|
||||
Storage::putFileAs($path, $image, $image_path);
|
||||
|
||||
// Return path to image
|
||||
return $path . '/' . $image_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if directory exist, if no, then create it
|
||||
*
|
||||
|
||||
38
app/Http/Requests/SetupWizard/StoreAppSetupRequest.php
Normal file
38
app/Http/Requests/SetupWizard/StoreAppSetupRequest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\SetupWizard;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreAppSetupRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string',
|
||||
'description' => 'required|string',
|
||||
'logo' => 'sometimes|file',
|
||||
'favicon' => 'sometimes|file',
|
||||
'contactMail' => 'required|email',
|
||||
'googleAnalytics' => 'required|string',
|
||||
'defaultStorage' => 'required|digits_between:1,9',
|
||||
'userRegistration' => 'required|boolean',
|
||||
'storageLimitation' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\SetupWizard;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreDatabaseCredentialsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'connection' => 'required|string',
|
||||
'host' => 'required|string',
|
||||
'port' => 'required|string',
|
||||
'name' => 'required|string',
|
||||
'username' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\SetupWizard;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreEnvironmentSetupRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'storage' => 'required|array',
|
||||
'storage.driver' => 'required|string',
|
||||
'storage.key' => 'sometimes|nullable|string',
|
||||
'storage.secret' => 'sometimes|nullable|string',
|
||||
'storage.endpoint' => 'sometimes|nullable|string',
|
||||
'storage.region' => 'sometimes|nullable|string',
|
||||
'storage.bucket' => 'sometimes|nullable|string',
|
||||
'mail' => 'required|array',
|
||||
'mail.driver' => 'required|string',
|
||||
'mail.host' => 'required|string',
|
||||
'mail.port' => 'required|string',
|
||||
'mail.username' => 'required|string',
|
||||
'mail.password' => 'required|string',
|
||||
'mail.encryption' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
37
app/Http/Requests/SetupWizard/StoreStripeBillingRequest.php
Normal file
37
app/Http/Requests/SetupWizard/StoreStripeBillingRequest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\SetupWizard;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreStripeBillingRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'billing_phone_number' => 'sometimes|nullable|string',
|
||||
'billing_postal_code' => 'required|string',
|
||||
'billing_vat_number' => 'required|string',
|
||||
'billing_address' => 'required|string',
|
||||
'billing_country' => 'required|string',
|
||||
'billing_state' => 'required|string',
|
||||
'billing_city' => 'required|string',
|
||||
'billing_name' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\SetupWizard;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreStripeCredentialsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'currency' => 'required|string',
|
||||
'webhookSecret' => 'required|string',
|
||||
'secret' => 'required|string',
|
||||
'key' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
35
app/Http/Requests/SetupWizard/StoreStripePlansRequest.php
Normal file
35
app/Http/Requests/SetupWizard/StoreStripePlansRequest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\SetupWizard;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreStripePlansRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'plans' => 'required|array',
|
||||
'plans.*.type' => 'required|string',
|
||||
'plans.*.attributes.name' => 'required|string',
|
||||
'plans.*.attributes.price' => 'required|string',
|
||||
'plans.*.attributes.description' => 'sometimes|nullable|string',
|
||||
'plans.*.attributes.capacity' => 'required|digits_between:1,9',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ namespace App\Providers;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Passport\Console\ClientCommand;
|
||||
use Laravel\Passport\Console\InstallCommand;
|
||||
use Laravel\Passport\Console\KeysCommand;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -31,5 +34,12 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
// Set locale for carbon dates
|
||||
setlocale(LC_TIME, $get_time_locale);
|
||||
|
||||
// Install passport commands
|
||||
$this->commands([
|
||||
InstallCommand::class,
|
||||
ClientCommand::class,
|
||||
KeysCommand::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\User;
|
||||
use Artisan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Cashier\Exceptions\IncompletePayment;
|
||||
use Stripe;
|
||||
@@ -16,9 +18,16 @@ class StripeService
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
dd(config('stripe.secret'));
|
||||
|
||||
$this->stripe = Stripe::make(env('STRIPE_SECRET'), '2020-03-02');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Stripe account details
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAccountDetails()
|
||||
{
|
||||
$account = $this->stripe->account()->details();
|
||||
@@ -112,6 +121,8 @@ class StripeService
|
||||
}
|
||||
|
||||
/**
|
||||
* Update customer details
|
||||
*
|
||||
* @param $user
|
||||
*/
|
||||
public function updateCustomerDetails($user)
|
||||
@@ -205,22 +216,38 @@ class StripeService
|
||||
/**
|
||||
* Create plan
|
||||
*
|
||||
* @param $request
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function createPlan($request)
|
||||
public function createPlan($data)
|
||||
{
|
||||
if ($data instanceof Request) {
|
||||
$plan = [
|
||||
'name' => $data->input('attributes.name'),
|
||||
'description' => $data->input('attributes.description'),
|
||||
'price' => $data->input('attributes.price'),
|
||||
'capacity' => $data->input('attributes.capacity'),
|
||||
];
|
||||
} else {
|
||||
$plan = [
|
||||
'name' => $data['attributes']['name'],
|
||||
'description' => $data['attributes']['description'],
|
||||
'price' => $data['attributes']['price'],
|
||||
'capacity' => $data['attributes']['capacity'],
|
||||
];
|
||||
}
|
||||
|
||||
$product = $this->stripe->products()->create([
|
||||
'name' => $request->input('attributes.name'),
|
||||
'description' => $request->input('attributes.description'),
|
||||
'name' => $plan['name'],
|
||||
'description' => $plan['description'],
|
||||
'metadata' => [
|
||||
'capacity' => $request->input('attributes.capacity')
|
||||
'capacity' => $plan['capacity']
|
||||
]
|
||||
]);
|
||||
|
||||
$plan = $this->stripe->plans()->create([
|
||||
'id' => Str::slug($request->input('attributes.name')),
|
||||
'amount' => $request->input('attributes.price'),
|
||||
'id' => Str::slug($plan['name']),
|
||||
'amount' => $plan['price'],
|
||||
'currency' => 'USD',
|
||||
'interval' => 'month',
|
||||
'product' => $product['id'],
|
||||
|
||||
Reference in New Issue
Block a user