public function getUser($id)
 {
     $user = User::find($id);
     if (is_null($user)) {
         return Error::make("Invalid User");
     }
     return Error::success("User Details", $user->toArray());
 }
 public function send_activation_mail_api($id)
 {
     $user = User::find($id);
     if (is_null($user)) {
         return Error::make("Invalid User");
     }
     return $this->send_activation_mail_helper($user);
 }
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
    if (Session::token() != Input::get('_token')) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
App::missing(function ($exception) {
    return Error::make(404, 404);
});
Route::filter('API', function () {
    if (Input::has('key')) {
        if (Input::get('key') != "teninchlong") {
            return Error::make(401, 401);
        }
    } else {
        return Error::make(1, 2);
    }
});
Route::filter('afterAPI', function ($request, $response) {
    $response->header('Content-Type', 'application/json');
    return $response;
});
Example #4
0
 public function dispatchController($match)
 {
     $controller = @explode('@', $match['target'])[0];
     $method = @explode('@', $match['target'])[1];
     if (class_exists($controller)) {
         $dispatchedController = new $controller();
         if (method_exists($dispatchedController, $method)) {
             if (!empty($match['params'])) {
                 $params = json_decode(json_encode($match['params']));
                 return $dispatchedController->{$method}($params);
             }
             return $dispatchedController->{$method}();
         }
         return Error::make('Route does not exist');
     }
     return Error::make('Route does not exist!');
 }
 public function add_result()
 {
     $requirements = ['exp_id', 'user_id', 'data'];
     $check = self::check_requirements($requirements);
     if ($check) {
         return Error::make(0, 100, $check);
     }
     $experiment = Experiment::where('exp_id', '=', Input::get('exp_id'))->first();
     if (is_null($experiment)) {
         return Error::make(1, 10);
     }
     $user = User::where('user_id', '=', Input::get('user_id'))->first();
     if (is_null($user)) {
         return Error::make(1, 1);
     }
     if (Input::has('result_id')) {
         $res = Result::where('result_id', '=', Input::get('result_id'))->first();
         if (intval(Input::get('exp_id')) != intval($res->exp_id)) {
             return Error::make(1, 11);
         }
         if (intval(Input::get('user_id')) != intval($res->user_id)) {
             return Error::make(1, 12);
         }
     }
     $columns = json_decode($experiment->specifications, true)["columns"];
     $results = json_decode(Input::get('data'), true);
     foreach ($results as $reading) {
         foreach ($columns as $column) {
             if (array_key_exists($column["title"], $reading)) {
                 if (!is_null($column["subcolumns"]) && sizeof($column["subcolumns"]) > 0) {
                     foreach ($column["subcolumns"] as $subcolumn) {
                         if (!array_key_exists($subcolumn["title"], $reading[$column["title"]])) {
                             return Error::make(101, 101, "Column " . $column["title"] . " has missing subcolumn " . $subcolumn["title"]);
                         }
                     }
                 }
             } else {
                 return Error::make(101, 101, "Missing column " . $column["title"]);
             }
         }
     }
     if (Input::has('result_id')) {
         try {
             Result::where('result_id', '=', intval(Input::get('result_id')))->update(array('data' => json_encode($results)));
             return Error::success("Results successfully updated", array('result_id' => intval(Input::get('result_id'))));
         } catch (Exception $e) {
             return Error::make(101, 101, $e->getMessage());
         }
     } else {
         $res = new Result();
         $res->data = json_encode($results);
         $res->user_id = intval(Input::get('user_id'));
         $res->exp_id = intval(Input::get('exp_id'));
         try {
             $res->save();
             return Error::success("Result successfully added!", array('result_id' => $res->id));
         } catch (Exception $e) {
             return Error::make(101, 101, $e->getMessage());
         }
     }
 }
 public function edit_pic_api($id)
 {
     $user = User::find($id);
     if (is_null($user)) {
         return Error::make("Invalid User");
     }
     if ($user->type != "driver") {
         return Error::make("User is not Driver");
     }
     $this->edit_pic_helper($user);
     $data = Driver::find($id)->toArray();
     return Error::success("Successfully Uploaded pictures", $data);
 }
    });
});
Route::group(array('before' => 'guest'), function () {
    Route::get('login', array('uses' => 'UserController@show_login'));
    Route::post('login', array('as' => 'login', 'uses' => 'UserController@login'));
    Route::post('register', array('as' => 'register', 'uses' => 'UserController@register'));
});
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is all the routes which will help the laravel application to run.
|
*/
Route::group(array("prefix" => "api"), function () {
    Route::post('login', array('uses' => 'UserController@login'));
    Route::post('register', array('uses' => 'UserController@register'));
    Route::get('user/{id}', array('uses' => 'APIController@getUser'));
    Route::get('customer/{id}', array('uses' => 'APIController@getCustomer'));
    Route::get('driver/{id}', array('uses' => 'APIController@getDriver'));
    Route::get('business/{id}', array('uses' => 'APIController@getBusiness'));
    Route::post('edit/{id}', array('uses' => 'HomeController@api_edit'));
    Route::post('edit_pic/{id}', array('uses' => 'HomeController@edit_pic_api'));
    Route::get('activation/{id}', array('uses' => 'UserController@send_activation_mail_api'));
    Route::any('{e1?}/{e2?}/{e3?}/{e4?}/{e5?}/{e6?}/{e7?}/{e8?}', function () {
        return Error::make("Invalid URL. Page don't exists");
    });
});
Route::controller('password', 'RemindersController');
Route::get('activate/{id}', array('uses' => 'UserController@activate'));