diff --git a/app/controllers/PrivilegeController.php b/app/controllers/PrivilegeController.php index f822233..4efe352 100644 --- a/app/controllers/PrivilegeController.php +++ b/app/controllers/PrivilegeController.php @@ -12,6 +12,16 @@ public function store() $privilege->name = Input::get('name'); $privilege->save(); + + return Response::json($privilege); + } + + public function deletePrivilege($id) + { + $privilege = Privilege::find($id); + $privilege->delete(); + + return Response::json(array("success" => true)); } } ?> \ No newline at end of file diff --git a/app/controllers/PulseController.php b/app/controllers/PulseController.php index bdc0201..06cbb9b 100644 --- a/app/controllers/PulseController.php +++ b/app/controllers/PulseController.php @@ -27,5 +27,14 @@ public function store() return Response::json($pulse); } + + public function deletePulse($id) + { + $user = Pulse::find($id); + $user->delete(); + + return Response::json(array("success" => true)); + } + } ?> \ No newline at end of file diff --git a/app/controllers/ServerController.php b/app/controllers/ServerController.php index 2f95324..7ca4231 100644 --- a/app/controllers/ServerController.php +++ b/app/controllers/ServerController.php @@ -101,7 +101,6 @@ public function changeStatus($guid) public function updateServerDetails($guid) { $server = Server::where('guid', '=', $guid)->first()->update(array( - "servergroup_id" => Input::get("servergroup_id"), "available_disk" => Input::get("available_disk"), "available_ram" => Input::get("available_ram"), "cpu_speed" => Input::get("cpu_speed"), diff --git a/app/controllers/ServerGroupController.php b/app/controllers/ServerGroupController.php index 83a707c..ccb5078 100644 --- a/app/controllers/ServerGroupController.php +++ b/app/controllers/ServerGroupController.php @@ -14,6 +14,11 @@ public function getServers($id) public function store() { + if (ServerGroup::where('name','=', Input::get("name"))->count() > 0) { + //$user = User::where('email','=', Input::get("email"))->get()->first(); + return Response::json(array('success' => false , 'error' => 'Server Group already exists')); + } + $serverGroup = new ServerGroup; $serverGroup->name = Input::get("name"); $serverGroup->save(); @@ -34,6 +39,13 @@ public function deleteServerGroup($id) $server->save(); } + $subscriptions = Subscription::where("servergroup_id", "=", $id)->get(); + + foreach($subscriptions as $Subscription) + { + $Subscription->delete(); + } + return Response::json(array("success" => true)); } @@ -41,5 +53,20 @@ public function getServerGroup($id) { return Response::json(ServerGroup::find($id)); } + + public function editServerGroup($id) + { + if (ServerGroup::find($id)->count() > 0) { + //$user = User::where('email','=', Input::get("email"))->get()->first(); + return Response::json(array('success' => false , 'error' => 'Server Group already exists')); + } + + $serverGroup = ServerGroup::find($id); + $serverGroup->name = Input::get("name"); + + $serverGroup->save(); + + return Response::json($serverGroup); + } } ?> \ No newline at end of file diff --git a/app/controllers/SubscriptionController.php b/app/controllers/SubscriptionController.php index 4a2643b..31f6b29 100644 --- a/app/controllers/SubscriptionController.php +++ b/app/controllers/SubscriptionController.php @@ -16,6 +16,18 @@ public function store() $subscription->push = Input::get('push'); $subscription->save(); + + return Response::json($subscription); + } + + public function updateSubscription($id) + { + $subscription = Subscription::find($id); + $subscription->text = Input::get('text'); + $subscription->phonecall = Input::get('phonecall'); + $subscription->save(); + + return Response::json($subscription); } public function deleteSubscription($id) diff --git a/app/filters.php b/app/filters.php index e0bc3b8..1008d48 100644 --- a/app/filters.php +++ b/app/filters.php @@ -65,7 +65,29 @@ { return Response::make('Username or Password Incorrect', 401, array('WWW-Authenticate' => 'Basic realm="your site description"')); } - if(Auth::user()->privilege_id < 5) + //if(Auth::user()->privilege_id < 2) + ////{ + /// return Response::make('You are not authorised to access this resource.', 401, array('WWW-Authenticate' => 'Basic realm="your site description"')); + //} +}); + +Route::filter('user.auth', function() +{ + $email = ""; + $password = ""; + + if (!isset($_SERVER['HTTP_AUTHORIZATION']) || $_SERVER['HTTP_AUTHORIZATION'] == '') + { + return Response::make('Please use basic auth to provide a username and password', 401, array('WWW-Authenticate' => 'Basic realm="your site description"')); + } + else{ + list($email, $password) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); + } + if( ! Auth::attempt(array('email' => $email, 'password' => $password))) + { + return Response::make('Username or Password Incorrect', 401, array('WWW-Authenticate' => 'Basic realm="your site description"')); + } + if(Auth::user()->privilege_id > 1) { return Response::make('You are not authorised to access this resource.', 401, array('WWW-Authenticate' => 'Basic realm="your site description"')); } diff --git a/app/routes.php b/app/routes.php index 7aaff17..cd629ac 100644 --- a/app/routes.php +++ b/app/routes.php @@ -11,24 +11,27 @@ | */ -//User routes -Route::get('/users', 'UserController@getAll'); -Route::get('/users/{id}', 'UserController@getUser'); -Route::get('/users/{id}/servergroups/default', 'UserController@getDefaultServerGroup'); -Route::post('/users', 'UserController@store'); -Route::delete('/users/{id}', 'UserController@deleteUser'); -Route::get('/users/{id}/subscriptions', 'UserController@getSubscriptions'); -Route::put('/subscriptions/{subid}', 'UserController@updateSubscription'); - //Auth route Route::get('/auth', 'AuthenticationController@auth'); -//Pulse routes -Route::get('/pulses', 'PulseController@getAll'); -Route::post('/pulses', 'PulseController@store'); - Route::group(array('before' => 'superadmin.auth'), function() { + //User routes + Route::get('/users', 'UserController@getAll'); + Route::get('/users/{id}', 'UserController@getUser'); + Route::get('/users/{id}/servergroups/default', 'UserController@getDefaultServerGroup'); + Route::post('/users', 'UserController@store'); + Route::delete('/users/{id}', 'UserController@deleteUser'); + Route::get('/users/{id}/subscriptions', 'UserController@getSubscriptions'); + Route::put('/users/{id}', 'UserController@updateUser'); + Route::put('/users/password', 'UserController@changePassword'); + + + //Pulse routes + Route::get('/pulses', 'PulseController@getAll'); + Route::post('/pulses', 'PulseController@store'); + Route::delete('/pulses/{id}', 'PulseController@deletePulse'); + //Server routes Route::get('/servers/unassigned', 'ServerController@getUnassignedServers'); Route::get('/servers/assigned', 'ServerController@getAssignedServers'); @@ -49,6 +52,7 @@ Route::get('/servergroups', 'ServerGroupController@getAll'); Route::get('/servergroups/{id}', 'ServerGroupController@getServerGroup'); Route::post('/servergroups', 'ServerGroupController@store'); + Route::put('/servergroups/{id}', 'ServerGroupController@editServerGroup'); Route::delete('/servergroups/{id}', 'ServerGroupController@deleteServerGroup'); Route::get('/servergroups/{id}/servers', 'ServerGroupController@getServers'); @@ -60,5 +64,6 @@ //Subscription routes Route::get('/subscriptions', 'SubscriptionController@getAll'); Route::post('/subscriptions', 'SubscriptionController@store'); + Route::put('/subscriptions/{id}', 'SubscriptionController@updateSubscription'); Route::delete('/subscriptions/{id}', 'SubscriptionController@deleteSubscription'); }); \ No newline at end of file diff --git a/app/tests/ExampleTest.php b/app/tests/ExampleTest.php deleted file mode 100644 index ead53e0..0000000 --- a/app/tests/ExampleTest.php +++ /dev/null @@ -1,17 +0,0 @@ -client->request('GET', '/'); - - $this->assertTrue($this->client->getResponse()->isOk()); - } - -} \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index c42dc4f..149652a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,7 +2,7 @@ + + + + ./app/tests/ diff --git a/vpu/.gitignore b/vpu/.gitignore new file mode 100644 index 0000000..e934adf --- /dev/null +++ b/vpu/.gitignore @@ -0,0 +1 @@ +cache/