This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccount/app/Http/Controllers/GUI/AdminController.php

138 lines
4.1 KiB
PHP
Raw Normal View History

2019-04-24 18:46:41 +00:00
<?php
namespace App\Http\Controllers\GUI;
use App\Exceptions\HTTPException;
use App\Http\Controllers\Controller;
use App\Http\Resources\oAuth\AccessToken;
use App\Models\App;
use App\Models\Invite;
use App\Models\Mail;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class AdminController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
public function listMails() {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$mails = Mail::query()->get("*");
return view('admin/mails_list', ["mails"=>$mails]);
}
public function inviteView() {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$invites = Invite::query()->get();
return view('admin/invites_list', ["invites"=>$invites]);
}
public function inviteNewView() {
return view('admin/invites_new', []);
}
public function settingsView() {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$settings = Setting::query()->get("*");
return view('admin/settings_list', ["settings"=>$settings]);
}
public function saveSettings(Request $request) {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$settings = Setting::query()->get("*");
foreach($settings as $setting) {
switch ($setting->typ) {
case "checkbox":
if($request->input($setting->name, false)) {
$setting->value = true;
} else {
$setting->value = false;
}
$setting->saveOrFail();
case "textinput":
$setting->value = $request->input($setting->name, "");
$setting->saveOrFail();
case "password":
$setting->value = $request->input($setting->name, "");
$setting->saveOrFail();
}
}
$settings = Setting::query()->get("*");
return view('admin/settings_list', ["settings"=>$settings]);
}
public function appList() {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$apps = App::query()->get("*");
return view('admin/app_list', ["msg"=>"", "apps" => $apps]);
}
public function appDetails($id) {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$app = App::query()->where("id", "=", $id)->first("*");
return view('admin/app_details', ["msg"=>"", "app" => $app]);
}
public function appDetailsSave(Request $request, $id) {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$app = App::query()->where("id", "=", $id)->first("*");
$app->auto_accept = (bool)$request->input("auto_accept", false);
$app->testing_warning = (bool)$request->input("testing_warning", false);
$app->untrusted_warning = (bool)$request->input("untrusted_warning", false);
$app->show_on_webpage = (bool)$request->input("show_on_webpage", false);
$app->saveOrFail();
$app = App::query()->where("id", "=", $id)->first("*");
return view('admin/app_details', ["msg"=>"", "app" => $app]);
}
public function inviteNew(Request $request) {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$invite = new Invite();
$invite->user_id = Auth::user()->id;
$invite->username = $request->input("username", null);
$invite->comment = $request->input("comment", null);
$invite->status = "active";
$invite->createToken();
$invite->saveOrFail();
return redirect("/gui/admin/invites");
}
//
}