From 760a0d537b8e076ad9216c8c8c9e442f231cbc48 Mon Sep 17 00:00:00 2001 From: ShockFromBL <12955300+ShockFromBL@users.noreply.github.com> Date: Sun, 7 Apr 2024 18:50:23 +0100 Subject: [PATCH] Add primary BLID selection --- .../Controllers/MyAccountLinkController.php | 63 ++++++++++++++++--- .../views/my-account/link/index.blade.php | 39 +++++++++--- 2 files changed, 82 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/MyAccountLinkController.php b/app/Http/Controllers/MyAccountLinkController.php index 1575e81..2cc3228 100644 --- a/app/Http/Controllers/MyAccountLinkController.php +++ b/app/Http/Controllers/MyAccountLinkController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\Blid; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\RateLimiter; use Illuminate\View\View; @@ -13,22 +14,64 @@ class MyAccountLinkController extends Controller */ public function show(): View { - return view('my-account.link.index'); + $status = 'UNVERIFIED (No BLID)'; + $color = '#f00'; + + if (auth()->user()->blids) { + if (auth()->user()->primary_blid) { + $status = 'VERIFIED'; + $color = '#0f0'; + } else { + $status = 'UNVERIFIED (No Primary BLID Selected)'; + } + } + + return view('my-account.link.index')->with([ + 'status' => $status, + 'color' => $color, + ]); } /** * TODO: Write function description. */ - public function store(): View + public function store(): RedirectResponse { + if (request('primary')) { + if (auth()->user()->primary_blid) { + return back()->withErrors([ + 'You have already selected your primary BLID.', + ]); + } + + request()->validate([ + 'primary' => 'required|integer|max_digits:6', + ]); + + $id = request('primary'); + + $blid = Blid::find($id); + + if (! $blid || $blid->user->id !== auth()->user()->id) { + return back()->withErrors([ + 'BLID '.$id.' is not linked to your Glass account.', + ]); + } + + auth()->user()->primary_blid = $blid->id; + auth()->user()->save(); + + return back()->with('success', 'BLID '.$blid->id.' ('.$blid->name.') has been selected as your primary BLID.'); + } + request()->validate([ - 'blid' => 'required|integer|max_digits:6|bail', + 'blid' => 'required|integer|max_digits:6', ], [ 'blid.*' => 'You must enter a valid BLID.', ]); if (RateLimiter::tooManyAttempts('failed-blid-link:'.auth()->user()->id, $perThreeMinutes = 3)) { - return view('my-account.link.index')->withErrors([ + return back()->withErrors([ 'You have too many failed attempts, please try again in a few minutes.', ]); } @@ -39,11 +82,11 @@ public function store(): View 'id' => $id, ]); - if ($blid->exists && $blid->user_id !== null) { + if ($blid->user_id) { RateLimiter::hit('failed-blid-link:'.auth()->user()->id); - return view('my-account.link.index')->withErrors([ - 'BLID '.$id.' is already linked to an account.', + return back()->withErrors([ + 'BLID '.$id.' is already linked.', ]); } @@ -52,7 +95,7 @@ public function store(): View if (! $auth['success']) { RateLimiter::hit('failed-blid-link:'.auth()->user()->id); - return view('my-account.link.index')->withErrors([ + return back()->withErrors([ 'BLID '.$id.' is not associated with your Steam account.'.($id === '0' ? ' Very funny.' : ''), ]); } @@ -60,7 +103,7 @@ public function store(): View $name = $auth['name']; if ($name === null) { - return view('my-account.link.index')->withErrors([ + return back()->withErrors([ 'BLID '.$id.' does not have an in-game name set.', ]); } @@ -71,6 +114,6 @@ public function store(): View RateLimiter::clear('failed-blid-link:'.auth()->user()->id); - return view('my-account.link.index')->with('success', 'BLID '.$id.' ('.$name.') has been successfully linked to your account.'); + return back()->with('success', 'BLID '.$id.' ('.$name.') has been successfully linked to your account.'); } } diff --git a/resources/views/my-account/link/index.blade.php b/resources/views/my-account/link/index.blade.php index a92725c..32bd28c 100644 --- a/resources/views/my-account/link/index.blade.php +++ b/resources/views/my-account/link/index.blade.php @@ -18,28 +18,47 @@ @section('content')

Link

-

To link a BLID to your account, please submit it below:

-
- @csrf - -
@if ($errors->any()) @foreach ($errors->all() as $error)
{{ $error }}
@endforeach @else - @if (isset($success)) -
{{ $success }}
+ @if (session()->has('success')) +
{{ session('success') }}
@endif @endif +

To link a BLID from your Steam account, please submit it below:

+
+ @csrf + +
+

Your Glass account status is currently: {{ $status }}

+ @if (!auth()->user()->primary_blid) +

To finish verifying your account, you must select a primary BLID. This can only be done once:

+
+ @csrf + + +
+

The primary BLID you select will become your username on the Glass website. Both your primary and alternative BLID(s) will be used for verifying ownership of past uploaded add-ons and in-game authentication.

+ @endif +

Your linked BLIDs:

@if (auth()->user()->blids->isNotEmpty()) -

Your account is currently linked to:

@else -

Your account is not currently linked to any BLIDs.

+

Your Glass account is not currently linked to any BLIDs.

@endif @endsection