Skip to content

Commit

Permalink
C:/Users/cadence/AppData/Local/Atlassian/SourceTree/git_local/vmu
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonscott committed May 15, 2014
1 parent 82b177b commit 10acf8c
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 33 deletions.
10 changes: 10 additions & 0 deletions app/controllers/PrivilegeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
?>
9 changes: 9 additions & 0 deletions app/controllers/PulseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
?>
1 change: 0 additions & 1 deletion app/controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
27 changes: 27 additions & 0 deletions app/controllers/ServerGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -34,12 +39,34 @@ 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));
}

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);
}
}
?>
12 changes: 12 additions & 0 deletions app/controllers/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion app/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"'));
}
Expand Down
31 changes: 18 additions & 13 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');

Expand All @@ -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');
});
17 changes: 0 additions & 17 deletions app/tests/ExampleTest.php

This file was deleted.

6 changes: 5 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<!-- This is required for VPU to work correctly -->
<listeners>
<listener class="PHPUnit_Util_Log_JSON"></listener>
</listeners>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./app/tests/</directory>
Expand Down
1 change: 1 addition & 0 deletions vpu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cache/

0 comments on commit 10acf8c

Please sign in to comment.