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

167 lines
5.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 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->hidden_in_app_list = (bool)$request->input("hidden_in_app_list", false);
2019-04-30 12:59:28 +00:00
$app->user_cant_remove_app = (bool)$request->input("user_cant_remove_app", false);
2019-04-24 18:46:41 +00:00
$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");
}
2019-04-25 12:19:16 +00:00
public function listUser() {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$users = User::query()->get();
return view('admin/user_list', ["msg"=>"", "users" => $users]);
}
public function userDetails($id) {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$user = User::query()->where("id", "=", $id)->firstOrFail();
$mails = Mail::query()->where("user_id", "=", $id)->get();
return view('admin/user_details', ["msg"=>"", "editUser" => $user, "mails" => $mails]);
}
public function saveUserDetails(Request $request, $id) {
if(!Auth::user()->admin) {
throw new HTTPException("Need Admin Access");
}
$user = User::query()->where("id", "=", $id)->firstOrFail();
$user->admin = (bool)$request->input("admin", false);
$user->developer = (bool)$request->input("developer", false);
$user->username = $request->input("username");
$user->saveOrFail();
return redirect("/gui/admin/users/".$id);
}
2019-04-24 18:46:41 +00:00
//
}