Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Gorodkov Denis
Project
Commits
c16a8c15
Commit
c16a8c15
authored
May 18, 2022
by
Gorodkov Denis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
9bfe1611
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
10 deletions
+12
-10
mymodule.module
app/docroot/modules/custom/mymodule/mymodule.module
+5
-0
CustomAuth.php
...ustom/mymodule/src/Authentication/Provider/CustomAuth.php
+5
-8
GetPeople.php
...es/custom/mymodule/src/Plugin/rest/resource/GetPeople.php
+2
-2
No files found.
app/docroot/modules/custom/mymodule/mymodule.module
View file @
c16a8c15
...
...
@@ -3,6 +3,7 @@
* @file
* Main file for hooks and custom functions.
*/
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
/**
* Implements hook_cron().
...
...
@@ -68,3 +69,7 @@ function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_
$form
[
"actions"
][
"reset"
][
"#access"
]
=
true
;
}
}
function
mymodule_preprocess_page
()
{
}
app/docroot/modules/custom/mymodule/src/Authentication/Provider/CustomAuth.php
View file @
c16a8c15
...
...
@@ -7,6 +7,8 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use
Drupal\Core\Session\AccountInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Drupal\Core\Access
;
use
Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
/**
* HTTP Basic authentication provider.
...
...
@@ -20,6 +22,7 @@ class CustomAuth implements AuthenticationProviderInterface {
*/
protected
$entityTypeManager
;
protected
$x_crsf
;
/**
* Constructs a HTTP basic authentication provider object.
*
...
...
@@ -34,21 +37,15 @@ class CustomAuth implements AuthenticationProviderInterface {
* {@inheritdoc}
*/
public
function
applies
(
Request
$request
)
{
$x_crsf
=
$request
->
headers
->
get
(
'X-CSRF-Token'
);
return
!
empty
(
$x_crsf
);
}
/**
* {@inheritdoc}
*/
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;
}
}
app/docroot/modules/custom/mymodule/src/Plugin/rest/resource/GetPeople.php
View file @
c16a8c15
...
...
@@ -90,6 +90,7 @@ class GetPeople extends ResourceBase {
$node_homeworld
=
$node
->
field_homeworld
->
referencedEntities
();
$node_homeworld
=
$node_homeworld
[
0
];
$cache
->
addCacheableDependency
(
$node_homeworld
);
$result
[
'homeworld'
][
'id'
]
=
$node_homeworld
->
id
();
$result
[
'homeworld'
][
'label'
]
=
$node_homeworld
->
label
();
...
...
@@ -117,8 +118,6 @@ class GetPeople extends ResourceBase {
}
public
function
post
(
$data
)
{
$head
=
\Drupal
::
request
()
->
headers
->
get
(
'X-CSRF-Token'
);
#aNNEGy331SxMmOsiGbCyBGUfQz7EXl7iIcXS-Vh8vSQ
if
(
$data
[
'swapi_id'
])
{
if
(
$this
->
checkNode
(
$data
[
'swapi_id'
]))
{
return
new
ResourceResponse
([
'Нода с таким swapi_id уже существует!'
]);
...
...
@@ -151,6 +150,7 @@ class GetPeople extends ResourceBase {
public
function
fillReference
(
$nameAttr
,
$node
)
{
$field_name
=
"field_"
.
$nameAttr
;
$items
=
$node
->
$field_name
->
referencedEntities
();
if
(
!
empty
(
$items
))
{
foreach
(
$items
as
$item
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment