Merge branch 'login_procedure' into 'develop'

Login procedure

See merge request !24
parents a9417f9a 1321689f
...@@ -4,6 +4,14 @@ epal_is_logged_in: ...@@ -4,6 +4,14 @@ epal_is_logged_in:
_controller: '\Drupal\epal\Controller\Login::helloWorld' _controller: '\Drupal\epal\Controller\Login::helloWorld'
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
epal_entityapi_test:
path: '/epal/entityapi/test'
options:
_auth: [ 'basic_auth' ]
requirements:
_user_is_logged_in: 'TRUE'
defaults:
_controller: '\Drupal\epal\Controller\Login::testQuery'
epal_auth_test: epal_auth_test:
path: 'epal/auth/test' path: 'epal/auth/test'
options: options:
......
...@@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; ...@@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityFieldManagerInterface;
/** /**
* Controller routines for page example routes. * Controller routines for page example routes.
...@@ -18,18 +19,22 @@ use Drupal\Core\Controller\ControllerBase; ...@@ -18,18 +19,22 @@ use Drupal\Core\Controller\ControllerBase;
class Login extends ControllerBase { class Login extends ControllerBase {
protected $query_factory; protected $query_factory;
protected $entityTypeManager;
protected $entityFieldManager;
public function __construct(EntityTypeManagerInterface $entityTypeManager, QueryFactory $query_factory) { public function __construct(EntityTypeManagerInterface $entityTypeManager, QueryFactory $query_factory, EntityFieldManagerInterface $entityFieldManager) {
// public function __construct(QueryFactory $query_factory) { // public function __construct(QueryFactory $query_factory) {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entityTypeManager;
$this->query_factory = $query_factory; $this->query_factory = $query_factory;
$this->entityFieldManager = $entityFieldManager;
} }
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('entity.manager'), $container->get('entity_type.manager'),
$container->get('entity.query') $container->get('entity.query'),
$container->get('entity_field.manager')
); );
} }
...@@ -67,7 +72,57 @@ public function helloWorld() { ...@@ -67,7 +72,57 @@ public function helloWorld() {
} }
return array_values($arrayToReturn); return array_values($arrayToReturn);
}
public function object_2_array($result) {
$array = array();
foreach ($result as $key=>$value)
{
if (is_object($value))
{
$array[$key]=$this->object_2_array($value);
}
elseif (is_array($value))
{
$array[$key]=$this->object_2_array($value);
}
else
{
$array[$key]=$value;
}
} }
return $array;
}
public function testQuery() {
$query = $this->query_factory->get('epal_users');
// ->condition('status', 1);
$scids = $query->execute();
$epalUsers_storage = $this->entityTypeManager->getStorage('epal_users');
$epalUsers = $epalUsers_storage->loadMultiple($scids);
$arrayToReturn = array();
$j=0;
foreach ($epalUsers as $epalUser) {
// print_r($epalUser);
// $arrayToReturn[$j] = implode(",", $this->object_2_array($epalUser->id) );
$arrayToReturn[$j] = $epalUser->user_id->target_id;
$j++;
/* foreach ($epalUser->name as $delta => $item) {
$arrayToReturn[$delta] = $item->value;
} */
/* array_push($arrayToReturn,
$epalUser->surname->getValue()); */
}
// return array_values($arrayToReturn);
$response = new JsonResponse($arrayToReturn);
return $response;
}
public function basicQuery() { public function basicQuery() {
return [ return [
......
...@@ -46,6 +46,9 @@ use Drupal\user\UserInterface; ...@@ -46,6 +46,9 @@ use Drupal\user\UserInterface;
* "name" = "name", * "name" = "name",
* "surname" = "surname", * "surname" = "surname",
* "taxis_taxid" = "taxis_taxid", * "taxis_taxid" = "taxis_taxid",
* "requesttoken" = "requesttoken",
* "accesstoken" = "accesstoken",
* "authtoken" = "authtoken",
* }, * },
* links = { * links = {
* "canonical" = "/admin/structure/epal_users/{epal_users}", * "canonical" = "/admin/structure/epal_users/{epal_users}",
...@@ -205,34 +208,6 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -205,34 +208,6 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
return $this; return $this;
} }
/*
public function getAddress() {
return $this->get('address')->value;
}
public function setAddress($name) {
$this->set('address', $name);
return $this;
}
public function getAddresstk() {
return $this->get('addresstk')->value;
}
public function setAddresstk($name) {
$this->set('addresstk', $name);
return $this;
}
public function getAddressarea() {
return $this->get('addressarea')->value;
}
public function setAddressarea($name) {
$this->set('addressarea', $name);
return $this;
}
*/
public function getAccesstoken() { public function getAccesstoken() {
return $this->get('accesstoken')->value; return $this->get('accesstoken')->value;
...@@ -288,6 +263,34 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -288,6 +263,34 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
return $this; return $this;
} }
public function getRequestToken() {
return $this->get('requesttoken')->value;
}
public function setRequestToken($requestToken) {
$this->set('requesttoken', $requestToken);
return $this;
}
public function getRequestTokenSecret() {
return $this->get('requesttokensecret')->value;
}
public function setRequestTokenSecret($requestTokenSecret) {
$this->set('requesttokensecret', $requestTokenSecret);
return $this;
}
public function getAccessTokenSecret() {
return $this->get('accesstokensecret')->value;
}
public function setAccessTokenSecret($accessTokenSecret) {
$this->set('accesstokensecret', $accessTokenSecret);
return $this;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -470,12 +473,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -470,12 +473,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
/* $fields['accesstoken'] = BaseFieldDefinition::create('string')
$fields['address'] = BaseFieldDefinition::create('string') ->setLabel(t('Access-Token από taxis'))
->setLabel(t('Διεύθυνση κατοικίας')) ->setDescription(t('Access-Token από taxis.'))
->setDescription(t('Δώσε τη διεύθυνση κατοικίας.'))
->setSettings(array( ->setSettings(array(
'max_length' => 50, 'max_length' => 1000,
'text_processing' => 0, 'text_processing' => 0,
)) ))
->setDefaultValue('') ->setDefaultValue('')
...@@ -491,11 +493,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -491,11 +493,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['addresstk'] = BaseFieldDefinition::create('string') $fields['accesstoken_secret'] = BaseFieldDefinition::create('string')
->setLabel(t('ΤΚ')) ->setLabel(t('Access-Token Secret από taxis'))
->setDescription(t('Δώσε τον ΤΚ κατοικίας.')) ->setDescription(t('Access-Token Secret από taxis.'))
->setSettings(array( ->setSettings(array(
'max_length' => 20, 'max_length' => 1000,
'text_processing' => 0, 'text_processing' => 0,
)) ))
->setDefaultValue('') ->setDefaultValue('')
...@@ -511,11 +513,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -511,11 +513,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['addressarea'] = BaseFieldDefinition::create('string') $fields['authtoken'] = BaseFieldDefinition::create('string')
->setLabel(t('Πόλη/Περιοχή διεύθυνσης κατοικίας')) ->setLabel(t('Authorization Token'))
->setDescription(t('Δώσε την πόλη/περιοχή διεύθυνσης.')) ->setDescription(t('Authorization Token που δημιουργείται από την εφαρμογή.'))
->setSettings(array( ->setSettings(array(
'max_length' => 50, 'max_length' => 1000,
'text_processing' => 0, 'text_processing' => 0,
)) ))
->setDefaultValue('') ->setDefaultValue('')
...@@ -530,13 +532,12 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -530,13 +532,12 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
*/
$fields['accesstoken'] = BaseFieldDefinition::create('string') $fields['requesttoken'] = BaseFieldDefinition::create('string')
->setLabel(t('Access-Token από taxis')) ->setLabel(t('Oauth Request Token'))
->setDescription(t('Access-Token από taxis.')) ->setDescription(t('Request Token received by service provider.'))
->setSettings(array( ->setSettings(array(
'max_length' => 300, 'max_length' => 1000,
'text_processing' => 0, 'text_processing' => 0,
)) ))
->setDefaultValue('') ->setDefaultValue('')
...@@ -552,11 +553,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -552,11 +553,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['authtoken'] = BaseFieldDefinition::create('string') $fields['requesttoken_secret'] = BaseFieldDefinition::create('string')
->setLabel(t('Authorization Token')) ->setLabel(t('Oauth Request Token Secret'))
->setDescription(t('Authorization Token που δημιουργείται από την εφαρμογή.')) ->setDescription(t('Request Token Secret received by service provider.'))
->setSettings(array( ->setSettings(array(
'max_length' => 300, 'max_length' => 1000,
'text_processing' => 0, 'text_processing' => 0,
)) ))
->setDefaultValue('') ->setDefaultValue('')
...@@ -592,9 +593,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -592,9 +593,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
->setDisplayOptions('view', array( ->setDisplayOptions('view', array(
'label' => 'above', 'label' => 'above',
'type' => 'integer', 'type' => 'integer',
'weight' => -4,
)) ))
->setDisplayOptions('form', array( ->setDisplayOptions('form', array(
'type' => 'integer', 'type' => 'integer',
'weight' => -4,
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
......
langcode: en uuid: 761245c9-c12c-4bad-baae-b6659bdcd614
langcode: el
status: true status: true
dependencies: dependencies:
config:
- user.role.administrator
- user.role.applicant
- user.role.authenticated
module: module:
- basic_auth
- epalreadydata - epalreadydata
- rest - rest
- serialization - serialization
- user
_core:
default_config_hash: x1x9jIC8SmXp0wDILOEs5_1lxH47q3VCokKYxEu4U-8
id: coursefields id: coursefields
label: coursefields label: coursefields
module: views module: views
...@@ -21,8 +30,12 @@ display: ...@@ -21,8 +30,12 @@ display:
position: 0 position: 0
display_options: display_options:
access: access:
type: none type: role
options: { } options:
role:
authenticated: authenticated
administrator: administrator
applicant: applicant
cache: cache:
type: tag type: tag
options: { } options: { }
...@@ -217,6 +230,7 @@ display: ...@@ -217,6 +230,7 @@ display:
- 'languages:language_interface' - 'languages:language_interface'
- request_format - request_format
- url.query_args - url.query_args
- user.roles
tags: { } tags: { }
rest_export_1: rest_export_1:
display_plugin: rest_export display_plugin: rest_export
...@@ -246,10 +260,13 @@ display: ...@@ -246,10 +260,13 @@ display:
name: name:
alias: '' alias: ''
raw_output: true raw_output: true
auth:
- basic_auth
cache_metadata: cache_metadata:
max-age: -1 max-age: -1
contexts: contexts:
- 'languages:language_content' - 'languages:language_content'
- 'languages:language_interface' - 'languages:language_interface'
- request_format - request_format
- user.roles
tags: { } tags: { }
langcode: en uuid: de8212d8-4c94-4132-bb3d-8761c9746d82
langcode: el
status: true status: true
dependencies: dependencies:
config:
- user.role.administrator
- user.role.applicant
- user.role.authenticated
module: module:
- basic_auth
- epalreadydata - epalreadydata
- hal - hal
- rest - rest
- serialization - serialization
- user
_core:
default_config_hash: hfXJdCjR9GthaynAMVZvAHOKY-_kuI4Qz9NyNFMYnbE
id: coursesectorlist id: coursesectorlist
label: courseSectorList label: courseSectorList
module: views module: views
...@@ -22,8 +31,12 @@ display: ...@@ -22,8 +31,12 @@ display:
position: 0 position: 0
display_options: display_options:
access: access:
type: none type: role
options: { } options:
role:
authenticated: authenticated
administrator: administrator
applicant: applicant
cache: cache:
type: tag type: tag
options: { } options: { }
...@@ -380,6 +393,7 @@ display: ...@@ -380,6 +393,7 @@ display:
- 'languages:language_content' - 'languages:language_content'
- 'languages:language_interface' - 'languages:language_interface'
- url.query_args - url.query_args
- user.roles
tags: { } tags: { }
rest_export_1: rest_export_1:
display_plugin: rest_export display_plugin: rest_export
...@@ -417,10 +431,13 @@ display: ...@@ -417,10 +431,13 @@ display:
options: options:
items_per_page: 0 items_per_page: 0
offset: 0 offset: 0
auth:
- basic_auth
cache_metadata: cache_metadata:
max-age: -1 max-age: -1
contexts: contexts:
- 'languages:language_content' - 'languages:language_content'
- 'languages:language_interface' - 'languages:language_interface'
- request_format - request_format
- user.roles
tags: { } tags: { }
langcode: en uuid: 1cff8f27-9685-419a-a482-2005548b23f4
langcode: el
status: true status: true
dependencies: dependencies:
config:
- user.role.administrator
- user.role.applicant
- user.role.authenticated
module: module:
- basic_auth
- epalreadydata - epalreadydata
- hal - hal
- rest - rest
- serialization - serialization
- user
_core:
default_config_hash: X-Hp7xhmfNgEXwpE0VYHvI6BIYiDJDxGhGXtNwpeiCs
id: coursesperschool id: coursesperschool
label: coursesperschool label: coursesperschool
module: views module: views
...@@ -22,8 +31,12 @@ display: ...@@ -22,8 +31,12 @@ display:
position: 0 position: 0
display_options: display_options:
access: access:
type: none type: role
options: { } options:
role:
authenticated: authenticated
administrator: administrator
applicant: applicant
cache: cache:
type: tag type: tag
options: { } options: { }
...@@ -457,6 +470,7 @@ display: ...@@ -457,6 +470,7 @@ display:
- 'languages:language_interface' - 'languages:language_interface'
- url - url
- url.query_args - url.query_args
- user.roles
tags: { } tags: { }
page_1: page_1:
display_plugin: page display_plugin: page
...@@ -466,6 +480,7 @@ display: ...@@ -466,6 +480,7 @@ display:
display_options: display_options:
display_extenders: { } display_extenders: { }
path: coursesperschool path: coursesperschool
enabled: false
cache_metadata: cache_metadata:
max-age: 0 max-age: 0
contexts: contexts:
...@@ -473,6 +488,7 @@ display: ...@@ -473,6 +488,7 @@ display:
- 'languages:language_interface' - 'languages:language_interface'
- url - url
- url.query_args - url.query_args
- user.roles
tags: { } tags: { }
rest_export_1: rest_export_1:
display_plugin: rest_export display_plugin: rest_export
...@@ -516,6 +532,8 @@ display: ...@@ -516,6 +532,8 @@ display:
options: options:
items_per_page: 0 items_per_page: 0
offset: 0 offset: 0
auth:
- basic_auth