|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
|
use App\Classes\Pterodactyl;
|
|
use App\Classes\Pterodactyl;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Models\User;
|
|
|
|
+use App\Notifications\DynamicNotification;
|
|
use Exception;
|
|
use Exception;
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
use Illuminate\Contracts\View\Factory;
|
|
use Illuminate\Contracts\View\Factory;
|
|
@@ -12,8 +13,10 @@ use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Http\Response;
|
|
|
|
+use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
+use Illuminate\Support\HtmlString;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
|
|
@@ -104,7 +107,6 @@ class UserController extends Controller
|
|
$user->update($request->all());
|
|
$user->update($request->all());
|
|
|
|
|
|
return redirect()->route('admin.users.index')->with('success', 'User updated!');
|
|
return redirect()->route('admin.users.index')->with('success', 'User updated!');
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -142,6 +144,55 @@ class UserController extends Controller
|
|
return redirect()->route('admin.users.index');
|
|
return redirect()->route('admin.users.index');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Show the form for seding notifications to the specified resource.
|
|
|
|
+ *
|
|
|
|
+ * @param User $user
|
|
|
|
+ * @return Application|Factory|View|Response
|
|
|
|
+ */
|
|
|
|
+ public function notifications(User $user)
|
|
|
|
+ {
|
|
|
|
+ return view('admin.users.notifications')->with([
|
|
|
|
+ 'user' => $user
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Notify the specified resource.
|
|
|
|
+ *
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @param User $user
|
|
|
|
+ * @return RedirectResponse
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public function notify(Request $request, User $user)
|
|
|
|
+ {
|
|
|
|
+ $via = $request->validate([
|
|
|
|
+ "via" => "required|min:1|array",
|
|
|
|
+ "via.*" => "required|string|in:mail,database",
|
|
|
|
+ ])["via"];
|
|
|
|
+
|
|
|
|
+ $mail = null;
|
|
|
|
+ $database = null;
|
|
|
|
+ if (in_array('database', $via)) {
|
|
|
|
+ $database = $request->validate([
|
|
|
|
+ "title" => "required|string|min:1",
|
|
|
|
+ "content" => "required|string|min:1"
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ if (in_array('mail', $via)) {
|
|
|
|
+ $data = $request->validate([
|
|
|
|
+ "subject" => "required|string|min:1",
|
|
|
|
+ "body" => "required|string|min:1"
|
|
|
|
+ ]);
|
|
|
|
+ $mail = (new MailMessage)->subject($data["subject"])->line(new HtmlString($data["body"]));
|
|
|
|
+ }
|
|
|
|
+ $user->notify(
|
|
|
|
+ new DynamicNotification($via, $database, $mail)
|
|
|
|
+ );
|
|
|
|
+ return redirect()->route('admin.users.notifications', $user->id)->with('success', 'User notified!');
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* @throws Exception
|
|
* @throws Exception
|
|
@@ -177,6 +228,7 @@ class UserController extends Controller
|
|
<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="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="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="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>
|
|
<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>
|
|
|
|
+ <a data-content="Notifications" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.notifications', $user->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-paper-plane"></i></a>
|
|
<form class="d-inline" onsubmit="return submitResult();" method="post" action="' . route('admin.users.destroy', $user->id) . '">
|
|
<form class="d-inline" onsubmit="return submitResult();" method="post" action="' . route('admin.users.destroy', $user->id) . '">
|
|
' . csrf_field() . '
|
|
' . csrf_field() . '
|
|
' . method_field("DELETE") . '
|
|
' . method_field("DELETE") . '
|
|
@@ -186,16 +238,16 @@ class UserController extends Controller
|
|
})
|
|
})
|
|
->editColumn('role', function (User $user) {
|
|
->editColumn('role', function (User $user) {
|
|
switch ($user->role) {
|
|
switch ($user->role) {
|
|
- case 'admin' :
|
|
|
|
|
|
+ case 'admin':
|
|
$badgeColor = 'badge-danger';
|
|
$badgeColor = 'badge-danger';
|
|
break;
|
|
break;
|
|
- case 'mod' :
|
|
|
|
|
|
+ case 'mod':
|
|
$badgeColor = 'badge-info';
|
|
$badgeColor = 'badge-info';
|
|
break;
|
|
break;
|
|
- case 'client' :
|
|
|
|
|
|
+ case 'client':
|
|
$badgeColor = 'badge-success';
|
|
$badgeColor = 'badge-success';
|
|
break;
|
|
break;
|
|
- default :
|
|
|
|
|
|
+ default:
|
|
$badgeColor = 'badge-secondary';
|
|
$badgeColor = 'badge-secondary';
|
|
break;
|
|
break;
|
|
}
|
|
}
|