Skip to content

Commit

Permalink
Add deletion in admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
cydrobolt committed Jan 18, 2016
1 parent 071233c commit 4adf77e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/Http/Controllers/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@ public function generateNewAPIKey(Request $request) {

return $user->api_key;
}

public function deleteUser(Request $request) {
if (!$this->currIsAdmin()) {
abort(401, 'User not admin.');
}

$user_id = $request->input('user_id');
$user = UserHelper::getUserById($user_id);

if (!$user) {
abort(404, 'User not found.');
}
$user->delete();
return "OK";
}
}
2 changes: 2 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
$app->post('/api/v2/link_avail_check', ['as' => 'api_link_check', 'uses' => 'AjaxController@checkLinkAvailability']);
$app->post('/api/v2/admin/toggle_api_active', ['as' => 'api_toggle_api_active', 'uses' => 'AjaxController@toggleAPIActive']);
$app->post('/api/v2/admin/generate_new_api_key', ['as' => 'api_generate_new_api_key', 'uses' => 'AjaxController@generateNewAPIKey']);

$app->post('/api/v2/admin/delete_user', ['as' => 'api_generate_new_api_key', 'uses' => 'AjaxController@deleteUser']);
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function up()
$table->string('api_quota')->default(60);

$table->timestamps();
$table->softDeletes();
});
}

Expand Down
13 changes: 12 additions & 1 deletion public/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ $(function () {
syncHash();
});

$('.delete-user').click(function () {
var te = $(this);
var user_id = te.data('user-id');

apiCall('admin/delete_user', {
'user_id': user_id,
}, function (new_status) {
te.text('Deleted!');
te.addClass('btn-disabled');
});
});

$('.activate-api-modal').click(function () {
var te = $(this);
var username = te.data('username');
Expand Down Expand Up @@ -92,7 +104,6 @@ $(function () {
if (action == 'toggle-api-active') {
new_status = res_value_to_text(new_status);
}
console.log(status_display_elem.html());
status_display_elem.text(new_status);
});
});
Expand Down
6 changes: 3 additions & 3 deletions resources/views/snippets/user_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
</td>

<td>
<a class='activate-edit-modal btn btn-sm btn-success'
<a class='delete-user btn btn-sm btn-danger'

data-username='{{$user->username}}'>
Edit
data-user-id='{{$user->id}}'>
Delete
</a>
</td>

Expand Down

0 comments on commit 4adf77e

Please sign in to comment.