public function postRegistration()
 {
     if ($this->isPostRequest()) {
         $validator = $this->getRegistrationValidator();
         if ($validator->passes()) {
             $credentials = $this->getRegistrationCredentials();
             $user = new User();
             //Take care, only mass assignable columns are fillable, check User model
             $user->fill($credentials);
             if ($user->save()) {
                 $status = 201;
                 $data = array('status' => $status, 'success' => true, 'message' => 'User sucessfully created');
                 $response = MyResponse::json($data, $status);
                 return $response;
             } else {
                 $status = 200;
                 $data = array('status' => $status, 'success' => false, 'message' => 'User unsucessfully updated');
                 $response = MyResponse::json($data, $status);
                 return $response;
             }
         } else {
             $status = 200;
             $data = array('status' => $status, 'success' => false, 'message' => $validator->messages()->toArray());
             $response = MyResponse::json($data, $status);
             return $response;
         }
     } else {
     }
 }
 public function delete($id)
 {
     // If Eloquent Object returned (rather than null) return the response for deletion
     if ($id != null) {
         $response = $this->repository->destroy($id);
         return $response;
     } else {
         $status = 404;
         $data = array('status' => $status, 'success' => false, 'message' => 'Event not found');
         $response = MyResponse::json($data, $status);
         return $response;
     }
 }
Example #3
0
 public function getBy($id)
 {
     // If entity variable is numeric, assume ID
     if (is_numeric($id)) {
         // Get Eloquent model based on ID
         $modelClassInstance = $this->repository->findById($id);
     } else {
         // Since not numeric, lets try get the Eloquent model based on Name
         $modelClassInstance = $this->repository->findBySlug($id);
     }
     // If Eloquent model returned (rather than null) return the name of the model
     if ($modelClassInstance != null) {
         $response = $modelClassInstance->name;
         return $response;
     }
     $status = 404;
     $data = array('status' => $status, 'success' => false, 'message' => 'Event not found');
     $response = MyResponse::json($data, $status);
     return $response;
 }
 public function deleteWhere($column, $value)
 {
     $related = $this->modelClassInstance->where($column, '=', $value);
     if ($related->delete()) {
         $status = 200;
         $data = array('status' => $status, 'success' => true, 'message' => 'Event sucessfully deleted');
         $response = MyResponse::json($data, $status);
         return $response;
     } else {
         $status = 200;
         $data = array('status' => $status, 'success' => false, 'message' => 'Event unsucessfully deleted');
         $response = MyResponse::json($data, $status);
         return $response;
     }
 }
 public function create(array $input)
 {
     $eventData = $input['event'];
     $sponsorData = $input['sponsors'];
     $categoryData = $input['category'];
     $eventValidator = new EventValidator(App::make('validator'));
     $eventValidator->with($eventData);
     if ($eventValidator->passes()) {
         // Start transaction!
         DB::beginTransaction();
         //Create the new event record and return the model
         $eventModel = $this->repository->create($eventData);
         //$event = parent::create($eventData);
         $sponsorValidator = new SponsorValidator(App::make('validator'));
         foreach ($sponsorData as $sponsor) {
             $sponsorValidator->with($sponsor);
             if ($sponsorValidator->passes()) {
                 //Create the new sponsor records and associate them with the event record
                 $sponsorModel = $this->sponsorRepository->create($sponsor);
                 $eventModel->sponsors()->save($sponsorModel);
             } else {
                 $status = 200;
                 $data = array('status' => $status, 'success' => false, 'message' => $sponsorValidator->errors()->toArray());
                 $response = MyResponse::json($data, $status);
                 //Roll back transactions
                 DB::rollback();
                 return $response;
             }
         }
         $categoryValidator = new CategoryValidator(App::make('validator'));
         $categoryValidator->with($categoryData);
         if ($categoryValidator->passes()) {
             //Create the category record and associate it with the event record
             $categoryModel = $this->categoryRepository->create($categoryData);
             $categoryModel->events()->save($eventModel);
         } else {
             $status = 200;
             $data = array('status' => $status, 'success' => false, 'message' => $categoryValidator->errors()->toArray());
             $response = MyResponse::json($data, $status);
             //Roll back transactions
             DB::rollback();
             return $response;
         }
     } else {
         $status = 200;
         $data = array('status' => $status, 'success' => false, 'message' => $eventValidator->errors()->toArray());
         $response = MyResponse::json($data, $status);
         //Roll back transactions
         DB::rollback();
         return $response;
     }
     $status = 201;
     $data = array('status' => $status, 'success' => true, 'message' => 'Event successfully created');
     $response = MyResponse::json($data, $status);
     // If we reach here, then data is valid and working. Commit the queries!
     DB::commit();
     return $response;
 }
Example #6
0
|
*/
Route::filter('csrf', function () {
    if (Session::token() != Input::get('_token')) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
/* Your choice for authentication mechanisms will greatly affect the logic in your filters. 
  |  I’ve opted not to go into great detail with regards to how the tokens are generated and users are stored. 
  |  Ultimately; you can check for token headers, username/password combos or even IP addresses.
  |
  | What’s important to note here is that we check for this thing (tokens in this case) and if they do not
  |  match those stored in user records, we abort the application execution cycle with a 400 error (and message).
  |
  |  You can find out more about filters at: http://laravel.com/docs/routing#route-filters.
 */
/* Get the users api_token from the dtabase and compare it to the api_token
  |  alias X-Api-Token recieved from the headers . Only matching users will
  |  be authenticated with the api
  */
Route::filter('api.auth', function () {
    //Get database user
    if (Auth::check()) {
        $api_token = Auth::user()->api_token;
    }
    if (Request::header('X-Api-Token') !== $api_token) {
        $status = 400;
        $data = array('status' => $status, 'success' => false, 'message' => 'Invalid Api_Token, Unauthorised');
        return MyResponse::json($data, $status);
    }
});