misc_pterodactyl-panel/app/Http/Controllers/Base/AccountController.php

73 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2016-12-07 22:46:38 +00:00
namespace Pterodactyl\Http\Controllers\Base;
use Pterodactyl\Models\User;
use Prologue\Alerts\AlertsMessageBag;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Users\UserUpdateService;
2017-08-31 02:14:20 +00:00
use Pterodactyl\Http\Requests\Base\AccountDataFormRequest;
class AccountController extends Controller
{
/**
* @var \Prologue\Alerts\AlertsMessageBag
*/
protected $alert;
/**
* @var \Pterodactyl\Services\Users\UserUpdateService
*/
protected $updateService;
/**
* AccountController constructor.
*
* @param \Prologue\Alerts\AlertsMessageBag $alert
* @param \Pterodactyl\Services\Users\UserUpdateService $updateService
*/
public function __construct(AlertsMessageBag $alert, UserUpdateService $updateService)
{
$this->alert = $alert;
$this->updateService = $updateService;
}
/**
* Display base account information page.
*
2017-03-19 23:36:50 +00:00
* @return \Illuminate\View\View
*/
public function index()
{
return view('base.account');
}
/**
* Update details for a user's account.
2017-03-19 23:36:50 +00:00
*
* @param \Pterodactyl\Http\Requests\Base\AccountDataFormRequest $request
2017-03-19 23:36:50 +00:00
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function update(AccountDataFormRequest $request)
{
$data = [];
if ($request->input('do_action') === 'password') {
$data['password'] = $request->input('new_password');
2017-01-23 22:11:25 +00:00
} elseif ($request->input('do_action') === 'email') {
$data['email'] = $request->input('new_email');
2017-01-23 22:11:25 +00:00
} elseif ($request->input('do_action') === 'identity') {
$data = $request->only(['name_first', 'name_last', 'username']);
}
2016-12-07 22:46:38 +00:00
$this->updateService->setUserLevel(User::USER_LEVEL_USER);
$this->updateService->handle($request->user(), $data);
$this->alert->success(trans('base.account.details_updated'))->flash();
return redirect()->route('account');
}
}