Пример #1
0
 /**
  * Validates a AJAX validation request and returns a JsonResponse
  *
  * @param \Illuminate\Http\Request $request
  * @param array                    $rules
  * @param array                    $messages
  * @return \Illuminate\Http\JsonResponse
  */
 public function validate(Request $request, array $rules = [], array $messages = [])
 {
     $rules = $this->getRules()->merge($rules)->toArray();
     if ($singleField = $request->has($this->singleFieldReferenceKey)) {
         $fields = [$request->get($this->singleFieldReferenceKey)];
     } else {
         $fields = Arr::keys($this->getRules()->toArray());
     }
     $data = $request->only($fields);
     $rules = Arr::only($rules, $fields);
     $validator = $this->validationFactory->make($data, $rules, $messages);
     if ($validator->fails()) {
         $messages = $validator->getMessageBag();
         if ($singleField) {
             $fieldName = $request->get($this->singleFieldReferenceKey);
             return $this->jsonResponse([$fieldName => $messages->first($fieldName)]);
         } else {
             $response = [];
             foreach ($messages->keys() as $key) {
                 $response[$key] = $messages->first($key);
             }
             return $this->jsonResponse($response);
         }
     } else {
         return $this->jsonResponse('true');
     }
 }
Пример #2
0
 public function bitbucket()
 {
     $this->codex->log('info', 'codex.hooks.git.webhook.call', ['remote' => 'bitbucket']);
     $headers = Arr::only(request()->headers->all(), ['x-request-uuid', 'x-event-key', 'user-agent', 'x-hook-uuid']);
     $data = array_dot(request()->all());
     $valid = $headers['user-agent'][0] === 'Bitbucket-Webhooks/2.0' && $headers['x-event-key'][0] === 'repo:push' && isset($data['repository.name']);
     if (!$valid) {
         return response('Invalid headzors', 500);
     }
     return $this->applyToGitProjects('bitbucket', function () use($data) {
         return $data['repository.name'];
     });
 }