App Setting Page

This commit is contained in:
Kekskurse 2019-04-25 12:03:34 +02:00
parent 4f7da5d196
commit c221c68db3
5 changed files with 135 additions and 27 deletions

View file

@ -50,42 +50,69 @@ class AppController extends Controller
return view('app/details', ["msg"=>"", "app" => $app]); return view('app/details', ["msg"=>"", "app" => $app]);
} }
public function updateApp(Request $request, $id) {
$this->validate($request, [
'name' => 'required|max:255|min:3|regex:@^[a-zA-Z0-9]*$@',
'description' => 'required|min:3',
'url' => 'required|url',
'direct_url' => 'url'
]);
// ToDO Unique App Name
$app = App::query()->where("id", "=", $id)->first();
if($app->user_id != Auth::user()->id) {
abort(401);
}
$app->name = $request->input("name");
$app->description = $request->input("description");
$app->url = $request->input("url");
$app->direct_url = $request->input("direct_url");
$app->saveOrFail();
return redirect('/gui/apps/'.$id);
}
public function changeIcon(Request $request, $id) { public function changeIcon(Request $request, $id) {
// Todo: Replace prove of concept with better code // Todo: Replace prove of concept with better code
$newTmp = tempnam("", "icon_upload"); $newTmp = tempnam("", "icon_upload");
$request->file("icon")->move("/tmp", $newTmp); $request->file("icon")->move("/tmp", $newTmp);
$info = getimagesize($newTmp); $info = getimagesize($newTmp);
if($info["0"] != $info["1"]) { if($info["0"] != $info["1"]) {
echo "Icon is not a squader";exit(); echo "Icon is not a squader. <a href='/gui/apps/".$id."'>Zurück</a>";exit();
} }
if($info[0] > 500) { if($info[0] > 500) {
echo "Icon is to big, max 500 px";exit(); echo "Icon is to big, max 500 px. <a href='/gui/apps/".$id."'>Zurück</a>";exit();
} }
if($info[0] < 50) { if($info[0] < 50) {
echo "Icon is to small, min 50px";exit(); echo "Icon is to small, min 50px. <a href='/gui/apps/".$id."'>Zurück</a>";exit();
} }
$app = App::query()->where("id", "=", $id)->firstOrFail(); $app = App::query()->where("id", "=", $id)->firstOrFail();
if($app->user_id != Auth::user()->id) { if($app->user_id != Auth::user()->id) {
echo "Its not your app";exit(); echo "Its not your app. <a href='/gui/apps/".$id."'>Zurück</a>";exit();
} }
$app->icon = file_get_contents($newTmp); $app->icon = file_get_contents($newTmp);
$app->saveOrFail(); $app->saveOrFail();
echo "OK"; return redirect('/gui/apps/'.$id);
} }
public function getAppIcon($id) { public function getAppIcon($id) {
$app = App::query()->where("id", "=", $id)->firstOrFail(); $app = App::query()->where("id", "=", $id)->firstOrFail();
if(empty($app->icon)) {
$app->icon = file_get_contents(resource_path("images/app.png"));
}
$r = getimagesizefromstring($app->icon); $r = getimagesizefromstring($app->icon);
return response($app->icon) return response($app->icon)
->header('Content-Type',$r["mime"]); ->header('Content-Type',$r["mime"]);
} }
} }

View file

