Fix frontend database password reset

This commit is contained in:
Dane Everitt 2017-03-05 16:46:44 -05:00
parent 32dec97e46
commit 3355554704
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 23 additions and 22 deletions

View file

@ -224,17 +224,16 @@ class AjaxController extends Controller
$server = Models\Server::byUuid($uuid); $server = Models\Server::byUuid($uuid);
$this->authorize('reset-db-password', $server); $this->authorize('reset-db-password', $server);
$database = Models\Database::where('id', $request->input('database'))->where('server_id', $server->id)->firstOrFail(); $database = Models\Database::where('server_id', $server->id)->findOrFail($request->input('database'));
$repo = new Repositories\DatabaseRepository;
try { try {
$repo = new Repositories\DatabaseRepository; $password = str_random(20);
$password = str_random(16); $repo->password($database->id, $password);
$repo->modifyPassword($request->input('database'), $password);
return response($password); return response($password);
} catch (\Pterodactyl\Exceptions\DisplayException $ex) { } catch (DisplayException $ex) {
return response()->json([ return response()->json(['error' => $ex->getMessage()], 503);
'error' => $ex->getMessage(),
], 503);
} catch (\Exception $ex) { } catch (\Exception $ex) {
Log::error($ex); Log::error($ex);

View file

@ -65,7 +65,7 @@ code {
font-size: 14px !important; font-size: 14px !important;
} }
.middle { .middle, .align-middle {
vertical-align: middle !important; vertical-align: middle !important;
} }

View file

@ -49,17 +49,19 @@
<th>@lang('strings.username')</th> <th>@lang('strings.username')</th>
<th>@lang('strings.password')</th> <th>@lang('strings.password')</th>
<th>@lang('server.config.database.host')</th> <th>@lang('server.config.database.host')</th>
@can('reset-db-password', $server)<td></td>@endcan
</tr> </tr>
@foreach($databases as $database) @foreach($databases as $database)
<tr> <tr>
<td>{{ $database->database }}</td> <td class="middle">{{ $database->database }}</td>
<td>{{ $database->username }}</td> <td class="middle">{{ $database->username }}</td>
<td><code>{{ Crypt::decrypt($database->password) }}</code> <td class="middle"><code data-attr="set-password">{{ Crypt::decrypt($database->password) }}</code></td>
@can('reset-db-password', $server) <td class="middle"><code>{{ $database->a_host }}:{{ $database->a_port }}</code></td>
<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> @can('reset-db-password', $server)
@endcan <td>
</td> <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>
<td><code>{{ $database->a_host }}:{{ $database->a_port }}</code></td> </td>
@endcan
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
@ -88,10 +90,10 @@
{!! Theme::js('js/frontend/server.socket.js') !!} {!! Theme::js('js/frontend/server.socket.js') !!}
<script> <script>
@can('reset-db-password', $server) @can('reset-db-password', $server)
$('[data-action="reset-database-password"]').click(function (e) { $('[data-action="reset-password"]').click(function (e) {
e.preventDefault(); e.preventDefault();
var block = $(this); var block = $(this);
$(this).find('i').addClass('fa-spin'); $(this).addClass('disabled').find('i').addClass('fa-spin');
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: Router.route('server.ajax.reset-database-password', { server: Pterodactyl.server.uuidShort }), url: Router.route('server.ajax.reset-database-password', { server: Pterodactyl.server.uuidShort }),
@ -99,10 +101,10 @@
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'), 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
}, },
data: { data: {
'database': $(this).data('id') database: $(this).data('id')
} }
}).done(function (data) { }).done(function (data) {
block.parent().find('code').html(data); block.parent().parent().find('[data-attr="set-password"]').html(data);
}).fail(function(jqXHR, textStatus, errorThrown) { }).fail(function(jqXHR, textStatus, errorThrown) {
console.error(jqXHR); console.error(jqXHR);
var error = 'An error occured while trying to process this request.'; var error = 'An error occured while trying to process this request.';
@ -115,7 +117,7 @@
text: error text: error
}); });
}).always(function () { }).always(function () {
block.find('i').removeClass('fa-spin'); block.removeClass('disabled').find('i').removeClass('fa-spin');
}); });
}); });
@endcan @endcan