2016-10-14 21:15:36 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-10-14 21:15:36 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Base;
|
|
|
|
|
2017-12-03 20:00:47 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2018-07-01 00:50:58 +00:00
|
|
|
use Illuminate\Auth\AuthManager;
|
2017-08-31 02:11:14 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2018-07-01 00:50:58 +00:00
|
|
|
use Illuminate\Contracts\Session\Session;
|
2016-10-14 21:15:36 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-08-31 02:11:14 +00:00
|
|
|
use Pterodactyl\Services\Users\UserUpdateService;
|
2017-08-31 02:14:20 +00:00
|
|
|
use Pterodactyl\Http\Requests\Base\AccountDataFormRequest;
|
2016-10-14 21:15:36 +00:00
|
|
|
|
|
|
|
class AccountController extends Controller
|
|
|
|
{
|
2017-08-31 02:11:14 +00:00
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
2018-07-01 00:50:58 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Auth\SessionGuard
|
|
|
|
*/
|
|
|
|
protected $sessionGuard;
|
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Users\UserUpdateService
|
|
|
|
*/
|
|
|
|
protected $updateService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AccountController constructor.
|
|
|
|
*
|
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
2018-07-01 00:50:58 +00:00
|
|
|
* @param \Illuminate\Auth\AuthManager $authManager
|
2017-08-31 02:11:14 +00:00
|
|
|
* @param \Pterodactyl\Services\Users\UserUpdateService $updateService
|
|
|
|
*/
|
2018-07-01 00:50:58 +00:00
|
|
|
public function __construct(AlertsMessageBag $alert, AuthManager $authManager, UserUpdateService $updateService)
|
2017-12-03 20:00:47 +00:00
|
|
|
{
|
2017-08-31 02:11:14 +00:00
|
|
|
$this->alert = $alert;
|
|
|
|
$this->updateService = $updateService;
|
2018-07-01 00:50:58 +00:00
|
|
|
$this->sessionGuard = $authManager->guard();
|
2017-08-27 20:10:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 21:15:36 +00:00
|
|
|
/**
|
|
|
|
* Display base account information page.
|
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\View\View
|
2016-10-14 21:15:36 +00:00
|
|
|
*/
|
2017-08-31 02:11:14 +00:00
|
|
|
public function index()
|
2016-10-14 21:15:36 +00:00
|
|
|
{
|
|
|
|
return view('base.account');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-31 02:11:14 +00:00
|
|
|
* Update details for a user's account.
|
2017-03-19 23:36:50 +00:00
|
|
|
*
|
2017-08-31 02:11:14 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Base\AccountDataFormRequest $request
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-08-31 02:11:14 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2016-10-14 21:15:36 +00:00
|
|
|
*/
|
2017-08-31 02:11:14 +00:00
|
|
|
public function update(AccountDataFormRequest $request)
|
2016-10-14 21:15:36 +00:00
|
|
|
{
|
2018-07-01 00:50:58 +00:00
|
|
|
// Prevent logging this specific session out when the password is changed. This will
|
|
|
|
// automatically update the user's password anyways, so no need to do anything else here.
|
2017-01-22 21:16:43 +00:00
|
|
|
if ($request->input('do_action') === 'password') {
|
2018-07-01 00:50:58 +00:00
|
|
|
$this->sessionGuard->logoutOtherDevices($request->input('new_password'));
|
|
|
|
} else {
|
|
|
|
if ($request->input('do_action') === 'email') {
|
|
|
|
$data = ['email' => $request->input('new_email')];
|
|
|
|
} elseif ($request->input('do_action') === 'identity') {
|
|
|
|
$data = $request->only(['name_first', 'name_last', 'username']);
|
|
|
|
} else {
|
|
|
|
$data = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->updateService->setUserLevel(User::USER_LEVEL_USER);
|
|
|
|
$this->updateService->handle($request->user(), $data);
|
2017-01-22 21:16:43 +00:00
|
|
|
}
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
$this->alert->success(trans('base.account.details_updated'))->flash();
|
2016-10-14 21:15:36 +00:00
|
|
|
|
|
|
|
return redirect()->route('account');
|
|
|
|
}
|
|
|
|
}
|