@ -1,23 +1,103 @@
<?php include(__DIR__."/../layout/top.php"); ?> <?php include(__DIR__."/../layout/top.php"); ?>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#overview" role="tab" aria-controls="overview" aria-selected="true">Overview</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#api" role="tab" aria-controls="api" aria-selected="false">API Access</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#settings" role="tab" aria-controls="settings" aria-selected="false">Settings</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Users</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
<div class="row">
<div class="col-md-9">
<h3>App <?php echo $app->name; ?></h3> <h3>App <?php echo $app->name; ?></h3>
<p><?php echo $app->description; ?></p> <p><?php echo $app->description; ?></p>
<a href="<?php echo $app->url; ?>"><?php echo $app->url; ?></a> <a href="<?php echo $app->url; ?>"><?php echo $app->url; ?></a>
<hr> </div>
<h3>Settings</h3> <div class="col-md-3">
<b>Icon</b> <img src="/gui/apps/<?php echo $app->id; ?>/icon" style="max-width: 100%;">
You can change the Icon of the App by uploading a square Pic. </div>
<form action="/gui/apps/<?php echo $app->id; ?>/changeIcon" method="post" enctype="multipart/form-data"> </div>
<input type="file" name="icon" class="form-control" ><br>
<input type="submit" class="btn btn-success" value="Upload"> </div>
</form> <div class="tab-pane fade" id="api" role="tabpanel" aria-labelledby="api-tab">
<hr>
<h3>API Access</h3> <h3>API Access</h3>
<b>API-Key</b> <b>API-Key</b>
<input class="form-control" value="<?php echo $app->apiKey; ?>"> <input class="form-control" value="<?php echo $app->apiKey; ?>">
<b>API-Secret</b> <b>API-Secret</b>
<input class="form-control" value="<?php echo $app->apiSecret; ?>"> <input class="form-control" value="<?php echo $app->apiSecret; ?>">
</div> </div>
<div class="tab-pane fade" id="settings" role="tabpanel" aria-labelledby="settings-tab">
<h3>Settings</h3>
<div class="row">
<div class="col-md-8">
<form method="post">
<table class="table">
<tr>
<td>Name</td>
<td><input name="name" class="form-control" value="<?php echo $app->name; ?>"> </td>
</tr>
<tr>
<td>URL</td>
<td><input name="url" class="form-control" value="<?php echo $app->url; ?>"> </td>
</tr>
<tr>
<td>Description</td>
<td><textarea class="form-control" name="description" placeholder="App Beschreibung"><?php echo $app->description; ?></textarea></td>
</tr>
<tr>
<td>Direct Login URL</td>
<td><input name="direct_url" class="form-control" value="<?php echo $app->direct_url; ?>"> </td>
</tr>
<tr>
<td>Testing <i class="fas fa-question-circle" data-placement="top" data-toggle="popover" title="Access" data-content="To change this setting contact the Site Administrator"></i></td>
<td><input type="checkbox" disabled <?php if($app->testing_warning) { echo 'checked'; } ?>> </td>
</tr>
<tr>
<td>Untrusted <i class="fas fa-question-circle" data-placement="top" data-toggle="popover" title="Access" data-content="To change this setting contact the Site Administrator"></i></td>
<td><input type="checkbox" disabled <?php if($app->untrusted_warning) { echo 'checked'; } ?>> </td>
</tr>
<tr>
<td>Auto Accept <i class="fas fa-question-circle" data-placement="top" data-toggle="popover" title="Access" data-content="To change this setting contact the Site Administrator"></i></td>
<td><input type="checkbox" disabled <?php if($app->auto_accept) { echo 'checked'; } ?>> </td>
</tr>
<tr>
<td>Show on Webpage <i class="fas fa-question-circle" data-placement="top" data-toggle="popover" title="Access" data-content="To change this setting contact the Site Administrator"></i></td>
<td><input type="checkbox" disabled <?php if($app->show_on_webpage) { echo 'checked'; } ?>> </td>
</tr>
</table>
<input type="submit" class="btn btn-success" value="Save">
</form>
</div> </div>
<div class="col-md-4">
<b>Icon</b><br>
You can change the Icon of the App by uploading a square Pic.
<form action="/gui/apps/<?php echo $app->id; ?>/changeIcon" method="post" enctype="multipart/form-data">
<input type="file" name="icon" class="form-control" ><br>
<input type="submit" class="btn btn-success" value="Upload">
</form>
</div>
</div>
</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
</div>
</div>
</div>
<script>
$(function () {
$('[data-toggle="popover"]').popover()
})
</script>
<?php include(__DIR__."/../layout/bottom.php"); ?> <?php include(__DIR__."/../layout/bottom.php"); ?>

View file

@ -10,7 +10,7 @@
?> ?>
<div class="list-group" id="list-tab" role="tablist"> <div class="list-group" id="list-tab" role="tablist">
<?php foreach($apps as $app) { ?> <?php foreach($apps as $app) { ?>
<a class="list-group-item list-group-item-action" id="list-profile-list" href="/gui/apps/<?php echo $app->id; ?>"><?php echo $app->name; ?></a> <a class="list-group-item list-group-item-action" style="padding-top:5px;padding-bottom:5px;" id="list-profile-list" href="/gui/apps/<?php echo $app->id; ?>"><img src="/gui/apps/<?php echo $app->id; ?>/icon" style="max-width: 30px;"> <?php echo $app->name; ?></a>
<?php } ?> <?php } ?>
</div> </div>
<?php <?php

View file

@ -2,7 +2,7 @@
<footer class="page-footer font-small blue"> <footer class="page-footer font-small blue">
<!-- Copyright --> <!-- Copyright -->
<div class="footer-copyright text-center py-3">Make with <i class="fas fa-cookie"></i> for <a href="https://www.keks.cloud">keks.cloud</a> <div class="footer-copyright text-center py-3"><i class="fas fa-code"></i> with <i class="fas fa-cookie"></i> for <a href="https://www.keks.cloud">keks.cloud</a>
- <i class="fas fa-code-branch"></i> <a href="https://gitea.keks.cloud/keks.cloud/keksAccount">Keks Account</a> - <i class="fas fa-code-branch"></i> <a href="https://gitea.keks.cloud/keks.cloud/keksAccount">Keks Account</a>
</div> </div>
<!-- Copyright --> <!-- Copyright -->

View file

@ -29,6 +29,7 @@ $router->group(['prefix' => 'gui', 'middleware' => 'gui'], function () use ($rou
$router->get('/apps/new', ['uses' => 'GUI\AppController@newAppView']); $router->get('/apps/new', ['uses' => 'GUI\AppController@newAppView']);
$router->post('/apps/new', ['uses' => 'GUI\AppController@newApp']); $router->post('/apps/new', ['uses' => 'GUI\AppController@newApp']);
$router->get('/apps/{id}', ['uses' => 'GUI\AppController@viewApp']); $router->get('/apps/{id}', ['uses' => 'GUI\AppController@viewApp']);
$router->post('/apps/{id}', ['uses' => 'GUI\AppController@updateApp']);
$router->post('/apps/{id}/changeIcon', ['uses' => 'GUI\AppController@changeIcon']); $router->post('/apps/{id}/changeIcon', ['uses' => 'GUI\AppController@changeIcon']);
$router->get('/apps/{id}/icon', ['uses' => 'GUI\AppController@getAppIcon']); $router->get('/apps/{id}/icon', ['uses' => 'GUI\AppController@getAppIcon']);
$router->get("/mailValidation/{id}/{code}", ['uses' => 'GUI\AccountController@validateEMail']); $router->get("/mailValidation/{id}/{code}", ['uses' => 'GUI\AccountController@validateEMail']);