Skip to content

Commit

Permalink
Updated pages & added option to disable auth server
Browse files Browse the repository at this point in the history
  • Loading branch information
faab007nl committed Dec 23, 2023
1 parent 7fab0e5 commit b0f56f3
Show file tree
Hide file tree
Showing 33 changed files with 1,104 additions and 311 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ TECHSCODE_AUTH_TOKEN=

TECHSCODE_GITHUB_API_TOKEN=
TECHSCODE_PLUGIN_API_TOKEN=

UPDATE_SERVER_ENABLED=false
32 changes: 25 additions & 7 deletions app/Http/Controllers/AuthenticateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public function authenticateCallback(){
$update_token = session()->get('update_token');
if (empty($update_token)){
return view('pages.error')
->with('error_message', 'Unknown Update Token');
->with([
'error_message' => 'Unknown update token',
'show_join_button' => true
]);
}
session()->forget('update_token');

Expand All @@ -43,14 +46,20 @@ public function authenticateCallback(){
$ot_token = request()->get('token');
if (empty($ot_token)){
return view('pages.error')
->with('error_message', 'Authentication Failed');
->with([
'error_message' => 'Authentication failed',
'show_join_button' => true
]);
}

$user_info = TechsCodeAuth::getUser($auth_token, $ot_token);

if (empty($user_info)){
return view('pages.error')
->with('error_message', 'Authentication Failed');
->with([
'error_message' => 'Authentication failed',
'show_join_button' => true
]);
}

/** @var UpdateRequest $update_request */
Expand All @@ -59,7 +68,10 @@ public function authenticateCallback(){
->first();
if (empty($update_request)){
return view('pages.error')
->with('error_message', 'Update Request Not Found');
->with([
'error_message' => 'Update request not found',
'show_join_button' => true
]);
}
$user_roles = $user_info['roles'];
$support_server_roles = $user_roles['support_server'];
Expand All @@ -82,7 +94,7 @@ public function authenticateCallback(){
$update_request->save();
return view('pages.error')
->with([
'error_message' => 'You do not have access to any plugins.<br>Please verify your roles on the support server.',
'error_message' => "You do not have access to $update_request->plugin_name.<br>Please verify your roles on the support server.",
'show_join_button' => true
]);
}
Expand All @@ -101,11 +113,17 @@ public function authenticateCallback(){
}catch (Exception $e){
\Log::debug($e->getMessage());
return view('pages.error')
->with('error_message', 'Unknown Error');
->with([
'error_message' => 'Unknown Error',
'show_join_button' => true
]);
} catch (GuzzleException|NotFoundExceptionInterface|ContainerExceptionInterface $e) {
\Log::debug($e->getMessage());
return view('pages.error')
->with('error_message', 'Unknown Error');
->with([
'error_message' => 'Unknown Error',
'show_join_button' => true
]);
}
}

Expand Down
31 changes: 7 additions & 24 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ public function authorizePage(Request $request, string $update_token)
if (empty($update_token)) {
return view('pages.authorize')
->with([
'update_token' => null,
'plugin_name' => null,
'current_version' => null,
'update_to' => null,
'show_auth_button' => false,
'error_message' => 'Invalid update token.',
'error_title' => 'Invalid Request',
'error_message' => 'Missing update token.',
]);
}

Expand All @@ -35,11 +31,7 @@ public function authorizePage(Request $request, string $update_token)
if (empty($update_request)) {
return view('pages.authorize')
->with([
'update_token' => null,
'plugin_name' => null,
'current_version' => null,
'update_to' => null,
'show_auth_button' => false,
'error_title' => 'Invalid Request',
'error_message' => 'Invalid update token.',
]);
}
Expand All @@ -48,12 +40,8 @@ public function authorizePage(Request $request, string $update_token)
if (!$techscode_plugin->isValidPlugin()) {
return view('pages.authorize')
->with([
'update_token' => null,
'plugin_name' => null,
'current_version' => null,
'update_to' => null,
'show_auth_button' => false,
'error_message' => 'Invalid plugin name.',
'error_title' => 'Update Failed',
'error_message' => 'This plugin is not registered with TechsCode.',
]);
}

Expand All @@ -63,11 +51,7 @@ public function authorizePage(Request $request, string $update_token)
){
return view('pages.authorize')
->with([
'update_token' => null,
'plugin_name' => null,
'current_version' => null,
'update_to' => null,
'show_auth_button' => false,
'error_title' => 'Update Failed',
'error_message' => 'This update request has already been authorized.',
]);
}
Expand All @@ -77,9 +61,8 @@ public function authorizePage(Request $request, string $update_token)
'update_token' => $update_token,
'plugin_name' => $techscode_plugin->getName(),
'current_version' => $update_request->current_version,
'current_version_date' => $update_request->current_version_date,
'update_to' => $update_request->update_to,
'show_auth_button' => true,
'error_message' => '',
]);
}
}
3 changes: 3 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http;

