Skip to content

Commit

Permalink
0.9.3 (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
1day2die authored Feb 23, 2023
2 parents a4c2fa2 + 24f1319 commit 485aeed
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 303 deletions.
20 changes: 15 additions & 5 deletions app/Extensions/PaymentGateways/PayPal/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Log;
use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\ProductionEnvironment;
use PayPalCheckoutSdk\Core\SandboxEnvironment;
Expand Down Expand Up @@ -74,7 +75,7 @@ function PaypalPay(Request $request)
"application_context" => [
"cancel_url" => route('payment.Cancel'),
"return_url" => route('payment.PayPalSuccess', ['payment' => $payment->id]),
'brand_name' => config('app.name', 'Laravel'),
'brand_name' => config('app.name', 'Controlpanel.GG'),
'shipping_preference' => 'NO_SHIPPING'
]

Expand All @@ -85,14 +86,23 @@ function PaypalPay(Request $request)
// Call API with your client and get a response for your call
$response = getPayPalClient()->execute($request);

// check for any errors in the response
if ($response->statusCode != 201) {
throw new \Exception($response->statusCode);
}

// make sure the link is not empty
if (empty($response->result->links[1]->href)) {
throw new \Exception('No redirect link found');
}

Redirect::away($response->result->links[1]->href)->send();
return;
} catch (HttpException $ex) {
error_log($ex->statusCode);
error_log($ex->getMessage());

Log::error('PayPal Payment: ' . $ex->getMessage());
$payment->delete();
Redirect::route('payment.Cancel');

Redirect::route('store.index')->with('error', __('Payment failed'))->send();
return;
}
}
Expand Down
40 changes: 7 additions & 33 deletions app/Http/Controllers/Admin/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Log;

class ServerController extends Controller
{
Expand All @@ -27,38 +28,6 @@ public function index()
return view('admin.servers.index');
}

/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param Server $server
* @return Response
*/
public function show(Server $server)
{
//
}

/**
* Show the form for editing the specified resource.
*
Expand Down Expand Up @@ -196,6 +165,8 @@ public function syncServers()
public function dataTable(Request $request)
{
$query = Server::with(['user', 'product']);


if ($request->has('product')) {
$query->where('product_id', '=', $request->input('product'));
}
Expand All @@ -204,6 +175,9 @@ public function dataTable(Request $request)
}
$query->select('servers.*');

Log::info($request->input('order'));


return datatables($query)
->addColumn('user', function (Server $server) {
return '<a href="' . route('admin.users.show', $server->user->id) . '">' . $server->user->name . '</a>';
Expand Down Expand Up @@ -232,7 +206,7 @@ public function dataTable(Request $request)
';
})
->addColumn('status', function (Server $server) {
$labelColor = $server->isSuspended() ? 'text-danger' : 'text-success';
$labelColor = $server->suspended ? 'text-danger' : 'text-success';

return '<i class="fas ' . $labelColor . ' fa-circle mr-2"></i>';
})
Expand Down
41 changes: 16 additions & 25 deletions app/Http/Controllers/Admin/ShopProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class ShopProductController extends Controller
{

/**
* Display a listing of the resource.
*
Expand Down Expand Up @@ -66,23 +67,12 @@ public function store(Request $request)
'display' => 'required|string|max:60',
]);

$disabled = ! is_null($request->input('disabled'));
$disabled = !is_null($request->input('disabled'));
ShopProduct::create(array_merge($request->all(), ['disabled' => $disabled]));

return redirect()->route('admin.store.index')->with('success', __('Store item has been created!'));
}

/**
* Display the specified resource.
*
* @param ShopProduct $shopProduct
* @return Response
*/
public function show(ShopProduct $shopProduct)
{
//
}

/**
* Show the form for editing the specified resource.
*
Expand Down Expand Up @@ -116,7 +106,7 @@ public function update(Request $request, ShopProduct $shopProduct)
'display' => 'required|string|max:60',
]);

$disabled = ! is_null($request->input('disabled'));
$disabled = !is_null($request->input('disabled'));
$shopProduct->update(array_merge($request->all(), ['disabled' => $disabled]));

return redirect()->route('admin.store.index')->with('success', __('Store item has been updated!'));
Expand All @@ -129,7 +119,7 @@ public function update(Request $request, ShopProduct $shopProduct)
*/
public function disable(Request $request, ShopProduct $shopProduct)
{
$shopProduct->update(['disabled' => ! $shopProduct->disabled]);
$shopProduct->update(['disabled' => !$shopProduct->disabled]);

return redirect()->route('admin.store.index')->with('success', __('Product has been updated!'));
}
Expand All @@ -147,32 +137,33 @@ public function destroy(ShopProduct $shopProduct)
return redirect()->back()->with('success', __('Store item has been removed!'));
}

