админка
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\UpdateAccountAccessRequest;
|
||||
use App\Services\AzerothCoreAccountService;
|
||||
use App\Services\InviteCodeService;
|
||||
use App\Support\WowData;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
public function index(
|
||||
Request $request,
|
||||
AzerothCoreAccountService $accounts,
|
||||
InviteCodeService $inviteCodes,
|
||||
): View
|
||||
{
|
||||
$search = trim((string) $request->query('search', ''));
|
||||
|
||||
return view('admin.accounts.index', [
|
||||
'accounts' => $accounts->listAccounts($search !== '' ? $search : null),
|
||||
'inviteCodes' => $inviteCodes->latest(),
|
||||
'inviteStats' => $inviteCodes->stats(),
|
||||
'search' => $search,
|
||||
'accessLevels' => WowData::securityLevels(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateAccess(int $accountId, UpdateAccountAccessRequest $request, AzerothCoreAccountService $accounts): RedirectResponse
|
||||
{
|
||||
abort_unless($accounts->findUserById($accountId), 404);
|
||||
|
||||
$accounts->updateAccessLevel($accountId, (int) $request->input('gmlevel'));
|
||||
|
||||
return back()->with('status', 'Уровень доступа обновлён.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\CreateInviteCodesRequest;
|
||||
use App\Services\InviteCodeService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class InviteCodeController extends Controller
|
||||
{
|
||||
public function store(CreateInviteCodesRequest $request, InviteCodeService $inviteCodes): RedirectResponse
|
||||
{
|
||||
$created = $inviteCodes->createCodes(
|
||||
(int) $request->integer('quantity'),
|
||||
$request->user(),
|
||||
);
|
||||
|
||||
return back()->with('status', sprintf('Создано инвайт-кодов: %d.', $created->count()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\LoginRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::attempt($request->safe()->only(['username', 'password']))) {
|
||||
return back()
|
||||
->withErrors(['username' => 'Неверный логин или пароль.'])
|
||||
->onlyInput('username');
|
||||
}
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(route('cabinet.index'));
|
||||
}
|
||||
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect()
|
||||
->route('login')
|
||||
->with('status', 'Сеанс завершён. Можно войти снова.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ChangePasswordRequest;
|
||||
use App\Services\AzerothCoreAccountService;
|
||||
use App\Services\GameClientDownloadService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Throwable;
|
||||
|
||||
class CabinetController extends Controller
|
||||
{
|
||||
public function index(Request $request, AzerothCoreAccountService $accounts): View
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return view('cabinet.index', [
|
||||
'user' => $user,
|
||||
'characters' => $accounts->charactersForAccount($user->id),
|
||||
'clientFilename' => config('moonwell.client.object_key'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function updatePassword(ChangePasswordRequest $request, AzerothCoreAccountService $accounts): RedirectResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
if (! $accounts->validatePassword($user, $request->string('current_password')->toString())) {
|
||||
return back()->withErrors(['current_password' => 'Текущий пароль указан неверно.']);
|
||||
}
|
||||
|
||||
$accounts->updatePassword($user, $request->string('password')->toString());
|
||||
|
||||
return back()->with('status', 'Пароль успешно обновлён.');
|
||||
}
|
||||
|
||||
public function client(GameClientDownloadService $clientDownloadService): RedirectResponse
|
||||
{
|
||||
try {
|
||||
return redirect()->away($clientDownloadService->temporaryUrl());
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return back()->with('error', 'Не удалось получить ссылку на клиент. Попробуй ещё раз позже.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exceptions\DuplicateGameAccountException;
|
||||
use App\Exceptions\InviteCodeException;
|
||||
use App\Http\Requests\RegisterGameAccountRequest;
|
||||
use App\Services\AzerothCoreAccountRegistrar;
|
||||
use App\Services\InviteCodeService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
use Throwable;
|
||||
@@ -85,24 +87,36 @@ class LandingController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function register(RegisterGameAccountRequest $request, AzerothCoreAccountRegistrar $registrar): RedirectResponse
|
||||
public function register(
|
||||
RegisterGameAccountRequest $request,
|
||||
AzerothCoreAccountRegistrar $registrar,
|
||||
InviteCodeService $inviteCodes,
|
||||
): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$result = $registrar->register(
|
||||
$result = $inviteCodes->redeemForRegistration(
|
||||
$request->string('invite_code')->toString(),
|
||||
$request->string('username')->toString(),
|
||||
$request->string('email')->toString(),
|
||||
$request->string('password')->toString(),
|
||||
fn (): array => $registrar->register(
|
||||
$request->string('username')->toString(),
|
||||
$request->string('email')->toString(),
|
||||
$request->string('password')->toString(),
|
||||
),
|
||||
);
|
||||
} catch (DuplicateGameAccountException $exception) {
|
||||
return back()
|
||||
->withErrors([$exception->field => $exception->getMessage()])
|
||||
->withInput($request->safe()->only(['username', 'email']));
|
||||
->withInput($request->safe()->only(['username', 'email', 'invite_code']));
|
||||
} catch (InviteCodeException $exception) {
|
||||
return back()
|
||||
->withErrors([$exception->field => $exception->getMessage()])
|
||||
->withInput($request->safe()->only(['username', 'email', 'invite_code']));
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return back()
|
||||
->with('registration_error', 'Не удалось создать аккаунт. Проверь настройки сервера и попробуй снова.')
|
||||
->withInput($request->safe()->only(['username', 'email']));
|
||||
->withInput($request->safe()->only(['username', 'email', 'invite_code']));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
|
||||
Reference in New Issue
Block a user