Skip to content

Commit 3355554

Browse files
committed
Fix frontend database password reset
1 parent 32dec97 commit 3355554

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

app/Http/Controllers/Server/AjaxController.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,16 @@ public function postResetDatabasePassword(Request $request, $uuid)
224224
$server = Models\Server::byUuid($uuid);
225225
$this->authorize('reset-db-password', $server);
226226

227-
$database = Models\Database::where('id', $request->input('database'))->where('server_id', $server->id)->firstOrFail();
227+
$database = Models\Database::where('server_id', $server->id)->findOrFail($request->input('database'));
228+
$repo = new Repositories\DatabaseRepository;
229+
228230
try {
229-
$repo = new Repositories\DatabaseRepository;
230-
$password = str_random(16);
231-
$repo->modifyPassword($request->input('database'), $password);
231+
$password = str_random(20);
232+
$repo->password($database->id, $password);
232233

233234
return response($password);
234-
} catch (\Pterodactyl\Exceptions\DisplayException $ex) {
235-
return response()->json([
236-
'error' => $ex->getMessage(),
237-
], 503);
235+
} catch (DisplayException $ex) {
236+
return response()->json(['error' => $ex->getMessage()], 503);
238237
} catch (\Exception $ex) {
239238
Log::error($ex);
240239

public/themes/pterodactyl/css/pterodactyl.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ code {
6565
font-size: 14px !important;
6666
}
6767

68-
.middle {
68+
.middle, .align-middle {
6969
vertical-align: middle !important;
7070
}
7171

resources/themes/pterodactyl/server/settings/databases.blade.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@
4949
<th>@lang('strings.username')</th>
5050
<th>@lang('strings.password')</th>
5151
<th>@lang('server.config.database.host')</th>
52+
@can('reset-db-password', $server)<td></td>@endcan
5253
</tr>
5354
@foreach($databases as $database)
5455
<tr>
55-
<td>{{ $database->database }}</td>
56-
<td>{{ $database->username }}</td>
57-
<td><code>{{ Crypt::decrypt($database->password) }}</code>
58-
@can('reset-db-password', $server)
59-
<button class="btn btn-xs btn-primary pull-right" data-action="reset-database-password" data-id="{{ $database->id }}"><i class="fa fa-fw fa-refresh"></i> @lang('server.config.database.reset_password')</button>
60-
@endcan
61-
</td>
62-
<td><code>{{ $database->a_host }}:{{ $database->a_port }}</code></td>
56+
<td class="middle">{{ $database->database }}</td>
57+
<td class="middle">{{ $database->username }}</td>
58+
<td class="middle"><code data-attr="set-password">{{ Crypt::decrypt($database->password) }}</code></td>
59+
<td class="middle"><code>{{ $database->a_host }}:{{ $database->a_port }}</code></td>
60+
@can('reset-db-password', $server)
61+
<td>
62+
<button class="btn btn-xs btn-primary pull-right" data-action="reset-password" data-id="{{ $database->id }}"><i class="fa fa-fw fa-refresh"></i> @lang('server.config.database.reset_password')</button>
63+
</td>
64+
@endcan
6365
</tr>
6466
@endforeach
6567
</tbody>
@@ -88,21 +90,21 @@
8890
{!! Theme::js('js/frontend/server.socket.js') !!}
8991
<script>
9092
@can('reset-db-password', $server)
91-
$('[data-action="reset-database-password"]').click(function (e) {
93+
$('[data-action="reset-password"]').click(function (e) {
9294
e.preventDefault();
9395
var block = $(this);
94-
$(this).find('i').addClass('fa-spin');
96+
$(this).addClass('disabled').find('i').addClass('fa-spin');
9597
$.ajax({
9698
type: 'POST',
9799
url: Router.route('server.ajax.reset-database-password', { server: Pterodactyl.server.uuidShort }),
98100
headers: {
99101
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
100102
},
101103
data: {
102-
'database': $(this).data('id')
104+
database: $(this).data('id')
103105
}
104106
}).done(function (data) {
105-
block.parent().find('code').html(data);
107+
block.parent().parent().find('[data-attr="set-password"]').html(data);
106108
}).fail(function(jqXHR, textStatus, errorThrown) {
107109
console.error(jqXHR);
108110
var error = 'An error occured while trying to process this request.';
@@ -115,7 +117,7 @@
115117
text: error
116118
});
117119
}).always(function () {
118-
block.find('i').removeClass('fa-spin');
120+
block.removeClass('disabled').find('i').removeClass('fa-spin');
119121
});
120122
});
121123
@endcan

0 commit comments

Comments
 (0)