diff --git a/app/Http/Controllers/Admin/AccountsController.php b/app/Http/Controllers/Admin/AccountsController.php index a4b071fa64..024d0822b3 100644 --- a/app/Http/Controllers/Admin/AccountsController.php +++ b/app/Http/Controllers/Admin/AccountsController.php @@ -3,8 +3,10 @@ namespace Pterodactyl\Http\Controllers\Admin; use Alert; +use Mail; use Pterodactyl\Models\User; use Pterodactyl\Repositories\UserRepository; +use Pterodactyl\Models\Server; use Pterodactyl\Http\Controllers\Controller; use Illuminate\Http\Request; @@ -38,7 +40,16 @@ public function getNew(Request $request) public function getView(Request $request, $id) { - // + return view('admin.accounts.view', ['user' => User::findOrFail($id), 'servers' => Server::where('owner', $id)->first()]); + } + + public function getDelete(Request $request, $id) + { + $user = new UserRepository; + $user->delete($id); + + Alert::success('An account has been successfully deleted.')->flash(); + return redirect()->route('admin.accounts'); } public function postNew(Request $request) @@ -65,4 +76,43 @@ public function postNew(Request $request) } + public function postUpdate(Request $request) + { + $this->validate($request, [ + 'email' => 'required|email|unique:users,email,'.$request->input('user'), + 'root_admin' => 'required', + 'password' => 'required_with:password_confirmation', + 'password_confirmation' => 'required_with:password' + ]); + + try { + + $users = new UserRepository; + $user = []; + + $user['email'] = $request->input('email'); + $user['root_admin'] = $request->input('root_admin'); + + if(!empty($request->input('password'))) { + $user['password'] = $request->input('password'); + } + + $users->update($request->input('user'), $user); + + } catch (\Exception $e) { + Alert::danger('An error occured while attempting to update a user. Please check the logs or try again.')->flash(); + return redirect()->route('admin.accounts.view', ['id' => $request->input('user')]); + } + + if($request->input('email_user')) { + Mail::send('emails.new_password', ['user' => User::findOrFail($request->input('user')), 'password' => $request->input('password')], function($message) use ($request) { + $message->to($request->input('email'))->subject('Pterodactyl - Admin Reset Password'); + }); + } + + Alert::success('A user was successfully updated.')->flash(); + return redirect()->route('admin.accounts.view', ['id' => $request->input('user')]); + + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index 1f5e48e292..18ceff19f9 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -12,11 +12,15 @@ public function map(Router $router) { // Account Routes $router->group(['prefix' => 'accounts'], function ($server) use ($router) { - $router->get('/', [ 'as' => 'admin.accounts', 'uses' => 'Admin\AccountsController@getIndex' ]); - $router->get('/view/{id}', [ 'as' => 'admin.accounts.view', 'uses' => 'Admin\AccountsController@getView' ]); $router->get('/new', [ 'as' => 'admin.accounts.new', 'uses' => 'Admin\AccountsController@getNew' ]); $router->post('/new', [ 'as' => 'admin.accounts.new', 'uses' => 'Admin\AccountsController@postNew' ]); + + $router->get('/', [ 'as' => 'admin.accounts', 'uses' => 'Admin\AccountsController@getIndex' ]); + $router->get('/view/{id}', [ 'as' => 'admin.accounts.view', 'uses' => 'Admin\AccountsController@getView' ]); + + $router->post('/update', [ 'as' => 'admin.accounts.update', 'uses' => 'Admin\AccountsController@postUpdate' ]); + $router->get('/delete/{id}', [ 'as' => 'admin.accounts.delete', 'uses' => 'Admin\AccountsController@getDelete' ]); }); // Server Routes diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index cf60b7b9a6..a76fcb95bc 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -41,4 +41,36 @@ public function create($username, $email, $password) } + /** + * Updates a user on the panel. Returns true if the update was successful. + * + * @param string $username + * @param string $email + * @param string $password An unhashed version of the user's password. + * @return boolean + */ + public function update($id, $user) + { + if(array_key_exists('password', $user)) { + $user['password'] = Hash::make($user['password']); + } + + User::where('id', $id)->update($user); + return true; + } + + /** + * Deletes a user on the panel. Returns true if the deletion was successful. + * + * @param string $username + * @param string $email + * @param string $password An unhashed version of the user's password. + * @return boolean + */ + public function delete($id) + { + User::destroy($id); + return true; + } + } diff --git a/resources/lang/en/base.php b/resources/lang/en/base.php index 852b6e16b8..e5ca4f2d48 100644 --- a/resources/lang/en/base.php +++ b/resources/lang/en/base.php @@ -14,6 +14,7 @@ 'validation_error' => 'An error occured while validating the data you submitted:', + 'confirm' => 'Are you sure?', 'failed' => 'These credentials do not match our records.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 'view_as_admin' => 'You are viewing this server listing as an admin. As such, all servers installed on the system are displayed. Any servers that you are set as the owner of are marked with a blue dot to the left of their name.', @@ -21,6 +22,7 @@ 'no_servers' => 'You do not currently have any servers listed on your account.', 'form_error' => 'The following errors were encountered while trying to process this request.', 'password_req' => 'Passwords must meet the following requirements: at least one uppercase character, one lowercase character, one digit, and be at least 8 characters in length.', + 'root_administrator' => 'Setting this to "Yes" gives a user full administrative access to PufferPanel.', 'account' => [ 'totp_header' => 'Two-Factor Authentication', @@ -35,6 +37,9 @@ 'totp_enabled' => 'Your account has been enabled with TOTP verification. Please click the close button on this box to finish.', 'totp_enabled_error' => 'The TOTP token provided was unable to be verified. Please try again.', + 'email_password' => 'Email Password', + 'update_user' => 'Update User', + 'delete_user' => 'Delete User', 'update_email' => 'Update Email', 'new_email' => 'New Email', 'new_password' => 'New Password', diff --git a/resources/lang/en/server.php b/resources/lang/en/server.php index 1e7461db29..bb32307aab 100644 --- a/resources/lang/en/server.php +++ b/resources/lang/en/server.php @@ -14,6 +14,7 @@ 'socket_status_crashed' => 'This server has been detected as CRASHED.', ], 'index' => [ + 'add_new' => 'Add New Server', 'memory_use' => 'Memory Usage', 'cpu_use' => 'CPU Usage', 'xaxis' => 'Time (2s Increments)', diff --git a/resources/lang/en/strings.php b/resources/lang/en/strings.php index 6b452c4a6c..9c9de3446e 100644 --- a/resources/lang/en/strings.php +++ b/resources/lang/en/strings.php @@ -27,5 +27,9 @@ 'submit' => 'Submit', 'current_password' => 'Current Password', 'again' => 'Again', + 'registered' => 'Registered', + 'root_administrator' => 'Root Administrator', + 'yes' => 'Yes', + 'no' => 'No' ]; diff --git a/resources/views/admin/accounts/view.blade.php b/resources/views/admin/accounts/view.blade.php new file mode 100644 index 0000000000..8cd481ba8a --- /dev/null +++ b/resources/views/admin/accounts/view.blade.php @@ -0,0 +1,155 @@ +@extends('layouts.admin') + +@section('title') + Viewing User +@endsection + +@section('content') +
+ + @if (count($errors) > 0) +
+ {{ trans('strings.whoops') }}! {{ trans('auth.errorencountered') }}

+ +
+ @endif + @foreach (Alert::getMessages() as $type => $messages) + @foreach ($messages as $message) + + @endforeach + @endforeach +

Viewing User: {{ $user->email }}


+
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +

{{ trans('base.root_administrator') }}

+
+
+
+ + {!! csrf_field() !!} + + + + +
+
+
+
+
+

{{ trans('base.account.update_pass') }}


+ +
+ +
+ +
+
+
+ +
+ +
+ +
+
+ +
+
+
+
+
+
+
+
+

Associated Servers


+ @if($servers) + + + + + + + + + + + + @foreach($servers as $server) + + + + + + + + @endforeach + +
Server NameNodeConnection
{{ $server->name }}{{ $server->node_name }}{{ $server->server_ip }}:{{ $server->server_port }}@if($server->active)Enabled@elseDisabled@endif
+ @else +
There are no servers associated with this account.
+ @endif + +
+
+
+ + +@endsection diff --git a/resources/views/emails/new_password.blade.php b/resources/views/emails/new_password.blade.php new file mode 100644 index 0000000000..4a154c0a5a --- /dev/null +++ b/resources/views/emails/new_password.blade.php @@ -0,0 +1,14 @@ + + + + Pterodactyl - Admin Reset Password + + +

Pterodactyl - Admin Reset Password

+

Hello there! You are receiving this email because an admin has reset the password on your Pterodactyl account.

+

Login: {{ config('app.url') }}/auth/login
+ Email: {{ $user->email }}
+ Password: {{ $password }}

+

Thanks,
Pterodactyl

+ + \ No newline at end of file