mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-04-26 02:00:32 -05:00
Added Ban Status endpoint and created a ban table to ban users.
This commit is contained in:
parent
b39781e399
commit
154105a374
|
|
@ -6,7 +6,7 @@
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\Auth\SteamLoginRequest;
|
||||
use App\Http\Responses\Api\Auth\SteamLoginResponse;
|
||||
use App\Models\User;
|
||||
use App\Models\User\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
|
|
|||
21
dist/app/Http/Controllers/Api/Player/PlayerController.php
vendored
Normal file
21
dist/app/Http/Controllers/Api/Player/PlayerController.php
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Player;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Responses\Api\Player\GetBanStatusResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class PlayerController extends Controller
|
||||
{
|
||||
public function getBanStatus()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
if($user->ban === null)
|
||||
return json_encode(new GetBanStatusResponse(false));
|
||||
|
||||
return json_encode(new GetBanStatusResponse(true, $user->ban));
|
||||
}
|
||||
}
|
||||
47
dist/app/Http/Responses/Api/Player/GetBanStatusResponse.php
vendored
Normal file
47
dist/app/Http/Responses/Api/Player/GetBanStatusResponse.php
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Responses\Api\Player;
|
||||
|
||||
use App\Models\User\Ban;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class GetBanStatusResponse
|
||||
{
|
||||
public bool $IsBanned = false;
|
||||
|
||||
public BanInfo $BanInfo;
|
||||
|
||||
public function __construct(bool $isBanned = false, ?Ban &$ban= null)
|
||||
{
|
||||
$this->IsBanned = $isBanned;
|
||||
|
||||
if($ban !== null) {
|
||||
$this->BanInfo = new BanInfo($ban->ban_reason, $ban->start_date, $ban->end_date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BanInfo {
|
||||
public int $BanPeriod = 0;
|
||||
|
||||
public string $BanReason;
|
||||
|
||||
public int $BanStart = 0;
|
||||
|
||||
public int $BanEnd = 0;
|
||||
|
||||
public bool $Confirmed = true;
|
||||
|
||||
public bool $Pending = false;
|
||||
|
||||
public function __construct(string $banReason = 'Not Banned',?Carbon $startDate = null, ?Carbon $endDate = null)
|
||||
{
|
||||
$this->BanReason = $banReason;
|
||||
|
||||
if(isset($startDate) && isset($endDate))
|
||||
$this->BanStart = $startDate->getTimestamp();
|
||||
$this->BanEnd = $endDate->getTimestamp();
|
||||
$this->BanPeriod = $startDate->diffInDays($endDate);
|
||||
}
|
||||
}
|
||||
26
dist/app/Models/User/Ban.php
vendored
Normal file
26
dist/app/Models/User/Ban.php
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperBan
|
||||
*/
|
||||
class Ban extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\IdeHelperUser;
|
||||
use Illuminate\Auth\Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperUser
|
||||
|
|
@ -16,4 +18,9 @@ class User extends Model implements \Illuminate\Contracts\Auth\Authenticatable
|
|||
protected $fillable = [
|
||||
'steam_id',
|
||||
];
|
||||
|
||||
public function ban(): HasOne
|
||||
{
|
||||
return $this->hasOne(Ban::class);
|
||||
}
|
||||
}
|
||||
2
dist/config/auth.php
vendored
2
dist/config/auth.php
vendored
|
|
@ -62,7 +62,7 @@
|
|||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\User::class,
|
||||
'model' => \App\Models\User\User::class,
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
|
|
|
|||
2
dist/database/factories/UserFactory.php
vendored
2
dist/database/factories/UserFactory.php
vendored
|
|
@ -7,7 +7,7 @@
|
|||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
|
|
|
|||
39
dist/database/migrations/2024_02_13_015013_create_bans_table.php
vendored
Normal file
39
dist/database/migrations/2024_02_13_015013_create_bans_table.php
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('bans', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignUuid('user_id')->constrained()->onDelete('cascade');
|
||||
$table->string('ban_reason');
|
||||
$table->date('start_date');
|
||||
$table->date('end_date');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('is_banned');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bans');
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('is_banned');
|
||||
});
|
||||
}
|
||||
};
|
||||
3
dist/routes/deathgardenApi.php
vendored
3
dist/routes/deathgardenApi.php
vendored
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use App\Http\Controllers\Api\Auth\SteamAuthController;
|
||||
use App\Http\Controllers\Api\Eula\EulaConsentController;
|
||||
use App\Http\Controllers\Api\Player\PlayerController;
|
||||
use App\Http\Controllers\Api\VersionController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
|
@ -25,5 +26,7 @@
|
|||
Route::middleware('api.auth')->group(function () {
|
||||
Route::get('consent/eula2', [EulaConsentController::class, 'get'])->name(EulaConsentController::class);
|
||||
Route::put('consent/eula2', [EulaConsentController::class, 'put'])->name(EulaConsentController::class);
|
||||
|
||||
Route::get('players/ban/status', [PlayerController::class, 'getBanStatus']);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user