diff --git a/app/Http/Controllers/Base/AccountController.php b/app/Http/Controllers/Base/AccountController.php index 2bfe9bd9f..dd2bf1936 100644 --- a/app/Http/Controllers/Base/AccountController.php +++ b/app/Http/Controllers/Base/AccountController.php @@ -25,11 +25,13 @@ namespace Pterodactyl\Http\Controllers\Base; +use Log; use Alert; use Illuminate\Http\Request; use Pterodactyl\Models\User; -use Pterodactyl\Exceptions\DisplayException; +use Pterodactyl\Repositories\UserRepository; use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Exceptions\DisplayValidationException; class AccountController extends Controller { @@ -45,61 +47,54 @@ class AccountController extends Controller } /** - * Update an account email. - * + * Update details for a users account. * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @return void */ - public function email(Request $request) + public function update(Request $request) { - $this->validate($request, [ - 'new_email' => 'required|email', - 'password' => 'required', - ]); + $data = []; - $user = $request->user(); + // Request to update account Password + if ($request->input('do_action') === 'password') { + $this->validate($request, [ + 'current_password' => 'required', + 'new_password' => 'required|confirmed|' . User::PASSWORD_RULES, + 'new_password_confirmation' => 'required', + ]); - if (! password_verify($request->input('password'), $user->password)) { - Alert::danger('The password provided was not valid for this account.')->flash(); + $data['password'] = $request->input('new_password'); - return redirect()->route('account'); + // Request to update account Email + } else if ($request->input('do_action') === 'email') { + $data['email'] = $request->input('new_email'); + + // Request to update account Identity + } else if ($request->input('do_action') === 'identity') { + $data = $request->only(['name_first', 'name_last', 'username']); + + // Unknown, hit em with a 404 + } else { + return abort(404); } - $user->email = $request->input('new_email'); - $user->save(); - - Alert::success('Your email address has successfully been updated.')->flash(); - - return redirect()->route('account'); - } - - /** - * Update an account password. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function password(Request $request) - { - $this->validate($request, [ - 'current_password' => 'required', - 'new_password' => 'required|confirmed|different:current_password|' . User::PASSWORD_RULES, - 'new_password_confirmation' => 'required', - ]); - - $user = $request->user(); - - if (! password_verify($request->input('current_password'), $user->password)) { - Alert::danger('The password provided was not valid for this account.')->flash(); - + if ( + in_array($request->input('do_action'), ['email', 'password']) + && ! password_verify($request->input('password'), $request->user()->password) + ) { + Alert::danger(trans('base.account.invalid_pass'))->flash(); return redirect()->route('account'); } try { - $user->setPassword($request->input('new_password')); - Alert::success('Your password has successfully been updated.')->flash(); - } catch (DisplayException $e) { - Alert::danger($e->getMessage())->flash(); + $repo = new UserRepository; + $repo->update($request->user()->id, $data); + Alert::success('Your account details were successfully updated.')->flash(); + } catch (DisplayValidationException $ex) { + return redirect()->route('account')->withErrors(json_decode($ex->getMessage())); + } catch (\Exception $ex) { + Log::error($ex); + Alert::danger(trans('base.account.exception'))->flash(); } return redirect()->route('account'); diff --git a/app/Http/Routes/BaseRoutes.php b/app/Http/Routes/BaseRoutes.php index 811fb45b7..9c42cbd61 100644 --- a/app/Http/Routes/BaseRoutes.php +++ b/app/Http/Routes/BaseRoutes.php @@ -63,13 +63,8 @@ class BaseRoutes 'as' => 'account', 'uses' => 'Base\AccountController@index', ]); - $router->post('/password', [ - 'as' => 'account.password', - 'uses' => 'Base\AccountController@password', - ]); - $router->post('/email', [ - 'as' => 'account.email', - 'uses' => 'Base\AccountController@email', + $router->post('/', [ + 'uses' => 'Base\AccountController@update', ]); }); diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 7c3af08db..933db40cc 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -154,10 +154,6 @@ class UserRepository unset($data['password']); } - if (! empty($data['root_admin'])) { - $user->root_admin = $data['root_admin']; - } - $user->fill($data); return $user->save(); diff --git a/public/themes/pterodactyl/css/pterodactyl.css b/public/themes/pterodactyl/css/pterodactyl.css index f9e8d8a75..5c849120d 100644 --- a/public/themes/pterodactyl/css/pterodactyl.css +++ b/public/themes/pterodactyl/css/pterodactyl.css @@ -121,3 +121,7 @@ td.has-progress { .box-header > .form-group > div > p.small { margin: 0; } + +.no-margin { + margin: 0 !important; +} diff --git a/resources/lang/en/base.php b/resources/lang/en/base.php index 4891ff61b..c71f04578 100644 --- a/resources/lang/en/base.php +++ b/resources/lang/en/base.php @@ -163,6 +163,12 @@ return [ 'new_password' => 'New Password', 'new_password_again' => 'Repeat New Password', 'new_email' => 'New Email Address', + 'first_name' => 'First Name', + 'last_name' => 'Last Name', + 'update_identitity' => 'Update Identity', + 'username_help' => 'Your username must be unique to your account, and may only contain the following characters: :requirements.', + 'invalid_pass' => 'The password provided was not valid for this account.', + 'exception' => 'An error occurred while attempting to update your account.', ], 'security' => [ 'header' => 'Account Security', diff --git a/resources/themes/pterodactyl/base/account.blade.php b/resources/themes/pterodactyl/base/account.blade.php index 0bb797fda..beec27402 100644 --- a/resources/themes/pterodactyl/base/account.blade.php +++ b/resources/themes/pterodactyl/base/account.blade.php @@ -34,64 +34,115 @@ @section('content')