Change Settings and name also change api routing and add server settings api endpoint
This commit is contained in:
parent
c8601651d8
commit
e022cd6d5c
8 changed files with 151 additions and 11 deletions
22
app/Http/Controllers/API/ServerController.php
Normal file
22
app/Http/Controllers/API/ServerController.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Exceptions\HTTPException;
|
||||
use App\Exceptions\NoPermissionException;
|
||||
use App\Exceptions\NotLoggedInException;
|
||||
use App\Exceptions\ResourceNotFound;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
use TaGeSo\APIResponse\Response;
|
||||
|
||||
class ServerController extends BaseController
|
||||
{
|
||||
public function getSettings(Response $response) {
|
||||
$settings = Setting::getPublicSettings();
|
||||
|
||||
return $response->withData(\App\Http\Resources\API\Setting::collection(collect($settings)));
|
||||
}
|
||||
}
|
36
app/Http/Resources/API/Setting.php
Normal file
36
app/Http/Resources/API/Setting.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources\API;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Setting extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$data = [
|
||||
'name' => $this->name,
|
||||
//'created_at' => $this->created_at,
|
||||
//'updated_at' => $this->created_at,
|
||||
'description' => $this->description,
|
||||
'typ' => $this->typ,
|
||||
'value' => $this->value,
|
||||
];
|
||||
|
||||
if($this->typ == "checkbox") {
|
||||
$data["value"] = (bool)$this->value;
|
||||
}
|
||||
|
||||
if($this->typ == "password") {
|
||||
$data["value"] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
|
@ -28,6 +28,22 @@ class Setting extends Model
|
|||
'',
|
||||
];
|
||||
|
||||
/*
|
||||
* Public setting keys
|
||||
*/
|
||||
static public $publicKeys = [
|
||||
'registration_possible',
|
||||
'invites',
|
||||
'url',
|
||||
'name',
|
||||
'recaptcha_v2_register',
|
||||
'recaptcha_v2_login',
|
||||
'recaptcha_v2_key',
|
||||
'name_big',
|
||||
'name_small',
|
||||
'name_slogen'
|
||||
];
|
||||
|
||||
|
||||
static public function getSettingsAsArray() {
|
||||
$settings = Setting::query()->get();
|
||||
|
@ -39,6 +55,11 @@ class Setting extends Model
|
|||
}
|
||||
|
||||
static public function getSettingValue($name) {
|
||||
//Hack for old gui
|
||||
return Setting::query()->where("name", "=", $name)->firstOrFail()->value;
|
||||
}
|
||||
|
||||
static public function getPublicSettings() {
|
||||
return Setting::query()->whereIn("name", self::$publicKeys)->get();
|
||||
}
|
||||
}
|
||||
|
|
53
database/migrations/2019_05_22_121930_new_gui_settings.php
Normal file
53
database/migrations/2019_05_22_121930_new_gui_settings.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class NewGuiSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$setting = new \App\Models\Setting();
|
||||
$setting->name = "name_big";
|
||||
$setting->description = "First Part of the Name, written big on the Webpage";
|
||||
$setting->typ = "textinput";
|
||||
$setting->value = \App\Models\Setting::getSettingValue("name");
|
||||
$setting->saveOrFail();
|
||||
$setting = new \App\Models\Setting();
|
||||
$setting->name = "name_small";
|
||||
$setting->description = "Secound Part of the Name, written smal on the Webpage";
|
||||
$setting->typ = "textinput";
|
||||
$setting->value = "";
|
||||
$setting->saveOrFail();
|
||||
\App\Models\Setting::query()->where("name", "=", "name")->delete();
|
||||
$setting = new \App\Models\Setting();
|
||||
$setting->name = "name_slogen";
|
||||
$setting->description = "Slogen show on the Webpage";
|
||||
$setting->typ = "textinput";
|
||||
$setting->value = "Zentraler authentication Service";
|
||||
$setting->saveOrFail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$setting = new \App\Models\Setting();
|
||||
$setting->name = "name";
|
||||
$setting->description = "Name of this Service";
|
||||
$setting->value = \App\Models\Setting::getSettingValue("name_big").\App\Models\Setting::getSettingValue("name_small");
|
||||
$setting->saveOrFail();
|
||||
\App\Models\Setting::query()->where("name", "=", "name_big")->delete();
|
||||
\App\Models\Setting::query()->where("name", "=", "name_small")->delete();
|
||||
\App\Models\Setting::query()->where("name", "=", "name_slogen")->delete();
|
||||
}
|
||||
}
|
|
@ -26,4 +26,6 @@ $app = require __DIR__.'/../bootstrap/app.php';
|
|||
|
|
||||
*/
|
||||
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
|
||||
$app->run();
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="alert alert-light" role="alert">
|
||||
<?php echo $settingsArray["name"]; ?> is still in development.
|
||||
<?php echo $settingsArray["name_big"].$settingsArray["name_small"]; ?> is still in development.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h3><?php echo $settingsArray["name"]; ?></h3>
|
||||
<h3><?php echo $settingsArray["name_big"].$settingsArray["name_small"]; ?></h3>
|
||||
<p>
|
||||
<?php echo $settingsArray["name"]; ?> is a oAuht Provider to login with a single user to different Services. You just need one Account to use all Services, also other developers can add this Service to there services.
|
||||
<?php echo $settingsArray["name_big"].$settingsArray["name_small"]; ?> is a oAuht Provider to login with a single user to different Services. You just need one Account to use all Services, also other developers can add this Service to there services.
|
||||
</p>
|
||||
<p>
|
||||
In the test phase of the Project you need an Invite-Code to create a new Account.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title><?php echo $settingsArray["name"]; ?></title>
|
||||
<title><?php echo $settingsArray["name_big"].$settingsArray["name_small"]; ?></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://bootswatch.com/4/flatly/bootstrap.min.css" type="text/css" rel="stylesheet">
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<body>
|
||||
<div class="container" style="margin-top: 30px;min-height: calc(100vh - 100px);">
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary" style="margin-bottom: 20px">
|
||||
<a class="navbar-brand" href="/"><?php echo $settingsArray["name"]; ?></a>
|
||||
<a class="navbar-brand" href="/"><?php echo $settingsArray["name_big"].$settingsArray["name_small"]; ?></a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
|
|
@ -37,21 +37,27 @@ $router->group(['prefix' => 'oauth'], function () use ($router) {
|
|||
|
||||
|
||||
//Internal API
|
||||
$router->group(['prefix' => 'api', 'middleware' => 'auth'], function () use ($router) {
|
||||
$router->group(['prefix' => 'api'], function () use ($router) {
|
||||
$router->group(['prefix' => 'v1'], function () use ($router) {
|
||||
$router->group(['prefix' => 'user'], function () use ($router) {
|
||||
$router->post("/login", ['uses' => 'API\UserController@passwordLogin']);
|
||||
$router->post("/register", ['uses' => 'API\UserController@register']);
|
||||
$router->get("/captcha", ['uses' => 'API\UserController@reCAPTCHA']);
|
||||
$router->get("/invites", ['uses' => 'API\UserController@getInviteCodeInfo']);
|
||||
});
|
||||
$router->group(['prefix' => 'account'], function () use ($router) {
|
||||
$router->get("/", ['uses' => 'API\AccountController@getUsers']);
|
||||
$router->get("/{id}", ['uses' => 'API\AccountController@getUser']);
|
||||
});
|
||||
$router->group(['prefix' => 'user'], function () use ($router) {
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
$router->post("api/v1/user/login", ['uses' => 'API\UserController@passwordLogin']);
|
||||
|
||||
//Public Routes
|
||||
/*$router->post("api/v1/user/login", ['uses' => 'API\UserController@passwordLogin']);
|
||||
$router->post("api/v1/user/register", ['uses' => 'API\UserController@register']);
|
||||
$router->get("api/v1/user/captcha", ['uses' => 'API\UserController@reCAPTCHA']);
|
||||
$router->get("api/v1/user/invites", ['uses' => 'API\UserController@getInviteCodeInfo']);
|
||||
$router->get("api/v1/user/invites", ['uses' => 'API\UserController@getInviteCodeInfo']);*/
|
||||
$router->get("api/v1/server/settings", ["uses" => "API\ServerController@getSettings"]);
|
||||
|
||||
$router->group(['prefix' => 'gui', 'middleware' => 'gui'], function () use ($router) {
|
||||
$router->get('/register', ['uses' => 'GUI\AccountController@registerView']);
|
||||
|
|
Reference in a new issue