Commit b1353277 authored by Χάρης Παπαδόπουλος's avatar Χάρης Παπαδόπουλος
Browse files

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}",
...@@ -57,7 +60,7 @@ use Drupal\user\UserInterface; ...@@ -57,7 +60,7 @@ use Drupal\user\UserInterface;
* field_ui_base_route = "epal_users.settings" * field_ui_base_route = "epal_users.settings"
* ) * )
*/ */
class EpalUsers extends ContentEntityBase implements EpalUsersInterface { class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
use EntityChangedTrait; use EntityChangedTrait;
...@@ -146,11 +149,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -146,11 +149,11 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('status', $published ? TRUE : FALSE); $this->set('status', $published ? TRUE : FALSE);
return $this; return $this;
} }
/** /**
* get / set methods for aditional fields * get / set methods for aditional fields
*/ */
public function getDrupaluser_id() { public function getDrupaluser_id() {
return $this->get('drupaluser_id')->value; return $this->get('drupaluser_id')->value;
} }
...@@ -159,7 +162,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -159,7 +162,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('drupaluser_id', $name); $this->set('drupaluser_id', $name);
return $this; return $this;
} }
public function getTaxis_userid() { public function getTaxis_userid() {
return $this->get('taxis_userid')->value; return $this->get('taxis_userid')->value;
} }
...@@ -168,7 +171,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -168,7 +171,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('taxis_userid', $name); $this->set('taxis_userid', $name);
return $this; return $this;
} }
public function getTaxis_taxid() { public function getTaxis_taxid() {
return $this->get('taxis_taxid')->value; return $this->get('taxis_taxid')->value;
} }
...@@ -177,7 +180,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -177,7 +180,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('taxis_taxid', $name); $this->set('taxis_taxid', $name);
return $this; return $this;
} }
public function getSurname() { public function getSurname() {
return $this->get('surname')->value; return $this->get('surname')->value;
} }
...@@ -186,7 +189,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -186,7 +189,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('surname', $name); $this->set('surname', $name);
return $this; return $this;
} }
public function getFathername() { public function getFathername() {
return $this->get('fathername')->value; return $this->get('fathername')->value;
} }
...@@ -195,7 +198,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -195,7 +198,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('fathername', $name); $this->set('fathername', $name);
return $this; return $this;
} }
public function getMothername() { public function getMothername() {
return $this->get('mothername')->value; return $this->get('mothername')->value;
} }
...@@ -204,36 +207,8 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -204,36 +207,8 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('mothername', $name); $this->set('mothername', $name);
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;
} }
...@@ -242,7 +217,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -242,7 +217,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('accesstoken', $name); $this->set('accesstoken', $name);
return $this; return $this;
} }
public function getAuthtoken() { public function getAuthtoken() {
return $this->get('authtoken')->value; return $this->get('authtoken')->value;
} }
...@@ -251,7 +226,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -251,7 +226,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('authtoken', $name); $this->set('authtoken', $name);
return $this; return $this;
} }
public function getTimelogin() { public function getTimelogin() {
return $this->get('timelogin')->value; return $this->get('timelogin')->value;
} }
...@@ -260,7 +235,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -260,7 +235,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('timelogin', $name); $this->set('timelogin', $name);
return $this; return $this;
} }
public function getTimeregistration() { public function getTimeregistration() {
return $this->get('timeregistration')->value; return $this->get('timeregistration')->value;
} }
...@@ -269,7 +244,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -269,7 +244,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('timeregistration', $name); $this->set('timeregistration', $name);
return $this; return $this;
} }
public function getTimetokeninvalid() { public function getTimetokeninvalid() {
return $this->get('timetokeninvalid')->value; return $this->get('timetokeninvalid')->value;
} }
...@@ -278,7 +253,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -278,7 +253,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
$this->set('timetokeninvalid', $name); $this->set('timetokeninvalid', $name);
return $this; return $this;
} }
public function getUserip() { public function getUserip() {
return $this->get('userip')->value; return $this->get('userip')->value;
} }
...@@ -288,10 +263,38 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -288,10 +263,38 @@ 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}
*/ */
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type); $fields = parent::baseFieldDefinitions($entity_type);
...@@ -345,8 +348,8 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -345,8 +348,8 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['taxis_userid'] = BaseFieldDefinition::create('string') $fields['taxis_userid'] = BaseFieldDefinition::create('string')
->setLabel(t('User id χρήστη από taxis')) ->setLabel(t('User id χρήστη από taxis'))
->setDescription(t('Δώσε το user id του χρήστη από taxis.')) ->setDescription(t('Δώσε το user id του χρήστη από taxis.'))
...@@ -366,7 +369,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -366,7 +369,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['taxis_taxid'] = BaseFieldDefinition::create('string') $fields['taxis_taxid'] = BaseFieldDefinition::create('string')
->setLabel(t('Tax id χρήστη')) ->setLabel(t('Tax id χρήστη'))
->setDescription(t('Δώσε το tax id / ΑΦΜ του χρήστη.')) ->setDescription(t('Δώσε το tax id / ΑΦΜ του χρήστη.'))
...@@ -387,7 +390,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -387,7 +390,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string') $fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Όνομα χρήστη')) ->setLabel(t('Όνομα χρήστη'))
->setDescription(t('Δώσε το όνομα χρήστη')) ->setDescription(t('Δώσε το όνομα χρήστη'))
...@@ -408,7 +411,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -408,7 +411,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['surname'] = BaseFieldDefinition::create('string') $fields['surname'] = BaseFieldDefinition::create('string')
->setLabel(t('Επώνυμο χρήστη')) ->setLabel(t('Επώνυμο χρήστη'))
->setDescription(t('Δώσε το επώνυμο του χρήστη.')) ->setDescription(t('Δώσε το επώνυμο του χρήστη.'))
...@@ -429,7 +432,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -429,7 +432,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['fathername'] = BaseFieldDefinition::create('string') $fields['fathername'] = BaseFieldDefinition::create('string')
->setLabel(t('Όνομα πατέρα χρήστη')) ->setLabel(t('Όνομα πατέρα χρήστη'))
->setDescription(t('Δώσε το όνομα του πατέρα του χρήστη.')) ->setDescription(t('Δώσε το όνομα του πατέρα του χρήστη.'))
...@@ -449,7 +452,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -449,7 +452,7 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['mothername'] = BaseFieldDefinition::create('string') $fields['mothername'] = BaseFieldDefinition::create('string')
->setLabel(t('Όνομα μητέρας χρήστη')) ->setLabel(t('Όνομα μητέρας χρήστη'))
->setDescription(t('Δώσε το όνομα της μητέρας χρήστη.')) ->setDescription(t('Δώσε το όνομα της μητέρας χρήστη.'))
...@@ -469,74 +472,12 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -469,74 +472,12 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
/*
$fields['address'] = BaseFieldDefinition::create('string')
->setLabel(t('Διεύθυνση κατοικίας'))
->setDescription(t('Δώσε τη διεύθυνση κατοικίας.'))
->setSettings(array(
'max_length' => 50,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['addresstk'] = BaseFieldDefinition::create('string')
->setLabel(t('ΤΚ'))
->setDescription(t('Δώσε τον ΤΚ κατοικίας.'))
->setSettings(array(
'max_length' => 20,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['addressarea'] = BaseFieldDefinition::create('string')
->setLabel(t('Πόλη/Περιοχή διεύθυνσης κατοικίας'))
->setDescription(t('Δώσε την πόλη/περιοχή διεύθυνσης.'))
->setSettings(array(
'max_length' => 50,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
*/
$fields['accesstoken'] = BaseFieldDefinition::create('string') $fields['accesstoken'] = BaseFieldDefinition::create('string')
->setLabel(t('Access-Token από taxis')) ->setLabel(t('Access-Token από taxis'))
->setDescription(t('Access-Token από taxis.')) ->setDescription(t('Access-Token από taxis.'))
->setSettings(array( ->setSettings(array(
'max_length' => 300, 'max_length' => 1000,
'text_processing' => 0, 'text_processing' => 0,
)) ))
->setDefaultValue('') ->setDefaultValue('')
...@@ -551,12 +492,32 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface { ...@@ -551,12 +492,32 @@ class EpalUsers extends ContentEntityBase implements EpalUsersInterface {
)) ))
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE); ->setDisplayConfigurable('view', TRUE);
$fields['accesstoken_secret'] = BaseFieldDefinition::create('string')
->setLabel(t('Access-Token Secret από taxis'))
->setDescription(t('Access-Token Secret από taxis.'))
->setSettings(array(
'max_length' => 1000,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['authtoken'] = BaseFieldDefinition::create('string') $fields['authtoken'] = BaseFieldDefinition::create('string')
->setLabel(t('Authorization Token')) ->setLabel(t('Authorization Token'))
->setDescription(t('Authorization Token που δημιουργείται από την εφαρμογή.')) ->setDescription(t('Authorization Token που δημιουργείται από την εφαρμογή.'))
->setSettings(array( ->setSettings(array(
'max_length' => 300, 'max_length' => 1000,
'text_processing' => 0, 'text_processing' => 0,
))