Skip to content

Commit

Permalink
Add primary BLID selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ShockFromBL committed Apr 7, 2024
1 parent bc48b52 commit 760a0d5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 20 deletions.
63 changes: 53 additions & 10 deletions app/Http/Controllers/MyAccountLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.',
]);
}
Expand All @@ -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.',
]);
}

Expand All @@ -52,15 +95,15 @@ 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.' : ''),
]);
}

$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.',
]);
}
Expand All @@ -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.');
}
}
39 changes: 29 additions & 10 deletions resources/views/my-account/link/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,47 @@

@section('content')
<h2>Link</h2>
<p>To link a BLID to your account, please submit it below:</p>
<form method="post">
@csrf
<input type="text" name="blid" placeholder="BLID" style="padding: 10px; width: 100%; box-sizing: border-box;" autocomplete="off" autofocus>
</form>
@if ($errors->any())
@foreach ($errors->all() as $error)
<div class="error">{{ $error }}</div>
@endforeach
@else
@if (isset($success))
<div class="success">{{ $success }}</div>
@if (session()->has('success'))
<div class="success">{{ session('success') }}</div>
@endif
@endif
<p>To link a BLID from your Steam account, please submit it below:</p>
<form method="post">
@csrf
<input type="text" name="blid" placeholder="BLID" style="padding: 10px; width: 100%; box-sizing: border-box;" autocomplete="off" autofocus>
</form>
<p>Your Glass account status is currently: <strong style="color: {{ $color }};">{{ $status }}</strong></p>
@if (!auth()->user()->primary_blid)
<p><strong>To finish verifying your account, you must select a primary BLID. This can only be done once:</strong></p>
<form method="post">
@csrf
<select name="primary" required>
<option value=""></option>
@foreach (auth()->user()->blids as $blid)
<option value="{{ $blid->id }}">{{ $blid->id }}</option>
@endforeach
</select>
<button type="submit">Select</button>
</form>
<p>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.</p>
@endif
<p>Your linked BLIDs:</p>
@if (auth()->user()->blids->isNotEmpty())
<p>Your account is currently linked to:</p>
<ul>
@foreach (auth()->user()->blids as $blid)
<li>{{ $blid->id }} ({{ $blid->name }})</li>
@if ($blid->id === auth()->user()->primary_blid)
<li><strong>{{ $blid->id }} ({{ $blid->name }})</strong></li>
@else
<li>{{ $blid->id }} ({{ $blid->name }})</li>
@endif
@endforeach
</ul>
@else
<p>Your account is not currently linked to any BLIDs.</p>
<p>Your Glass account is not currently linked to any BLIDs.</p>
@endif
@endsection

0 comments on commit 760a0d5

Please sign in to comment.