public function dataTable()
public function dataTable(Request $request)
{
$query = ShopProduct::query();


return datatables($query)
->addColumn('actions', function (ShopProduct $shopProduct) {
return '
<a data-content="'.__('Edit').'" data-toggle="popover" data-trigger="hover" data-placement="top" href="'.route('admin.store.edit', $shopProduct->id).'" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
<a data-content="' . __('Edit') . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.store.edit', $shopProduct->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
<form class="d-inline" onsubmit="return submitResult();" method="post" action="'.route('admin.store.destroy', $shopProduct->id).'">
'.csrf_field().'
'.method_field('DELETE').'
<button data-content="'.__('Delete').'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm btn-danger mr-1"><i class="fas fa-trash"></i></button>
<form class="d-inline" onsubmit="return submitResult();" method="post" action="' . route('admin.store.destroy', $shopProduct->id) . '">
' . csrf_field() . '
' . method_field('DELETE') . '
<button data-content="' . __('Delete') . '" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm btn-danger mr-1"><i class="fas fa-trash"></i></button>
</form>
';
})
->addColumn('disabled', function (ShopProduct $shopProduct) {
$checked = $shopProduct->disabled == false ? 'checked' : '';

return '
<form class="d-inline" onsubmit="return submitResult();" method="post" action="'.route('admin.store.disable', $shopProduct->id).'">
'.csrf_field().'
'.method_field('PATCH').'
<form class="d-inline" onsubmit="return submitResult();" method="post" action="' . route('admin.store.disable', $shopProduct->id) . '">
' . csrf_field() . '
' . method_field('PATCH') . '
<div class="custom-control custom-switch">
<input '.$checked.' name="disabled" onchange="this.form.submit()" type="checkbox" class="custom-control-input" id="switch'.$shopProduct->id.'">
<label class="custom-control-label" for="switch'.$shopProduct->id.'"></label>
<input ' . $checked . ' name="disabled" onchange="this.form.submit()" type="checkbox" class="custom-control-input" id="switch' . $shopProduct->id . '">
<label class="custom-control-label" for="switch' . $shopProduct->id . '"></label>
</div>
</form>
';
Expand Down
66 changes: 30 additions & 36 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

class UserController extends Controller
{

private Pterodactyl $pterodactyl;

public function __construct(Pterodactyl $pterodactyl)
Expand Down Expand Up @@ -132,7 +133,7 @@ public function update(Request $request, User $user)
]);
}

if (! is_null($request->input('new_password'))) {
if (!is_null($request->input('new_password'))) {
$request->validate([
'new_password' => 'required|string|min:8',
'new_password_confirmation' => 'required|same:new_password',
Expand Down Expand Up @@ -259,7 +260,7 @@ public function notify(Request $request)
public function toggleSuspended(User $user)
{
try {
! $user->isSuspended() ? $user->suspend() : $user->unSuspend();
!$user->isSuspended() ? $user->suspend() : $user->unSuspend();
} catch (Exception $exception) {
return redirect()->back()->with('error', $exception->getMessage());
}
Expand All @@ -270,52 +271,45 @@ public function toggleSuspended(User $user)
/**
* @throws Exception
*/
public function dataTable()
public function dataTable(Request $request)
{
$query = User::with(['discordUser', 'servers'])->select('users.*');
$query = User::with('discordUser')->withCount('servers');
// manually count referrals in user_referrals table
$query->selectRaw('users.*, (SELECT COUNT(*) FROM user_referrals WHERE user_referrals.referral_id = users.id) as referrals_count');


return datatables($query)
->addColumn('avatar', function (User $user) {
return '<img width="28px" height="28px" class="rounded-circle ml-1" src="'.$user->getAvatar().'">';
return '<img width="28px" height="28px" class="rounded-circle ml-1" src="' . $user->getAvatar() . '">';
})
->addColumn('credits', function (User $user) {
return '<i class="fas fa-coins mr-2"></i> '.$user->credits();
return '<i class="fas fa-coins mr-2"></i> ' . $user->credits();
})
->addColumn('verified', function (User $user) {
return $user->getVerifiedStatus();
})
->addColumn('servers', function (User $user) {
return $user->servers->count();
})
->addColumn('referrals', function (User $user) {
return DB::table('user_referrals')->where('referral_id', '=', $user->id)->count();
})
->addColumn('discordId', function (User $user) {
return $user->discordUser ? $user->discordUser->id : '';
})
->addColumn('last_seen', function (User $user) {
return ['display' => $user->last_seen ? $user->last_seen->diffForHumans() : '',
'raw' => $user->last_seen ? strtotime($user->last_seen) : '', ];
})
->addColumn('actions', function (User $user) {
$suspendColor = $user->isSuspended() ? 'btn-success' : 'btn-warning';
$suspendIcon = $user->isSuspended() ? 'fa-play-circle' : 'fa-pause-circle';
$suspendText = $user->isSuspended() ? __('Unsuspend') : __('Suspend');

return '
<a data-content="'.__('Login as User').'" data-toggle="popover" data-trigger="hover" data-placement="top" href="'.route('admin.users.loginas', $user->id).'" class="btn btn-sm btn-primary mr-1"><i class="fas fa-sign-in-alt"></i></a>
<a data-content="'.__('Verify').'" data-toggle="popover" data-trigger="hover" data-placement="top" href="'.route('admin.users.verifyEmail', $user->id).'" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-envelope"></i></a>
<a data-content="'.__('Show').'" data-toggle="popover" data-trigger="hover" data-placement="top" href="'.route('admin.users.show', $user->id).'" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-eye"></i></a>
<a data-content="'.__('Edit').'" data-toggle="popover" data-trigger="hover" data-placement="top" href="'.route('admin.users.edit', $user->id).'" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
<form class="d-inline" method="post" action="'.route('admin.users.togglesuspend', $user->id).'">
'.csrf_field().'
<button data-content="'.$suspendText.'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm '.$suspendColor.' text-white mr-1"><i class="far '.$suspendIcon.'"></i></button>
</form>
<form class="d-inline" onsubmit="return submitResult();" method="post" action="'.route('admin.users.destroy', $user->id).'">
'.csrf_field().'
'.method_field('DELETE').'
<button data-content="'.__('Delete').'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm btn-danger mr-1"><i class="fas fa-trash"></i></button>
</form>
<a data-content="' . __('Login as User') . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.loginas', $user->id) . '" class="btn btn-sm btn-primary mr-1"><i class="fas fa-sign-in-alt"></i></a>
<a data-content="' . __('Verify') . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.verifyEmail', $user->id) . '" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-envelope"></i></a>
<a data-content="' . __('Show') . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.show', $user->id) . '" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-eye"></i></a>
<a data-content="' . __('Edit') . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.edit', $user->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
<form class="d-inline" method="post" action="' . route('admin.users.togglesuspend', $user->id) . '">
' . csrf_field() . '
<button data-content="' . $suspendText . '" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm ' . $suspendColor . ' text-white mr-1"><i class="far ' . $suspendIcon . '"></i></button>
</form>
<form class="d-inline" onsubmit="return submitResult();" method="post" action="' . route('admin.users.destroy', $user->id) . '">
' . csrf_field() . '
' . method_field('DELETE') . '
<button data-content="' . __('Delete') . '" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm btn-danger mr-1"><i class="fas fa-trash"></i></button>
</form>
';
})
->editColumn('role', function (User $user) {
Expand All @@ -334,15 +328,15 @@ public function dataTable()
break;
}

return '<span class="badge '.$badgeColor.'">'.$user->role.'</span>';
return '<span class="badge ' . $badgeColor . '">' . $user->role . '</span>';
})
->editColumn('last_seen', function (User $user) {
return $user->last_seen ? $user->last_seen->diffForHumans() : __('Never');
})
->editColumn('name', function (User $user) {
return '<a class="text-info" target="_blank" href="'.config('SETTINGS::SYSTEM:PTERODACTYL:URL').'/admin/users/view/'.$user->pterodactyl_id.'">'.strip_tags($user->name).'</a>';
return '<a class="text-info" target="_blank" href="' . config('SETTINGS::SYSTEM:PTERODACTYL:URL') . '/admin/users/view/' . $user->pterodactyl_id . '">' . strip_tags($user->name) . '</a>';
})
/*->orderColumn('last_seen', function ($query) {
$query->orderBy('last_seen', "desc");
})*/
->rawColumns(['avatar', 'name', 'credits', 'role', 'usage', 'referrals', 'actions', 'last_seen'])
->make(true);
->rawColumns(['avatar', 'name', 'credits', 'role', 'usage', 'actions'])
->make();
}
}
Loading

0 comments on commit 485aeed

Please sign in to comment.