use App\Http\Middleware\IsUpdateServerEnabled;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
Expand Down Expand Up @@ -42,6 +43,7 @@ class Kernel extends HttpKernel
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
IsUpdateServerEnabled::class,
],
];

Expand All @@ -64,5 +66,6 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'update-server-enabled' => \App\Http\Middleware\IsUpdateServerEnabled::class,
];
}
26 changes: 26 additions & 0 deletions app/Http/Middleware/IsUpdateServerEnabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class IsUpdateServerEnabled
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (!config('services.update_server_enabled')) {
return response()->json([
'error' => 'The update server is currently disabled.',
], 503);
}

return $next($request);
}
}
26 changes: 14 additions & 12 deletions app/Models/TechsCodePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
class TechsCodePlugin
{
public static array $valid_plugins = [
"ultrapermissions" => "UltraPermissions",
"ultraeconomy" => "UltraEconomy",
"ultramotd" => "UltraMotd",
"ultrapunishments" => "UltraPunishments",
"ultraregions" => "UltraRegions",
"ultracustomizer" => "UltraCustomizer",
"ultrascoreboards" => "UltraScoreboards",
"insanevaults" => "InsaneVaults",
"insaneshops" => "InsaneShops",
"insaneannouncer" => "InsaneAnnouncer",
"techseditor" => "TechsEditor",
"ultraeconomytest" => "UltraEconomyTest",
"ultrapermissions" => "Ultra Permissions",
"ultrascoreboards" => "Ultra Scoreboards",
"ultrapunishments" => "Ultra Punishments",
"ultracustomizer" => "Ultra Customizer",
"ultraeconomy" => "Ultra Economy",
"ultraregions" => "Ultra Regions",
"ultramotd" => "Ultra Motd",
"insaneshops" => "Insane Shops",
"insanespawners" => "Insane Spawners",
"insanevaults" => "Insane Vaults",
"insaneannouncer" => "Insane Announcer",
"insanechatcolors" => "Insane Chat Colors",
"techseditor" => "Techs Editor",
"ultraeconomytest" => "Ultra Economy Test",
];

private string $value;
Expand Down
16 changes: 16 additions & 0 deletions app/Models/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;

/**
* Class UpdateRequest
Expand All @@ -14,6 +15,7 @@
* @property UpdateRequestStatus $status
* @property string $plugin_name
* @property string $current_version
* @property Carbon $current_version_date
* @property string $update_to
* @property array $allowed_plugins
* @property bool $has_beta_access
Expand All @@ -39,6 +41,10 @@ class UpdateRequest extends Model
'updated_at' => 'datetime',
];

protected $appends = [
'current_version_date'
];

public function getStatusAttribute($value): UpdateRequestStatus
{
return UpdateRequestStatus::from($value);
Expand All @@ -52,4 +58,14 @@ public function getAllowedPluginsAttribute($value): array
return [];
}

public function getCurrentVersionDateAttribute($value){
$plugin_release = ReleaseVersion::where('plugin_name', $this->plugin_name)
->where('plugin_version', $this->current_version)
->first();
if($plugin_release){
return $plugin_release->created_at;
}
return null;
}

}
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
"license": "MIT",
"require": {
"php": "^8.1",
"ext-curl": "*",
"blade-ui-kit/blade-icons": "^1.5",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"ext-curl": "*"
"laravel/tinker": "^2.8"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.8",
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
"laravel/sail": "^1.26",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.1",
Expand Down
Loading

0 comments on commit b0f56f3

Please sign in to comment.