Commit c16a8c15 authored by Gorodkov Denis's avatar Gorodkov Denis

commit

parent 9bfe1611
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* @file * @file
* Main file for hooks and custom functions. * Main file for hooks and custom functions.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Implements hook_cron(). * Implements hook_cron().
...@@ -68,3 +69,7 @@ function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_ ...@@ -68,3 +69,7 @@ function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_
$form["actions"]["reset"]["#access"] = true; $form["actions"]["reset"]["#access"] = true;
} }
} }
function mymodule_preprocess_page() {
}
...@@ -7,6 +7,8 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; ...@@ -7,6 +7,8 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Access; use Drupal\Core\Access;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* HTTP Basic authentication provider. * HTTP Basic authentication provider.
...@@ -20,6 +22,7 @@ class CustomAuth implements AuthenticationProviderInterface { ...@@ -20,6 +22,7 @@ class CustomAuth implements AuthenticationProviderInterface {
*/ */
protected $entityTypeManager; protected $entityTypeManager;
protected $x_crsf;
/** /**
* Constructs a HTTP basic authentication provider object. * Constructs a HTTP basic authentication provider object.
* *
...@@ -34,21 +37,15 @@ class CustomAuth implements AuthenticationProviderInterface { ...@@ -34,21 +37,15 @@ class CustomAuth implements AuthenticationProviderInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function applies(Request $request) { public function applies(Request $request) {
$x_crsf = $request->headers->get('X-CSRF-Token');
return !empty($x_crsf);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function authenticate(Request $request) { public function authenticate(Request $request) {
$x_crsf = $request->headers->get('X-CSRF-Token');
$valid = \Drupal::csrfToken()->validate($x_crsf);
$account = \Drupal\user\Entity\User::load(1);
return $account;
return NULL; #return NULL;
} }
} }
...@@ -90,6 +90,7 @@ class GetPeople extends ResourceBase { ...@@ -90,6 +90,7 @@ class GetPeople extends ResourceBase {
$node_homeworld = $node->field_homeworld->referencedEntities(); $node_homeworld = $node->field_homeworld->referencedEntities();
$node_homeworld = $node_homeworld[0]; $node_homeworld = $node_homeworld[0];
$cache->addCacheableDependency($node_homeworld);
$result['homeworld']['id'] = $node_homeworld->id(); $result['homeworld']['id'] = $node_homeworld->id();
$result['homeworld']['label'] = $node_homeworld->label(); $result['homeworld']['label'] = $node_homeworld->label();
...@@ -117,8 +118,6 @@ class GetPeople extends ResourceBase { ...@@ -117,8 +118,6 @@ class GetPeople extends ResourceBase {
} }
public function post($data) { public function post($data) {
$head = \Drupal::request()->headers->get('X-CSRF-Token');
#aNNEGy331SxMmOsiGbCyBGUfQz7EXl7iIcXS-Vh8vSQ
if ($data['swapi_id']) { if ($data['swapi_id']) {
if ($this->checkNode($data['swapi_id'])) { if ($this->checkNode($data['swapi_id'])) {
return new ResourceResponse(['Нода с таким swapi_id уже существует!']); return new ResourceResponse(['Нода с таким swapi_id уже существует!']);
...@@ -151,6 +150,7 @@ class GetPeople extends ResourceBase { ...@@ -151,6 +150,7 @@ class GetPeople extends ResourceBase {
public function fillReference($nameAttr, $node) { public function fillReference($nameAttr, $node) {
$field_name = "field_" . $nameAttr; $field_name = "field_" . $nameAttr;
$items = $node->$field_name->referencedEntities(); $items = $node->$field_name->referencedEntities();
if (!empty($items)) { if (!empty($items)) {
foreach ($items as $item) { foreach ($items as $item) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment