Delete account is no longer a GET request

This commit is contained in:
Dane Everitt 2016-01-04 16:22:57 -05:00
parent 4ae8a45ed3
commit 98d2a1e1fd
3 changed files with 30 additions and 10 deletions

View file

@ -47,13 +47,17 @@ class AccountsController extends Controller
]);
}
public function getDelete(Request $request, $id)
public function deleteView(Request $request, $id)
{
$user = new UserRepository;
$user->delete($id);
Alert::success('An account has been successfully deleted.')->flash();
return redirect()->route('admin.accounts');
try {
User::findOrFail($id)->delete();
return response(null, 204);
} catch(\Exception $ex) {
Log::error($ex);
return response()->json([
'error' => 'An error occured while attempting to delete this user.'
], 500);
}
}
public function postNew(Request $request)

View file

@ -55,8 +55,8 @@ class AdminRoutes {
]);
// Delete an Account Matching an ID
$router->get('/delete/{id}', [
'uses' => 'Admin\AccountsController@getDelete'
$router->delete('/view/{id}', [
'uses' => 'Admin\AccountsController@deleteView'
]);
});

View file

@ -61,8 +61,8 @@
<input type="hidden" name="user" value="{{ $user->id }}">
{!! csrf_field() !!}
<input type="submit" value="{{ trans('base.account.update_user') }}" class="btn btn-primary btn-sm">
<a href="/admin/accounts/delete/{{ $user->id }}">
<button id="delete" type="button" class="btn btn-sm btn-danger" value="{{ trans('base.account.delete_user') }}">{{ trans('base.account.delete_user') }}</button>
<a href="#">
<button type="button" class="btn btn-sm btn-danger" data-action="deleteUser" value="{{ trans('base.account.delete_user') }}">{{ trans('base.account.delete_user') }}</button>
</a>
</div>
</fieldset>
@ -150,6 +150,22 @@ $(document).ready(function(){
});
return false;
});
$('button[data-action="deleteUser"]').click(function (event) {
event.preventDefault();
$.ajax({
method: 'DELETE',
url: '/admin/accounts/view/{{ $user->id }}',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).done(function (data) {
alert('Account was successfully deleted from the system.');
window.location = '/admin/accounts';
}).fail(function (jqXHR) {
console.error(jqXHR);
alert('An error occured: ' + jqXHR.JSONResponse.error);
})
})
});
</script>
@endsection