Merge pull request #95 from LogischJo/development
Fix: Force Verification
This commit is contained in:
commit
7fd8f7e8bd
|
@ -12,11 +12,7 @@ use App\Models\Product;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Notifications\ServerCreationError;
|
use App\Notifications\ServerCreationError;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\View\Factory;
|
|
||||||
use Illuminate\Contracts\View\View;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,18 +34,28 @@ class ServerController extends Controller
|
||||||
return redirect()->route('servers.index')->with('error', "You've already reached your server limit!");
|
return redirect()->route('servers.index')->with('error', "You've already reached your server limit!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Required Verification for creating an server
|
||||||
|
if (Configuration::getValueByKey('FORCE_EMAIL_VERIFICATION', false) === 'true' && !Auth::user()->hasVerifiedEmail()) {
|
||||||
|
return redirect()->route('profile.index')->with('error', "You havent verified your email! Thats required to create an server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Required Verification for creating an server
|
||||||
|
if (Configuration::getValueByKey('FORCE_DISCORD_VERIFICATION', false) === 'true' && !Auth::user()->discordUser) {
|
||||||
|
return redirect()->route('profile.index')->with('error', "You havent linked an Discord Account to your profile! Thats required to create an server");
|
||||||
|
}
|
||||||
|
|
||||||
//minimum credits
|
//minimum credits
|
||||||
if (Auth::user()->credits <= Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER' , 50)) {
|
if (Auth::user()->credits <= Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50)) {
|
||||||
return redirect()->route('servers.index')->with('error', "You do not have the required amount of credits to create a new server!");
|
return redirect()->route('servers.index')->with('error', "You do not have the required amount of credits to create a new server!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return view('servers.create')->with([
|
return view('servers.create')->with([
|
||||||
'products' => Product::where('disabled' , '=' , false)->orderBy('price', 'asc')->get(),
|
'products' => Product::where('disabled', '=', false)->orderBy('price', 'asc')->get(),
|
||||||
'locations' => Location::whereHas('nodes' , function ($query) {
|
'locations' => Location::whereHas('nodes', function ($query) {
|
||||||
$query->where('disabled' , '=' , false);
|
$query->where('disabled', '=', false);
|
||||||
})->get(),
|
})->get(),
|
||||||
'nests' => Nest::where('disabled' , '=' , false)->get(),
|
'nests' => Nest::where('disabled', '=', false)->get(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,11 +63,11 @@ class ServerController extends Controller
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
"name" => "required|max:191",
|
"name" => "required|max:191",
|
||||||
"description" => "nullable|max:191",
|
"description" => "nullable|max:191",
|
||||||
"node_id" => "required|exists:nodes,id",
|
"node_id" => "required|exists:nodes,id",
|
||||||
"egg_id" => "required|exists:eggs,id",
|
"egg_id" => "required|exists:eggs,id",
|
||||||
"product_id" => "required|exists:products,id",
|
"product_id" => "required|exists:products,id",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//limit validation
|
//limit validation
|
||||||
|
@ -70,17 +76,27 @@ class ServerController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
//minimum credits
|
//minimum credits
|
||||||
if (Auth::user()->credits <= Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER' , 50)) {
|
if (Auth::user()->credits <= Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50)) {
|
||||||
return redirect()->route('servers.index')->with('error', "You do not have the required amount of credits to create a new server!");
|
return redirect()->route('servers.index')->with('error', "You do not have the required amount of credits to create a new server!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Required Verification for creating an server
|
||||||
|
if (Configuration::getValueByKey('FORCE_EMAIL_VERIFICATION', false) === 'true' && !Auth::user()->hasVerifiedEmail()) {
|
||||||
|
return redirect()->route('profile.index')->with('error', "You havent verified your email! Thats required to create an server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Required Verification for creating an server
|
||||||
|
if (Configuration::getValueByKey('FORCE_DISCORD_VERIFICATION', false) === 'true' && !Auth::user()->discordUser) {
|
||||||
|
return redirect()->route('profile.index')->with('error', "You havent linked an Discord Account to your profile! Thats required to create an server");
|
||||||
|
}
|
||||||
|
|
||||||
//create server
|
//create server
|
||||||
$egg = Egg::findOrFail($request->input('egg_id'));
|
$egg = Egg::findOrFail($request->input('egg_id'));
|
||||||
$server = Auth::user()->servers()->create($request->all());
|
$server = Auth::user()->servers()->create($request->all());
|
||||||
$node = Node::findOrFail($request->input('node_id'));
|
$node = Node::findOrFail($request->input('node_id'));
|
||||||
|
|
||||||
//create server on pterodactyl
|
//create server on pterodactyl
|
||||||
$response = Pterodactyl::createServer($server , $egg , $node);
|
$response = Pterodactyl::createServer($server, $egg, $node);
|
||||||
|
|
||||||
if (is_null($response)) return $this->serverCreationFailed($server);
|
if (is_null($response)) return $this->serverCreationFailed($server);
|
||||||
if ($response->failed()) return $this->serverCreationFailed($server);
|
if ($response->failed()) return $this->serverCreationFailed($server);
|
||||||
|
@ -88,7 +104,7 @@ class ServerController extends Controller
|
||||||
//update server with pterodactyl_id
|
//update server with pterodactyl_id
|
||||||
$server->update([
|
$server->update([
|
||||||
'pterodactyl_id' => $response->json()['attributes']['id'],
|
'pterodactyl_id' => $response->json()['attributes']['id'],
|
||||||
'identifier' => $response->json()['attributes']['identifier']
|
'identifier' => $response->json()['attributes']['identifier']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return redirect()->route('servers.index')->with('success', 'server created');
|
return redirect()->route('servers.index')->with('success', 'server created');
|
||||||
|
@ -109,7 +125,7 @@ class ServerController extends Controller
|
||||||
try {
|
try {
|
||||||
$server->delete();
|
$server->delete();
|
||||||
return redirect()->route('servers.index')->with('success', 'server removed');
|
return redirect()->route('servers.index')->with('success', 'server removed');
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
return redirect()->route('servers.index')->with('error', 'An exception has occurred while trying to remove a resource');
|
return redirect()->route('servers.index')->with('error', 'An exception has occurred while trying to remove a resource');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,9 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Configuration;
|
||||||
use App\Models\PaypalProduct;
|
use App\Models\PaypalProduct;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Contracts\View\Factory;
|
|
||||||
use Illuminate\Contracts\View\View;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\Response;
|
|
||||||
|
|
||||||
class StoreController extends Controller
|
class StoreController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -16,10 +13,21 @@ class StoreController extends Controller
|
||||||
{
|
{
|
||||||
$isPaypalSetup = false;
|
$isPaypalSetup = false;
|
||||||
if (env('PAYPAL_SECRET') && env('PAYPAL_CLIENT_ID')) $isPaypalSetup = true;
|
if (env('PAYPAL_SECRET') && env('PAYPAL_CLIENT_ID')) $isPaypalSetup = true;
|
||||||
if (env('APP_ENV' , 'local') == 'local') $isPaypalSetup = true;
|
if (env('APP_ENV', 'local') == 'local') $isPaypalSetup = true;
|
||||||
|
|
||||||
|
|
||||||
|
//Required Verification for creating an server
|
||||||
|
if (Configuration::getValueByKey('FORCE_EMAIL_VERIFICATION', false) === 'true' && !Auth::user()->hasVerifiedEmail()) {
|
||||||
|
return redirect()->route('profile.index')->with('error', "You havent verified your email! Thats required to buy credits.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Required Verification for creating an server
|
||||||
|
if (Configuration::getValueByKey('FORCE_DISCORD_VERIFICATION', false) === 'true' && !Auth::user()->discordUser) {
|
||||||
|
return redirect()->route('profile.index')->with('error', "You havent linked an Discord Account to your profile! Thats required to buy credits");
|
||||||
|
}
|
||||||
|
|
||||||
return view('store.index')->with([
|
return view('store.index')->with([
|
||||||
'products' => PaypalProduct::where('disabled' , '=' , false)->orderBy('price' , 'asc')->get(),
|
'products' => PaypalProduct::where('disabled', '=', false)->orderBy('price', 'asc')->get(),
|
||||||
'isPaypalSetup' => $isPaypalSetup
|
'isPaypalSetup' => $isPaypalSetup
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,5 +82,21 @@ class ConfigurationSeeder extends Seeder
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'description' => 'updates the users server limit to this amount (unless the user already has a higher server limit) after making a purchase with real money, set to 0 to ignore this.',
|
'description' => 'updates the users server limit to this amount (unless the user already has a higher server limit) after making a purchase with real money, set to 0 to ignore this.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Configuration::firstOrCreate([
|
||||||
|
'key' => 'FORCE_EMAIL_VERIFICATION',
|
||||||
|
] , [
|
||||||
|
'value' => 'false',
|
||||||
|
'type' => 'boolean',
|
||||||
|
'description' => 'Force an user to verify the email adress before creating a server / buying credits.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
Configuration::firstOrCreate([
|
||||||
|
'key' => 'FORCE_DISCORD_VERIFICATION',
|
||||||
|
] , [
|
||||||
|
'value' => 'false',
|
||||||
|
'type' => 'boolean',
|
||||||
|
'description' => 'Force an user to link an Discord Account before creating a server / buying credits.'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue