Skip to content

Commit

Permalink
Adding discord settings to admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 23, 2018
1 parent 9468745 commit 26178f6
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-debug.log
# Laravel 4 specific
bootstrap/compiled.php
app/storage/
storage/settings.json

# Laravel 5 & Lumen specific
public/storage
Expand Down
43 changes: 43 additions & 0 deletions app/Http/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use \DiscordWebhooks\Client;
use \DiscordWebhooks\Embed;

class SettingsController extends Controller
{
Expand Down Expand Up @@ -49,9 +51,50 @@ public function savePterodactyl(){
if(Request("ptero_appkey")!= null){
\Setting::set("pterodactyl_appkey", Request("ptero_appkey"));
}
// \Setting::save();
session()->flash('good', 'Your settings have been saved');
return redirect()->back();
}

public function showDiscord(){
return view('admin.pages.settings.discord.index');
}
public function testDiscord(){
$orderlink = \Setting::get("DISCORD_ORDER_WEBHOOK");
$adminlink = \Setting::get("DISCORD_LOGIN_WEBHOOK");

$embed = new Embed();
$embed->color("1376020");
$embed->description('Discord Webook test called from MinePoS admin panel');

if($orderlink != null){
(new Client($orderlink))->embed($embed)->send();
}
if($adminlink != null){
(new Client($adminlink))->embed($embed)->send();
}
session()->flash('good', 'Discord test complete please check discord and verify the messages have been sent');
return redirect()->back();
}
public function saveDiscord(){

\Setting::set("DISCORD_LOGIN_ENABLED", (Request("admin_enabled") != null));
\Setting::save();

\Setting::set("DISCORD_ORDER_ENABLED", (Request("order_enabled") != null));
\Setting::save();

if(Request("admin_link")!= null){
\Setting::set("DISCORD_LOGIN_WEBHOOK", Request("admin_link"));
\Setting::save();
}
if(Request("admin_link")!= null){
\Setting::set("DISCORD_ORDER_WEBHOOK", Request("order_link"));
\Setting::save();
}
session()->flash('good', 'Your settings have been saved');
return redirect()->back();
//DISCORD_LOGIN_WEBHOOK
}

public function magicPterodactyl(){
Expand Down
28 changes: 14 additions & 14 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ public function showCategory(Category $category){
return view('category')->with(['category'=>$category]);
}
public function paymentDone(){
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$order = \App\Order::find($item_number);
if($order == null){
abort(404);
return;
}
return view('paymentDone')->with(compact("item_name", "item_number", "payment_status","payment_amount","payment_currency","txn_id","receiver_email","payer_email","order"));
// $item_name = $_POST['item_name'];
// $item_number = $_POST['item_number'];
// $payment_status = $_POST['payment_status'];
// $payment_amount = $_POST['mc_gross'];
// $payment_currency = $_POST['mc_currency'];
// $txn_id = $_POST['txn_id'];
// $receiver_email = $_POST['receiver_email'];
// $payer_email = $_POST['payer_email'];
// $order = \App\Order::find($item_number);
// if($order == null){
// abort(404);
// return;
// }
return view('paymentDone');
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/PayPalTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function index(){
}

$order = new Order;
$commands = "{ \"13\": [ \"bc %player% has just donated!\",\"give %player% diamond\",\"spawn %player%\" ] }";
$sid = \App\Server::all()[0]->id;
$commands = "{ \"".$sid."\": [ \"bc %player% has just donated!\",\"give %player% diamond\"] }";
$commands = str_replace("%player%", \Store::username(), $commands);

$order->username = \Store::username();
Expand Down Expand Up @@ -61,7 +62,7 @@ public function paypalIpn()
Log::info("Payment verified agenst payapl and inserted to orders table to the database.");
$ids = explode('|', $ipn->getPostData()['custom']);

$order = \App\Order::find($ids[0]);
$order = \App\Order::find($ipn->getPostData()['item_number']);
$order->txid = $ipn->getPostData()['txn_id'];
$order->gateway = "paypal";

Expand Down
6 changes: 3 additions & 3 deletions app/Listeners/UserEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use \DiscordWebhooks\Client;
use \DiscordWebhooks\Embed;

use \Setting;
class UserEventListener
{
/**
Expand Down Expand Up @@ -37,12 +37,12 @@ public function onUserLogout($event)

public function onUserLogin($event)
{
if(env('DISCORD_LOGIN_ENABLED', false)){
if(Setting::get('DISCORD_LOGIN_ENABLED', false)){
$ip = \Request::ip();
if(env('APP_DEBUG', false)){
$ip = preg_replace('/[0-9]+/', '*', $ip);
}
$webhook = env('DISCORD_LOGIN_WEBHOOK');
$webhook = Setting::get('DISCORD_LOGIN_WEBHOOK');

$webhook = new Client($webhook);
$embed = new Embed();
Expand Down
6 changes: 3 additions & 3 deletions app/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function lastIPN(){

public function orderNotification()
{
if(env('DISCORD_ORDER_ENABLED', false)){
$webhook = env('DISCORD_ORDER_WEBHOOK');
if(\Setting::get('DISCORD_ORDER_ENABLED', false)){
$webhook = \Setting::get('DISCORD_ORDER_WEBHOOK');

$webhook = new Client($webhook);
$embed = new Embed();
Expand All @@ -25,7 +25,7 @@ public function orderNotification()
$webhook->embed($embed)->send();
}

\Mail::to($this->lastIPN()['payer_email'])->send(new \App\Mail\OrderProcessed($this));
//\Mail::to($this->lastIPN()['payer_email'])->send(new \App\Mail\OrderProcessed($this));
}
public static function paymentsDays($days)
{
Expand Down
1 change: 0 additions & 1 deletion resources/views/PayPalTest.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<input type="hidden" name="business" value="{{\Setting::get('paypal_email')}}" />
<input type="hidden" name="notify_url" value="{{route('paypal.ipn')}}" />
<input type="hidden" name="cancel_return" value="{{route('store.index')}}" />
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="return" value="{{route('store.paymentdone')}}" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="custom" value="{{$order->id}}|{{$order->username}}"/>
Expand Down
2 changes: 2 additions & 0 deletions resources/views/admin/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet" href="/admin/bower_components/bootstrap/dist/css/bootstrap.min.css">

<!-- Font Awesome -->
<link rel="stylesheet" href="/admin/bower_components/font-awesome/css/font-awesome.min.css">

<!-- Ionicons -->
<link rel="stylesheet" href="/admin/bower_components/Ionicons/css/ionicons.min.css">
<!-- Theme style -->
Expand Down
87 changes: 87 additions & 0 deletions resources/views/admin/pages/settings/discord/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
@extends('admin.layout')

@section('title')
Discord
@endsection

@section('desc')
Eye, Nice to see you want to use our discord intergration
@endsection

@section('content')
<div class="col-md-8">
<div class="box box-info">
<div class="box-header">
<h3 class="box-title">Discord

</h3>
</div>
<!-- /.box-header -->
<form action="{{route('admin.settings.discord')}}" method="POST">
{{csrf_field()}}
<div class="box-body pad">


<div class="checkbox icheck">
<label>
<input type="checkbox" @if(Setting::get('DISCORD_LOGIN_ENABLED', false)) checked @endif name="admin_enabled" value="admin_enabled"> Admin Login Notifications
</label>
</div>
<div class="checkbox icheck">
<label>
<input @if(Setting::get('DISCORD_ORDER_ENABLED', false)) checked @endif type="checkbox" name="order_enabled" value="order_enabled"> Order Notifications
</label>
</div>
<br>
<label for="adminlink">Admin Login Notificatoins</label>
<input class="form-control" required id="adminlink" type="text" name="admin_link" value="{{\Setting::get('DISCORD_LOGIN_WEBHOOK')}}"/>
<label for="adminlink">Order Notificatoins</label>

<input class="form-control" required id="orderlink" type="text" name="order_link" value="{{\Setting::get('DISCORD_ORDER_WEBHOOK')}}"/>

</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
<!-- /.box -->
</div>


<div class="col-md-4">
<div class="box box-success">
<div class="box-header">
<h3 class="box-title">Test webhooks
</h3>
</div>
<!-- /.box-header -->
<form action="{{route('admin.settings.discord.test')}}" method="POST">
{{csrf_field()}}
<div class="box-body pad">
This test process will attempt to send messages to both the webhooks
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Lets Go!</button>
</div>
</form>
</div>
<!-- /.box -->
</div>
@endsection

@section('head')
<link rel="stylesheet" href="/admin/plugins/iCheck/square/blue.css">
@endsection
@section('extra')
<script src="/admin/plugins/iCheck/icheck.min.js"></script>
<script>
$(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' /* optional */
});
});
</script>
@endsection
6 changes: 3 additions & 3 deletions resources/views/admin/parts/navnormal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</li>
@endif

@if(\Auth::user()->can('list orders') || \Auth::user()->can('create order'))
@if(\Auth::user()->can('list order') || \Auth::user()->can('create order'))
<li class="treeview @if(\Request::is('admin/orders*')) active @endif">
<a href="#">
<i class="fa fa-credit-card-alt"></i> <span>Orders</span>
Expand All @@ -69,8 +69,8 @@
@if(\Auth::user()->can('create order'))
<li><a href=""><i class="fa fa-plus"></i> Create Orders</a></li>
@endif
@if(\Auth::user()->can('list orders'))
<li><a href=""><i class="fa fa-list"></i> Manage Orders</a></li>
@if(\Auth::user()->can('list order'))
<li><a href="{{Route('admin.order')}}"><i class="fa fa-list"></i> Manage Orders</a></li>
@endif
</ul>
</li>
Expand Down
5 changes: 4 additions & 1 deletion resources/views/admin/parts/navsettings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

<li class="@if(\Request::is('admin/settings/pterodactyl*')) active @endif"><a href="{{Route('admin.settings.pterodactyl')}}"><i class="fa fa-gamepad "></i> <span>Pterodactyl</span></a></li>

<li class="@if(\Request::is('admin/settings/payments*')) active @endif"><a href="{{Route('admin.settings.payments')}}"><i class="fa fa-paypal "></i> <span>Payments</span></a></li>
<li class="@if(\Request::is('admin/settings/payments*')) active @endif"><a href="{{Route('admin.settings.payments')}}"><i class="fa fa-paypal "></i> <span>Payments</span></a></li>

<li class="@if(\Request::is('admin/settings/discord*')) active @endif"><a href="{{Route('admin.settings.discord')}}"><i class="fa fa-question" aria-hidden="true"></i>
</i> <span>Discord</span></a></li>
12 changes: 12 additions & 0 deletions resources/views/buycraft/paymentDone.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,17 @@
@endsection

@section('content')
<div class="col-sm-12 col-md-12">
<div class="container-fluid">
<div class="row">
<div class="card dark-container">
<h4 class="card-header" data-toggle="modal" data-target="#main-container-modal">Payment Complete</h4>
<div class="card-body">
<p>Thank you for donating, your order should be processed soon</p>
</div>
</div>
</div>
</div>
</div>

@endsection
4 changes: 4 additions & 0 deletions routes/admin/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
Route::get('settings/pterodactyl','Admin\SettingsController@showPterodactyl')->middleware('permission:edit settings')->name("admin.settings.pterodactyl");
Route::post('settings/pterodactyl','Admin\SettingsController@savePterodactyl')->middleware('permission:edit settings')->name("admin.settings.pterodactyl");

Route::get('settings/discord','Admin\SettingsController@showDiscord')->middleware('permission:edit settings')->name("admin.settings.discord");
Route::post('settings/discord','Admin\SettingsController@saveDiscord')->middleware('permission:edit settings')->name("admin.settings.discord");
Route::post('settings/discord','Admin\SettingsController@testDiscord')->middleware('permission:edit settings')->name("admin.settings.discord.test");

