1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Http\Controllers;
7
8use App\Models\UserClient;
9
10class ClientVerificationsController extends Controller
11{
12 public function __construct()
13 {
14 $this->middleware('auth', ['only' => 'store']);
15 $this->middleware('verify-user');
16 $this->middleware('throttle:60,10');
17
18 parent::__construct();
19 }
20
21 public function create()
22 {
23 if (!auth()->check()) {
24 return ext_view('sessions.create', null, null, 401);
25 }
26
27 $hash = request('ch');
28 $client = UserClient::lookupOrNew(auth()->user()->getKey(), $hash);
29
30 if ($client->verified) {
31 return ext_view('client_verifications.completed');
32 }
33
34 return ext_view('client_verifications.create', compact('hash'));
35 }
36
37 public function store()
38 {
39 $hash = request('ch');
40 UserClient::markVerified(auth()->user()->getKey(), $hash);
41
42 return ujs_redirect(route('client-verifications.create', ['ch' => $hash]));
43 }
44}