예제 #1
0
 public function getOrCreateAction()
 {
     if (!Input::has('q')) {
         app()->abort(422, "Invalid user key");
     }
     $criteria = ["key_id" => Input::get('q')];
     $assertor = Assertor::where($criteria)->get()->first();
     $criteria["date"] = new Carbon();
     if (!$assertor) {
         $assertor = Assertor::create($criteria);
     }
     return $this->response(Assertor::find($assertor->id));
 }
예제 #2
0
 public function validateInput(array $values)
 {
     Validator::extend("check_context", function ($atts, $value, $parameters) use($values) {
         preg_match("~^.+/([a-zA-Z]+).jsonld\$~", $value, $matches);
         if (count($matches) == 0) {
             return false;
         }
         $model = ucfirst(str_singular($matches[1]));
         //0 = entire string
         $allowed_models = ["Webpage", "Evaluation", "Assertion", "Assertor"];
         $class = "App\\Models\\" . $model;
         if (!class_exists($class) || !in_array($model, $allowed_models)) {
             return false;
         }
         /** @var LDModel $instance */
         $instance = new $class();
         if (!method_exists($instance, "getContext")) {
             return false;
         }
         return true;
     });
     Validator::extend('private_key', function ($attr, $value, $parameters) use($values) {
         if (!isset($parameters[0])) {
             return false;
         }
         $ldid = array_get($values, $parameters[0]);
         $id = $this->getIdFromLdId($ldid);
         if (!$id) {
             return false;
         }
         $result = Assertor::where(['id' => $id, 'key_id' => $value])->first();
         return $result != null;
     });
     Validator::extend('ldid_exists', function ($attr, $value, $parameters) {
         preg_match("~^id:([a-z]+)/([0-9]+)\$~", $value, $matches);
         if (count($matches) == 0) {
             preg_match("~^utt:([a-z]+)/([0-9]+)\$~", $value, $matches);
         }
         if (count($matches) == 0) {
             preg_match("~^" . url() . "/([a-z]+)/([0-9]+)\$~", $value, $matches);
         }
         if (count($matches) != 3) {
             return false;
         }
         $id = $matches[2];
         $model = "App\\Models\\" . str_singular(ucfirst($matches[1]));
         if (!class_exists($model)) {
             return false;
         }
         $result = $model::where(['id' => $id])->first();
         return $result != null;
     });
     Validator::extend('ldid_model', function ($attr, $value, $parameters) {
         preg_match("~^id:([a-z]+)/([0-9]+)\$~", $value, $matches);
         if (count($matches) == 0) {
             preg_match("~^utt:([a-z]+)/([0-9]+)\$~", $value, $matches);
         }
         if (count($matches) == 0) {
             preg_match("~^" . url() . "/([a-z]+)/([0-9]+)\$~", $value, $matches);
         }
         if (count($matches) != 3) {
             return false;
         }
         //limit results to specific model
         if (!isset($parameters[0])) {
             return false;
         }
         $invalidModel = $matches[1] != $parameters[0];
         if ($invalidModel) {
             return false;
         }
         return true;
     });
     return Validator::make($values, $this->getValidationRules());
 }