Commit 30d0e77f authored by Νίκος Κατσαούνος's avatar Νίκος Κατσαούνος
Browse files

Merge branch 'develop' of https://git.minedu.gov.gr/itminedu/e-epal into component_updates

parents cfabdf81 cc188496
......@@ -207,7 +207,7 @@ epal.ministry.storesettings:
requirements:
_user_is_logged_in: 'TRUE'
regionview:
path: '/epal/ScoolperPerf'
path: '/epal/ScoolperPerf/{check_status}'
options:
_auth: [ 'basic_auth' ]
defaults:
......
......@@ -427,7 +427,7 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
public function getSchoolsPerPerfetcure(Request $request)
public function getSchoolsPerPerfetcure(Request $request, $check_status)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
......@@ -436,14 +436,20 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
$user = reset($users);
if ($user)
{
$perfectureId = $user -> init -> value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $perfectureId ));
$selectionId = $user -> init -> value;
if ($check_status == 1){
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $selectionId ));
}
else
{
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('edu_admin_id'=> $selectionId ));
}
if ($schools)
{
$list = array();
foreach ($schools as $object) {
$status = $this->returnstatus(147);
$status = $this->returnstatus($object -> id());
$list[] = array(
'id' =>$object -> id(),
'name' => $object -> name ->value,
......@@ -595,10 +601,74 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
public function returnstatus($id)
{
if ($id == 147)
return true ;
return false;
$schoolid = $id;
$SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
$SchoolCat = reset($SchoolCats);
if ($SchoolCat){
$categ = $SchoolCat-> metathesis_region -> value;
}
$CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $schoolid ));
if ($CourseA)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 1, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => -1, 'currentclass' => 1 ));
//foreach ($CourseA as $object) {
if (sizeof($studentPerSchool) < $limit){
return false;
exit;
}
} // }
$CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
if ($CourseB)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 2, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
foreach ($CourseB as $object) {
$sectorid = $object -> sector_id -> entity -> id();
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2 ));
if (sizeof($studentPerSchool) < $limit){
return false;
exit;
}
}
}
$CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
if ($CourseC)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 3, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
foreach ($CourseC as $object) {
$specialityid = $object -> specialty_id -> entity -> id() ;
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3 ));
if (sizeof($studentPerSchool) < $limit){
return false;
exit;
}
}
}
return true;
exit;
}
......
......@@ -128,116 +128,111 @@ class CBController extends ControllerBase
public function authenticatePhase2($request, $authToken, $authVerifier)
{
$taxis_userid = null;
$trx = $this->connection->startTransaction();
try {
$oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->setToken($authToken, $this->requestTokenSecret);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$oauth->fetch($this->api_url);
$this->logger->warning($oauth->getLastResponse());
$taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText');
$currentTime = time();
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userid));
$epalUser = reset($epalUsers);
$epalToken = md5(uniqid(mt_rand(), true));
if ($epalUser) {
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) {
// $user->setPassword('harispass');
// $user->setUsername('harisp');
$user->setPassword($epalToken);
$user->setUsername($epalToken);
$user->save();
$epalUser->set('authtoken', $epalToken);
$epalUser->set('accesstoken', $accessToken['oauth_token']);
$epalUser->set('accesstoken_secret', $accessToken['oauth_token_secret']);
$epalUser->set('requesttoken',$this->requestToken);
$epalUser->set('requesttoken_secret', $this->requestTokenSecret);
$epalUser->set('timelogin', $currentTime);
$epalUser->set('userip', $request->getClientIp());
$epalUser->save();
$taxis_userid = null;
$trx = $this->connection->startTransaction();
try {
$oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->setToken($authToken, $this->requestTokenSecret);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$oauth->fetch($this->api_url);
$this->logger->warning($oauth->getLastResponse());
$taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText');
$currentTime = time();
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userid));
$epalUser = reset($epalUsers);
$epalToken = md5(uniqid(mt_rand(), true));
if ($epalUser) {
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) {
$user->setPassword($epalToken);
$user->setUsername($epalToken);
$user->save();
$epalUser->set('authtoken', $epalToken);
$epalUser->set('accesstoken', $accessToken['oauth_token']);
$epalUser->set('accesstoken_secret', $accessToken['oauth_token_secret']);
$epalUser->set('requesttoken',$this->requestToken);
$epalUser->set('requesttoken_secret', $this->requestTokenSecret);
$epalUser->set('timelogin', $currentTime);
$epalUser->set('userip', $request->getClientIp());
$epalUser->save();
}
}
}
if ($epalUser === null || !$epalUser) {
//Create a User
$user = User::create();
//Mandatory settings
$unique_id = uniqid('####');
$user->setPassword($epalToken);
$user->enforceIsNew();
$user->setEmail($unique_id);
$user->setUsername($epalToken); //This username must be unique and accept only a-Z,0-9, - _ @ .
$user->activate();
$user->set('init', $unique_id);
//Set Language
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$user->set('langcode', $language_interface->getId());
$user->set('preferred_langcode', $language_interface->getId());
$user->set('preferred_admin_langcode', $language_interface->getId());
//Adding default user role
$user->addRole('applicant');
$user->save();
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('mail' => $unique_id));
$user = reset($users);
if ($user) {
$this->logger->warning('userid 190='.$user->id().'*** name='.$user->name->value);
$epalUser = $this->entityTypeManager()->getStorage('epal_users')->create(array(
// 'langcode' => $language_interface->getId(),
'langcode' => 'el',
'user_id' => $user->id(),
'drupaluser_id' => $user->id(),
'taxis_userid' => $taxis_userid,
'taxis_taxid' => $unique_id,
'name' => $unique_id,
'surname' => $unique_id,
'fathername' => $unique_id,
'mothername' => $unique_id,
'accesstoken' => $accessToken['oauth_token'],
'accesstoken_secret' => $accessToken['oauth_token_secret'],
'authtoken' => $epalToken,
'requesttoken' => $this->requestToken,
'requesttoken_secret' => $this->requestTokenSecret,
'timelogin' => $currentTime,
'timeregistration' => $currentTime,
'timetokeninvalid' => 0,
'userip' => $request->getClientIp(),
'status' => 1
));
$epalUser->save();
} else {
return false;
}
if ($epalUser === null || !$epalUser) {
}
$this->oauthostSession->set('authtoken', $epalToken);
$this->oauthostSession->save();
// $this->oauthostSession->delete();
//Create a User
$user = User::create();
//Mandatory settings
$unique_id = uniqid('####');
$user->setPassword($epalToken);
$user->enforceIsNew();
$user->setEmail($unique_id);
$user->setUsername($epalToken); //This username must be unique and accept only a-Z,0-9, - _ @ .
$user->activate();
$user->set('init', $unique_id);
//Set Language
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$user->set('langcode', $language_interface->getId());
$user->set('preferred_langcode', $language_interface->getId());
$user->set('preferred_admin_langcode', $language_interface->getId());
//Adding default user role
$user->addRole('applicant');
$user->save();
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('mail' => $unique_id));
$user = reset($users);
if ($user) {
$this->logger->warning('userid 190='.$user->id().'*** name='.$user->name->value);
$epalUser = $this->entityTypeManager()->getStorage('epal_users')->create(array(
'langcode' => 'el',
'user_id' => $user->id(),
'drupaluser_id' => $user->id(),
'taxis_userid' => $taxis_userid,
'taxis_taxid' => $unique_id,
'name' => $unique_id,
'surname' => $unique_id,
'fathername' => $unique_id,
'mothername' => $unique_id,
'accesstoken' => $accessToken['oauth_token'],
'accesstoken_secret' => $accessToken['oauth_token_secret'],
'authtoken' => $epalToken,
'requesttoken' => $this->requestToken,
'requesttoken_secret' => $this->requestTokenSecret,
'timelogin' => $currentTime,
'timeregistration' => $currentTime,
'timetokeninvalid' => 0,
'userip' => $request->getClientIp(),
'status' => 1
));
$epalUser->save();
} else {
return false;
}
return $epalToken;
} catch (OAuthException $e) {
$this->logger->warning($e->getMessage());
$trx->rollback();
return false;
} catch (\Exception $ee) {
$this->logger->warning($ee->getMessage());
$trx->rollback();
return false;
}
}
$this->oauthostSession->set('authtoken', $epalToken);
$this->oauthostSession->save();
// $this->oauthostSession->delete();
return $epalToken;
} catch (OAuthException $e) {
$this->logger->warning($e->getMessage());
$trx->rollback();
return false;
} catch (\Exception $ee) {
$this->logger->warning($ee->getMessage());
$trx->rollback();
return false;
}
return false;
}
......
<?php
namespace Drupal\oauthost\Controller;
<?php namespace Drupal\oauthost\Controller;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
......@@ -16,11 +14,11 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
class OAuthLogout extends ControllerBase
{
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
protected $consumer_key = '';
protected $consumer_secret = '';
protected $request_token_url;
......@@ -33,10 +31,7 @@ class OAuthLogout extends ControllerBase
protected $redirect_url;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel)
EntityTypeManagerInterface $entityTypeManager, QueryFactory $entity_query, Connection $connection, LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query;
......@@ -47,17 +42,14 @@ class OAuthLogout extends ControllerBase
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity.manager'),
$container->get('entity.query'),
$container->get('database'),
$container->get('logger.factory')
);
$container->get('entity.manager'), $container->get('entity.query'), $container->get('database'), $container->get('logger.factory')
);
}
public function logoutGo(Request $request)
{
$trx = $this->connection->startTransaction();
try {
$user = null;
$username = $request->headers->get('PHP_AUTH_USER');
......@@ -67,85 +59,98 @@ class OAuthLogout extends ControllerBase
if ($this->oauthostSession) {
$configRowName = $this->oauthostSession->configrowname->value;
} else {
$trx->rollback();
$this->logger->warning("oauthostSession for [{$username}] not set");
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$ostauthConfigs = $this->entityTypeManager->getStorage('oauthost_config')->loadByProperties(array('name' => $configRowName));
$ostauthConfig = reset($ostauthConfigs);
if ($ostauthConfig) {
$this->consumer_key = $ostauthConfig->consumer_key->value;
$this->consumer_secret = $ostauthConfig->consumer_secret->value;
$this->request_token_url = $ostauthConfig->request_token_url->value;
$this->user_authorization_url = $ostauthConfig->user_authorization_url->value;
$this->access_token_url = $ostauthConfig->access_token_url->value;
$this->signature_method = $ostauthConfig->signature_method->value;
$this->api_url = $ostauthConfig->api_url->value;
$this->callback_url = $ostauthConfig->callback_url->value;
$this->logout_url = $ostauthConfig->logout_url->value;
$this->redirect_url = $ostauthConfig->redirect_url->value;
} else {
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $username));
$epalUser = reset($epalUsers);
$foundUser = true;
if ($epalUser) {
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) {
$res = \Drupal::httpClient()->get($this->logout_url . $username, array('headers' => array('Accept' => 'text/plain')));
/* $resData = (string) $res->getBody();
if (empty($resData)) {
return FALSE;
} */
// if ($res->getStatusCode() === "200")
$ostauthConfigs = $this->entityTypeManager->getStorage('oauthost_config')->loadByProperties(array('name' => $configRowName));
$ostauthConfig = reset($ostauthConfigs);
if ($ostauthConfig) {
$this->consumer_key = $ostauthConfig->consumer_key->value;
$this->consumer_secret = $ostauthConfig->consumer_secret->value;
$this->request_token_url = $ostauthConfig->request_token_url->value;
$this->user_authorization_url = $ostauthConfig->user_authorization_url->value;
$this->access_token_url = $ostauthConfig->access_token_url->value;
$this->signature_method = $ostauthConfig->signature_method->value;
$this->api_url = $ostauthConfig->api_url->value;
$this->callback_url = $ostauthConfig->callback_url->value;
$this->logout_url = $ostauthConfig->logout_url->value;
$this->redirect_url = $ostauthConfig->redirect_url->value;
} else {
$trx->rollback();
$this->logger->warning("ostauthConfig [{$configRowName}]not found");
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$user->setPassword(uniqid('pw'));
$user->save();
$epalUser->set('accesstoken', '-');
$epalUser->set('accesstoken_secret', '-');
$epalUser->set('authtoken','-');
$epalUser->set('requesttoken','-');
$epalUser->set('requesttoken_secret', '-');
$epalUser->save();
$epalUsers = $this->entityTypeManager
->getStorage('epal_users')
->loadByProperties(array('authtoken' => $username));
$epalUser = reset($epalUsers);
$foundUser = false;
if ($epalUser) {
$user = $this->entityTypeManager
->getStorage('user')
->load($epalUser->user_id->target_id);
$logout_token = $epalUser->getRequesttoken();
if ($user) {
$res = \Drupal::httpClient()->get($this->logout_url . $username, array('headers' => array('Accept' => 'text/plain')));
$user->setPassword(uniqid('pw'));
$user->save();
$epalUser->set('accesstoken', '-');
$epalUser->set('accesstoken_secret', '-');
$epalUser->set('authtoken', '-');
$epalUser->set('requesttoken', '-');
$epalUser->set('requesttoken_secret', '-');
$epalUser->save();
$foundUser = true;
}
}
if (!$foundUser) {
$trx->rollback();
$this->logger->warning("user not found");
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
// logout from remote host
$logout_call_url = "{$this->logout_url}{$logout_token}";
if (($ch = curl_init()) !== false) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $logout_call_url);
$remote_logout_result = curl_exec($ch);
if ($remote_logout_result === false) {
// record failure
$this->logger->warning("OAUTH remote logout call to [{$logout_call_url}] fail: " . curl_error($ch));
}
curl_close($ch);
} else {
$foundUser = false;
$this->logger->warning("OAUTH remote logout to [{$logout_call_url}] not called");
}
} else {
$foundUser = false;
}
if (!$foundUser) {
$this->logger->warning("user not found");
session_unset();
session_destroy();
\Drupal::service('page_cache_kill_switch')->trigger();
$this->oauthostSession->delete();
$this->logger->info("OAUTH remote logout success for [{$username}]");
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->setContent("{\"message\": \"Server logout successful\",\"next\": \"{$this->redirect_url}\"}");
$response->setStatusCode(Response::HTTP_OK);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
session_unset();
session_destroy();
\Drupal::service('page_cache_kill_switch')->trigger();
$response = new Response();
$response->setContent('logout successful');
$response->setStatusCode(Response::HTTP_OK);
$response->headers->set('Content-Type', 'application/json');
$this->oauthostSession->delete();
return $response;
// return new RedirectResponse($this->redirect_url . '&auth_role=', 302, []);
return $response;
} catch (Exception $e) {
$this->logger->warning($e->getMessage());
$response = new Response();
......@@ -156,5 +161,4 @@ class OAuthLogout extends ControllerBase
return $response;
}
}
}
......@@ -56,6 +56,27 @@ import {
</form>
</div>
<div id="checksaved" (onHidden)="onHidden('#checksaved')"
class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header modal-header-danger">
<h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;Πρέπει να συπληρώσετε όλα τα πεδία</h3>
<button type="button" class="close pull-right" aria-label="Close" (click)="hideModal('#checksaved')">
<span aria-hidden="true"><i class="fa fa-times"></i></span>
</button>
</div>
<div class="modal-body">