Commit 1a4eb225 authored by Γιάννης Δαγκουλής's avatar Γιάννης Δαγκουλής

Merge branch 'AngularTaxisAuthentication' into 'AngularTaxisAuthentication'

Angular taxis authentication

See merge request !3
parents 8bd7f078 76b32fde
{
"name": "drupal/iek",
"type": "drupal-module",
"description": "IEK Registration",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/iek",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/iek",
"source": "http://cgit.drupalcode.org/iek"
},
"require": { }
}
name: iek
type: module
description: IEK user table
core: 8.x
package: IEK
dependencies:
entity.iek_users.add_form:
route_name: entity.iek_users.add_form
title: 'Add Iek users'
appears_on:
- entity.iek_users.collection
# Iek users menu items definition
entity.iek_users.collection:
title: 'Iek users list'
route_name: entity.iek_users.collection
description: 'List Iek users entities'
parent: system.admin_structure
weight: 100
iek_users.admin.structure.settings:
title: Iek users settings
description: 'Configure Iek users entities'
route_name: iek_users.settings
parent: system.admin_structure
# Iek users routing definition
iek_users.settings_tab:
route_name: iek_users.settings
title: 'Settings'
base_route: iek_users.settings
entity.iek_users.canonical:
route_name: entity.iek_users.canonical
base_route: entity.iek_users.canonical
title: 'View'
entity.iek_users.edit_form:
route_name: entity.iek_users.edit_form
base_route: entity.iek_users.canonical
title: 'Edit'
entity.iek_users.delete_form:
route_name: entity.iek_users.delete_form
base_route: entity.iek_users.canonical
title: Delete
weight: 10
<?php
/**
* @file
* Contains iek.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function iek_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the iek module.
case 'help.page.iek':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('IEK Registration') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function iek_theme() {
return [
'iek' => [
'template' => 'iek',
'render element' => 'children',
],
];
}
add iek users entities:
title: 'Create new Iek users entities'
administer iek users entities:
title: 'Administer Iek users entities'
description: 'Allow to access the administration form to configure Iek users entities.'
restrict access: true
delete iek users entities:
title: 'Delete Iek users entities'
edit iek users entities:
title: 'Edit Iek users entities'
access iek users overview:
title: 'Access the Iek users overview page'
view published iek users entities:
title: 'View published Iek users entities'
view unpublished iek users entities:
title: 'View unpublished Iek users entities'
user_data:
path: '/iek/userdata'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\iek\Controller\CurrentUser::getIekUserData'
requirements:
_user_is_logged_in: 'TRUE'
current_user:
path: '/iek/curuser'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\iek\Controller\CurrentUser::getLoginInfo'
requirements:
_user_is_logged_in: 'TRUE'
iek.application_submit:
path: '/iek/appsubmit'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\iek\Controller\ApplicationSubmit::appSubmit'
requirements:
_user_is_logged_in: 'TRUE'
services:
logger.channel.oauth:
parent: 'logger.channel_base'
arguments: ['oauthost']
<?php
/**
* @file
* Contains iek_users.page.inc.
*
* Page callback for Iek users entities.
*/
use Drupal\Core\Render\Element;
/**
* Prepares variables for Iek users templates.
*
* Default template: iek_users.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_iek_users(array &$variables) {
// Fetch IekUsers Entity Object.
$iek_users = $variables['elements']['#iek_users'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
<?php
namespace Drupal\iek\Controller;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class CurrentUser extends ControllerBase
{
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entityTypeManager)
{
$this->entityTypeManager = $entityTypeManager;
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager')
);
}
public function getLoginInfo(Request $request)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$iekUsers = $this->entityTypeManager->getStorage('iek_users')->loadByProperties(array('authtoken' => $authToken));
$iekUser = reset($iekUsers);
if ($iekUser) {
return $this->respondWithStatus([
'name' => $iekUser->name->value,
], Response::HTTP_OK);
} else {
return $this->respondWithStatus([
'message' => t("IEK user not found"),
], Response::HTTP_FORBIDDEN);
}
}
public function getIekUserData(Request $request)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$iekUsers = $this->entityTypeManager->getStorage('iek_users')->loadByProperties(array('authtoken' => $authToken));
$iekUser = reset($iekUsers);
if ($iekUser) {
$user = $this->entityTypeManager->getStorage('user')->load($iekUser->user_id->target_id);
if ($user) {
$userName = $iekUser->name->value;
$userSurname = $iekUser->surname->value;
$userFathername = $iekUser->fathername->value;
$userMothername = $iekUser->mothername->value;
$userEmail = $user->mail->value;
return $this->respondWithStatus([
'userName' => mb_substr($iekUser->name->value,0,4,'UTF-8') !== "####" ? $iekUser->name->value : '',
'userSurname' => mb_substr($iekUser->surname->value,0,4,'UTF-8') !== "####" ? $iekUser->surname->value : '',
'userFathername' => mb_substr($iekUser->fathername->value,0,4,'UTF-8') !== "####" ? $iekUser->fathername->value : '',
'userMothername' => mb_substr($iekUser->mothername->value,0,4,'UTF-8') !== "####" ? $iekUser->mothername->value : '',
'userEmail' => mb_substr($user->mail->value,0,4,'UTF-8') !== "####" ? $user->mail->value : '',
], Response::HTTP_OK);
} else {
return $this->respondWithStatus([
'message' => t("user not found"),
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
} else {
return $this->respondWithStatus([
'message' => t("IEK user not found"),
], Response::HTTP_FORBIDDEN);
}
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
return $res;
}
}
<?php
namespace Drupal\iek\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\user\EntityOwnerInterface;
/**
* Provides an interface for defining Iek users entities.
*
* @ingroup iek
*/
interface IekUsersInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
// Add get/set methods for your configuration properties here.
/**
* Gets the Iek users name.
*
* @return string
* Name of the Iek users.
*/
public function getName();
/**
* Sets the Iek users name.
*
* @param string $name
* The Iek users name.
*
* @return \Drupal\iek\Entity\IekUsersInterface
* The called Iek users entity.
*/
public function setName($name);
/**
* Gets the Iek users creation timestamp.
*
* @return int
* Creation timestamp of the Iek users.
*/
public function getCreatedTime();
/**
* Sets the Iek users creation timestamp.
*
* @param int $timestamp
* The Iek users creation timestamp.
*
* @return \Drupal\iek\Entity\IekUsersInterface
* The called Iek users entity.
*/
public function setCreatedTime($timestamp);
/**
* Returns the Iek users published status indicator.
*
* Unpublished Iek users are only visible to restricted users.
*
* @return bool
* TRUE if the Iek users is published.
*/
public function isPublished();
/**
* Sets the published status of a Iek users.
*
* @param bool $published
* TRUE to set this Iek users to published, FALSE to set it to unpublished.
*
* @return \Drupal\iek\Entity\IekUsersInterface
* The called Iek users entity.
*/
public function setPublished($published);
//get/set methods for additional fields for configuration properties.
public function getDrupaluser_id();
public function setDrupaluser_id($val);
public function getTaxis_userid();
public function setTaxis_userid($val);
public function getTaxis_taxid();
public function setTaxis_taxid($val);
public function getSurname();
public function setSurname($val);
public function getFathername();
public function setFathername($val);
public function getMothername();
public function setMothername($val);
//public function getAddress();
//public function setAddress($val);
//public function getAddresstk();
//public function setAddresstk($val);
//public function getAddressarea();
//public function setAddressarea($val);
public function getAccesstoken();
public function setAccesstoken($val);
public function getAuthtoken();
public function setAuthtoken($val);
public function getTimelogin();
public function setTimelogin($val);
public function getTimeregistration();
public function setTimeregistration($val);
public function getTimetokeninvalid();
public function setTimetokeninvalid($val);
public function getUserip();
public function setUserip($val);
}
<?php
namespace Drupal\iek\Entity;
use Drupal\views\EntityViewsData;
/**
* Provides Views data for Iek users entities.
*/
class IekUsersViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
return $data;
}
}
<?php
namespace Drupal\iek\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
/**
* Provides a form for deleting Iek users entities.
*
* @ingroup iek
*/
class IekUsersDeleteForm extends ContentEntityDeleteForm {
}
<?php
namespace Drupal\iek\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for Iek users edit forms.
*
* @ingroup iek
*/
class IekUsersForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\iek\Entity\IekUsers */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = &$this->entity;
$status = parent::save($form, $form_state);
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Iek users.', [
'%label' => $entity->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Iek users.', [
'%label' => $entity->label(),
]));
}
$form_state->setRedirect('entity.iek_users.canonical', ['iek_users' => $entity->id()]);
}
}
<?php
namespace Drupal\iek\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class IekUsersSettingsForm.
*
* @package Drupal\iek\Form
*
* @ingroup iek
*/
class IekUsersSettingsForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'IekUsers_settings';
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Empty implementation of the abstract submit class.
}
/**
* Defines the settings form for Iek users entities.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* Form definition array.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['IekUsers_settings']['#markup'] = 'Settings form for Iek users entities. Manage field settings here.';
return $form;
}
}
<?php
namespace Drupal\iek;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Access controller for the Iek users entity.
*
* @see \Drupal\iek\Entity\IekUsers.
*/
class IekUsersAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\iek\Entity\IekUsersInterface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
return AccessResult::allowedIfHasPermission($account, 'view unpublished iek users entities');
}
return AccessResult::allowedIfHasPermission($account, 'view published iek users entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit iek users entities');