diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..2119fa8 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,3 @@ +{ + "esnext": true +} diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 71b0d72..54a0068 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -29,5 +29,24 @@ class AjaxController extends Controller { if (!$this->currIsAdmin()) { abort(401, 'User not admin.'); } + + $user_to_toggle = $request->input('user_id'); + $user = User::where('id', $user_id) + ->where('active', 1) + ->first(); + if (!$user) { + abort(404, 'User not found.'); + } + $current_status = $user->api_active; + + if ($current_status == 1) { + $new_status = 0; + } + else { + $new_status = 1; + } + + $user->api_active = $new_status; + $user->save(); } } diff --git a/app/Http/routes.php b/app/Http/routes.php index adc205f..0c5759c 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -35,5 +35,5 @@ $app->post('/signup', ['as' => 'psignup', 'uses' => 'UserController@performSignu $app->post('/shorten', ['as' => 'shorten', 'uses' => 'LinkController@performShorten']); /* API endpoints */ -$app->post('/api/v2/link_avail_check', ['as' => 'link_check', 'uses' => 'AjaxController@checkLinkAvailability']); -$app->post('/api/v2/admin/toggle_api_active', ['as' => 'link_check', 'uses' => 'AjaxController@toggleAPIActive']); +$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']); diff --git a/public/js/admin.js b/public/js/admin.js index 8c603bd..13649fc 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -46,7 +46,7 @@ $(function () { {{else}} False {{/if}} - - Active (click to toggle) + - Active (click to toggle)

API Key: {{api_key}} @@ -62,6 +62,7 @@ $(function () { api_key: api_key, api_active: api_active, api_quota: api_quota, + user_id: user_id, title: "API Information for " + username, body: markup }; @@ -74,12 +75,10 @@ $(function () { $('.activate-edit-modal').click(function () { // activate modal }); - - $('.toggle-api-active').click(function () { + $('body').delegate('.toggle-api-active', 'click', function () { var toggle_user_id = $(this).data('user-id'); apiCall('admin/toggle_api_active', { 'user_id': toggle_user_id, }); }); - }); diff --git a/public/js/api.js b/public/js/api.js index ea524d4..d4407e2 100644 --- a/public/js/api.js +++ b/public/js/api.js @@ -1,6 +1,7 @@ function apiCall(path, data) { - var base_api_path = '/api/v2/'; + var base_api_path = BASE_API_PATH; var api_path = base_api_path + path; + console.log('api call'); $.ajax({ url: api_path, data: data diff --git a/public/js/constants.js b/public/js/constants.js new file mode 100644 index 0000000..a3663dc --- /dev/null +++ b/public/js/constants.js @@ -0,0 +1,3 @@ +/* Polr JS Constants */ + +const BASE_API_PATH = '/api/v2/'; diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php index a815ef2..9b1dbb9 100644 --- a/resources/views/layouts/base.blade.php +++ b/resources/views/layouts/base.blade.php @@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + @yield('css')