Route::post('settings/pterodactyl/setup','Admin\SettingsController@magicPterodactyl')->middleware('permission:edit settings')->name("admin.settings.pterodactyl.setup");

Route::post('settings/update','Admin\SettingsController@save')->middleware('permission:edit settings')->name("admin.settings.save");
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

Route::get('/', 'HomeController@index')->name("store.index");
Route::get('/category/{category}', 'HomeController@showCategory')->name("store.category");
Route::post('/payment-complete', 'HomeController@paymentDone')->name("store.paymentdone");
Route::get('/payment-complete', 'HomeController@paymentDone')->name("store.paymentdone");

Route::get('paypal/','PayPalTestController@index')->name('paypal');
Route::get('paypal/ipn','PayPalTestController@paypalIpn')->name('paypal.ipn');
Expand Down
2 changes: 1 addition & 1 deletion storage/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"theme":"buycraft","admin":{"url":"admin"},"home_title":"MinePoS","home_desc":"<p>Demo MinePoS Store :)<\/p>","pterodactyl_link":"https:\/\/pterodactyl.minepos.net\/api\/","pterodactyl_key":"80qqDg8mdN3x3sqOdybDxwq7QpLOld1TY4zwxKMX7sFx0hNe","pterodactyl_appkey":"f5sUq0FcHL4NxlhbEsRRlZXhdThNecF9MBTVIKXXpeXBlrg7","PayPalSecret":"EAt5VBV3ae789prQ2xtltU6F17sQVPaXljXTHPOlHB8WLvQuKsAGWlcwhWiNE70ggXe-xCn9IqCe0tWN","PayPalClientID":"AWQMJBcuVcbMwVTYilN_fpB9M6cNxFZ7U5T0J-ATrfDbUrRkeVDP45iEYoxnpn-Hw9F_ALewAwrxkq0e","paypal_email":"[email protected]"}
{"theme":"buycraft","admin":{"url":"admin"},"home_title":"MinePoS","home_desc":"<p>Demo MinePoS Store :)<\/p>","pterodactyl_link":"https:\/\/pterodactyl.minepos.net\/api\/","pterodactyl_key":"YPxmLf1k5a6v1LcLClvIkHeoaCvYKcm1donvgWDhq71gJlWb","pterodactyl_appkey":"r8JzVF4JKJj2GaM94snLNhMSq1YrRi89WIJVCnAyxq8jV6JK","PayPalSecret":"EAt5VBV3ae789prQ2xtltU6F17sQVPaXljXTHPOlHB8WLvQuKsAGWlcwhWiNE70ggXe-xCn9IqCe0tWN","PayPalClientID":"AWQMJBcuVcbMwVTYilN_fpB9M6cNxFZ7U5T0J-ATrfDbUrRkeVDP45iEYoxnpn-Hw9F_ALewAwrxkq0e","paypal_email":"[email protected]","DISCORD_LOGIN_WEBHOOK":"https:\/\/discordapp.com\/api\/webhooks\/414863378188599314\/ooz3EkkWBWUHRz2YtAll1IafYgeAFSF31uc1IO6FPuJhjeVH8JiNTvbrT-URgdD-18WJ","DISCORD_ORDER_WEBHOOK":"https:\/\/discordapp.com\/api\/webhooks\/423094221914767370\/FNvJAzz6u4ra8UUgx3II-p2drhH-ADOZp0fbRgDwkXR0zCluU_1wG47US9P3z0anxvVO","DISCORD_LOGIN_ENABLED":true,"DISCORD_ORDER_ENABLED":true}

0 comments on commit 26178f6

Please sign in to comment.