Commit cf136167 authored by Open Source Developer's avatar Open Source Developer

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

parents 45a639ee 3881f9c4
...@@ -5,6 +5,8 @@ namespace Drupal\epal; ...@@ -5,6 +5,8 @@ namespace Drupal\epal;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Exception; use Exception;
use Drupal\epal\Crypt;
/** /**
* Description of Client * Description of Client
* *
...@@ -30,23 +32,11 @@ class Client ...@@ -30,23 +32,11 @@ class Client
$this->_settings = array_merge($this->_settings, $settings); $this->_settings = array_merge($this->_settings, $settings);
$this->_settings['ws_endpoint_token'] = "{$this->_settings['ws_endpoint']}/oauth2/token"; $this->_settings['ws_endpoint_token'] = "{$this->_settings['ws_endpoint']}/oauth2/token";
$this->_settings['ws_endpoint_token_granttype'] = 'password'; $this->_settings['ws_endpoint_token_granttype'] = 'password';
$this->_settings['ws_endpoint_studentepalinfo'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalInfo";
$this->_settings['ws_endpoint_studentepalcertification'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalCertification"; $this->_settings['ws_endpoint_studentepalcertification'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalCertification";
$this->_settings['ws_endpoint_studentepalpromotion'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalPromotion"; $this->_settings['ws_endpoint_studentepalpromotion'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalPromotion";
$this->_settings['ws_endpoint_alldidactiyear'] = "{$this->_settings['ws_endpoint']}/api/general/GetAllDidactiYear"; $this->_settings['ws_endpoint_alldidactiyear'] = "{$this->_settings['ws_endpoint']}/api/general/GetAllDidactiYear";
} }
/**
* Επιστρέφει πίνακα με κλειδιά τα property names των πεδίων που επιστρέφει η GetStudentEpalInfo
* και τιμές λεκτικά - ετικέτες τους.
*
* @return array
*/
public function getStudentInfoFields()
{
return $this->studentInfoFields;
}
/** /**
* Λαμβάνει το authentication token * Λαμβάνει το authentication token
* *
...@@ -183,30 +173,32 @@ class Client ...@@ -183,30 +173,32 @@ class Client
}, ''); }, '');
$result = $this->get($endpoint, [], $headers); // data as path params... $result = $this->get($endpoint, [], $headers); // data as path params...
try {
$crypt = new Crypt();
$val = 'call:' . print_r($endpoint, true) . ':rcv:' . print_r($result, true);
$val_enc = $crypt->encrypt($val);
$this->log(__METHOD__ . $val_enc, 'info');
} catch (\Exception $e) {
$this->log(__METHOD__ . " cannot log encrypted", 'info');
}
if ($result['success'] === false) { if ($result['success'] === false) {
$this->log(__METHOD__ . " Error while calling ws. Diagnostic: {$result['response']}. Response code: {$result['http_status']}", "error"); $this->log(__METHOD__ . " Error while calling ws. Diagnostic: {$result['response']}. Response code: {$result['http_status']}", "error");
throw new Exception("Προέκυψε λάθος κατά την άντληση των στοιχείων."); throw new Exception("Προέκυψε λάθος κατά την άντληση των στοιχείων.");
} }
// now return true/false/null ?
return $result['response']; return $result['response'];
// if (($response = json_decode($result['response'], true)) !== null) {
// return $response;
// } else {
// throw new Exception("Προέκυψε λάθος κατά την λήψη των στοιχείων. Αδυναμία άντλησης στοιχείων από το response {$result['response']}");
// }
} }
public function getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name) public function getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{ {
$this->log(__METHOD__); // " $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name"); $this->log(__METHOD__);
return $this->getStudentEpalPromotionOrCertification($this->_settings['ws_endpoint_studentepalpromotion'], $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name); return $this->getStudentEpalPromotionOrCertification($this->_settings['ws_endpoint_studentepalpromotion'], $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} }
public function getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name) public function getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{ {
$this->log(__METHOD__); // " $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name"); $this->log(__METHOD__);
return $this->getStudentEpalPromotionOrCertification($this->_settings['ws_endpoint_studentepalcertification'], $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name); return $this->getStudentEpalPromotionOrCertification($this->_settings['ws_endpoint_studentepalcertification'], $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} }
...@@ -240,6 +232,14 @@ class Client ...@@ -240,6 +232,14 @@ class Client
$result = curl_exec($ch); $result = curl_exec($ch);
// log url as appropriate
try {
$crypt = new Crypt();
$uri = $crypt->encrypt($uri);
} catch (\Exception $e) {
$uri = '-cannot encrypt-';
}
if (curl_errno($ch)) { if (curl_errno($ch)) {
$this->log(__METHOD__ . " Error calling {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true), "error"); $this->log(__METHOD__ . " Error calling {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true), "error");
throw new Exception("Λάθος κατά την κλήση της υπηρεσίας."); throw new Exception("Λάθος κατά την κλήση της υπηρεσίας.");
...@@ -275,6 +275,14 @@ class Client ...@@ -275,6 +275,14 @@ class Client
$result = curl_exec($ch); $result = curl_exec($ch);
// log url as appropriate
try {
$crypt = new Crypt();
$uri = $crypt->encrypt($uri);
} catch (\Exception $e) {
$uri = '-cannot encrypt-';
}
if (curl_errno($ch)) { if (curl_errno($ch)) {
$this->log(__METHOD__ . " Error calling {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true), "error"); $this->log(__METHOD__ . " Error calling {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true), "error");
throw new Exception("Λάθος κατά την κλήση της υπηρεσίας."); throw new Exception("Λάθος κατά την κλήση της υπηρεσίας.");
......
<?php
namespace Drupal\epal;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Client;
class ClientConsumer
{
protected $entityTypeManager;
protected $logger;
protected $client;
protected $settings;
protected $cached_didactic_years = [
"1" => "2008 - 2009",
"2" => "2011 - 2012",
"3" => "1999 - 2000",
"4" => "2000 - 2001",
"5" => "2009 - 2010",
"6" => "2010 - 2011",
"7" => "2001 - 2002",
"8" => "2002 - 2003",
"9" => "2003 - 2004",
"10" => "2004 - 2005",
"11" => "2005 - 2006",
"12" => "2006 - 2007",
"13" => "2007 - 2008",
"17" => "2012 - 2013",
"18" => "2013 - 2014",
"22" => "2014 - 2015",
"23" => "2015 - 2016",
"24" => "2016 - 2017"
];
protected $cached_level_names = [
"1" => "Α",
"2" => "Β",
"3" => "Γ",
"4" => "Δ"
];
public function __construct($settings, EntityTypeManagerInterface $entityTypeManager, LoggerChannelFactoryInterface $loggerChannel)
{
$this->settings = $settings;
$this->entityTypeManager = $entityTypeManager;
$this->logger = $loggerChannel->get('epal-school');
$this->client = new Client($this->settings, $this->logger);
}
public function getAllDidactiYear()
{
$ts_start = microtime(true);
// try {
// $catalog = $this->client->getAllDidactiYear();
// } catch (\Exception $e) {
// $catalog = [];
// }
$catalog = $this->cached_didactic_years;
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return $catalog;
}
public function getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{
$ts_start = microtime(true);
try {
$result = $this->client->getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} catch (\Exception $e) {
$result = -1;
}
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return $result;
}
public function getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{
$ts_start = microtime(true);
try {
$result = $this->client->getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} catch (\Exception $e) {
$result = -1;
}
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return $result;
}
/**
* If $ending is provided
* it is assumed as the second part of the academic-year (i.e. 2017 for 2016-2017),
* the function returns the corresponding id to match first;
* If $id is provided, return the corresponding label.
* $id has priority over $ending, if both are supplied.
*
* @return null|string null if no input or no info located
*/
public function getDidacticYear($ending = null, $id = null)
{
$value = null;
if ($id !== null) {
if (array_key_exists($id, $this->cached_didactic_years)) {
$value = $this->cached_didactic_years[$id];
}
} elseif ($ending !== null) {
$remain = array_filter($this->cached_didactic_years, function ($v) use ($ending) {
$pos = strpos($v, "$ending");
return ($pos !== false && $pos > 4);
});
if (count($remain) > 0) {
$values = array_keys($remain);
$value = $values[0];
}
}
return $value;
}
/**
* Get the level name of the denoted class level
*
* @return string|mixed The level name of the provided failsafe value if not found
*/
public function getLevelName($id, $failsafe_value = 'X')
{
$value = $failsafe_value;
if (array_key_exists($id, $this->cached_level_names)) {
$value = $this->cached_level_names["$id"];
}
return $value;
}
private function generateRandomString($length)
{
$characters = ['Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω'];
$charactersLength = count($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
}
...@@ -24,10 +24,10 @@ use Drupal\Core\TypedData\Plugin\DataType\TimeStamp; ...@@ -24,10 +24,10 @@ use Drupal\Core\TypedData\Plugin\DataType\TimeStamp;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
define("ERROR_DB", -1); define("ERR_DB", -1);
define("NO_CLASS_LIMIT_DOWN", -2); define("NO_CLASS_LIM_DOWN", -2);
define("SMALL_CLASS", 1); define("SMALL_CLS", 1);
define("NON_SMALL_CLASS", 2); define("NON_SMALL_CLS", 2);
class ReportsCreator extends ControllerBase { class ReportsCreator extends ControllerBase {
...@@ -603,8 +603,8 @@ class ReportsCreator extends ControllerBase { ...@@ -603,8 +603,8 @@ class ReportsCreator extends ControllerBase {
for ($j = 0; $j < sizeof($schoolNameColumn); $j++) { for ($j = 0; $j < sizeof($schoolNameColumn); $j++) {
//αν έγινε αίτημα για εμφάνιση ολιγομελών και είναι το τρέχον τμήμα ολιγομελές //αν έγινε αίτημα για εμφάνιση ολιγομελών και είναι το τρέχον τμήμα ολιγομελές
if ( ($finalized === "1") || ($finalized === "0" && $smallClass[$j] === SMALL_CLASS if ( ($finalized === "1") || ($finalized === "0" && $smallClass[$j] === SMALL_CLS
&& $schoolSectionColumn[$j] !== "Β τάξη" && $schoolSectionColumn[$j] !== "Γ τάξη" && $schoolSectionColumn[$j] !== "Δ τάξη" ) ) && $schoolSectionColumn[$j] !== "Β τάξη" && $schoolSectionColumn[$j] !== "Γ τάξη" && $schoolSectionColumn[$j] !== "Δ τάξη" ) )
array_push($list,(object) array( array_push($list,(object) array(
'name' => $schoolNameColumn[$j], 'name' => $schoolNameColumn[$j],
...@@ -644,16 +644,16 @@ class ReportsCreator extends ControllerBase { ...@@ -644,16 +644,16 @@ class ReportsCreator extends ControllerBase {
$limitDown = $this->retrieveLimitDown($classId, $regionId); $limitDown = $this->retrieveLimitDown($classId, $regionId);
if ($limitDown === NO_CLASS_LIMIT_DOWN) if ($limitDown === NO_CLASS_LIM_DOWN)
return NO_CLASS_LIMIT_DOWN; return NO_CLASS_LIM_DOWN;
else if ($limitDown === ERROR_DB) else if ($limitDown === ERR_DB)
return ERROR_DB; return ERR_DB;
$numStudents = (int) $numStud; $numStudents = (int) $numStud;
if ( ($numStudents < $limitDown) /*&& ($numStudents > 0)*/ ) if ( ($numStudents < $limitDown) /*&& ($numStudents > 0)*/ )
return SMALL_CLASS; return SMALL_CLS;
else else
return NON_SMALL_CLASS; return NON_SMALL_CLS;
} }
...@@ -671,12 +671,12 @@ class ReportsCreator extends ControllerBase { ...@@ -671,12 +671,12 @@ class ReportsCreator extends ControllerBase {
return $classLimit->limit_down; return $classLimit->limit_down;
} }
else { else {
return NO_CLASS_LIMIT_DOWN; return NO_CLASS_LIM_DOWN;
} }
} //end try } //end try
catch (\Exception $e) { catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
return ERROR_DB; return ERR_DB;
} }
} //end function } //end function
......
...@@ -9,19 +9,36 @@ use Drupal\Core\Controller\ControllerBase; ...@@ -9,19 +9,36 @@ use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Crypt;
class SubmitedApplications extends ControllerBase class SubmitedApplications extends ControllerBase
{ {
protected $entityTypeManager; protected $entityTypeManager;
protected $logger;
/*
public function __construct(EntityTypeManagerInterface $entityTypeManager) public function __construct(EntityTypeManagerInterface $entityTypeManager)
{ {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entityTypeManager;
} }
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
$this->logger = $loggerChannel->get('epal');
}
public static function create(ContainerInterface $container) public static function create(ContainerInterface $container)
{ {
return new static( return new static(
$container->get('entity_type.manager') $container->get('entity_type.manager'),
$container->get('logger.factory')
); );
} }
...@@ -38,17 +55,37 @@ class SubmitedApplications extends ControllerBase ...@@ -38,17 +55,37 @@ class SubmitedApplications extends ControllerBase
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid)); $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid));
$i = 0; $i = 0;
if ($epalStudents) { if ($epalStudents) {
$list = array();
$crypt = new Crypt();
$list = array();
foreach ($epalStudents as $object) { foreach ($epalStudents as $object) {
$indexid = intval($object -> id())-1; $indexid = intval($object -> id())-1;
try {
$name_decoded = $crypt->decrypt($object->name->value);
$studentsurname_decoded = $crypt->decrypt($object->studentsurname->value);
}
catch (\Exception $e) {
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected error occured during DECODING data in getSubmittedApplications Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$list[] = array( $list[] = array(
'id' => $indexid, 'id' => $indexid,
'name' => $object -> name ->value, //'name' => $object -> name ->value,
'studentsurname' => $object -> studentsurname ->value); 'name' => $name_decoded,
//'studentsurname' => $object -> studentsurname ->value);
'studentsurname' => $studentsurname_decoded );
$i++; $i++;
} }
unset($crypt);
return $this->respondWithStatus( return $this->respondWithStatus(
$list $list
, Response::HTTP_OK); , Response::HTTP_OK);
...@@ -105,31 +142,74 @@ class SubmitedApplications extends ControllerBase ...@@ -105,31 +142,74 @@ class SubmitedApplications extends ControllerBase
if ($course) if ($course)
$courseName = $this->entityTypeManager->getStorage('eepal_specialty')->load($course->coursefield_id->target_id)->name->value; $courseName = $this->entityTypeManager->getStorage('eepal_specialty')->load($course->coursefield_id->target_id)->name->value;
} }
$crypt = new Crypt();
try {
$name_decoded = $crypt->decrypt($object->name->value);
$studentsurname_decoded = $crypt->decrypt($object->studentsurname->value);
$fatherfirstname_decoded = $crypt->decrypt($object->fatherfirstname->value);
$motherfirstname_decoded = $crypt->decrypt($object->motherfirstname->value);
$regionaddress_decoded = $crypt->decrypt($object->regionaddress->value);
$regiontk_decoded = $crypt->decrypt($object->regiontk->value);
$regionarea_decoded = $crypt->decrypt($object->regionarea->value);
$certificatetype_decoded = $crypt->decrypt($object->certificatetype->value);
$relationtostudent_decoded = $crypt->decrypt($object->relationtostudent->value);
$telnum_decoded = $crypt->decrypt($object->telnum->value);
$guardian_name_decoded = $crypt->decrypt($object->guardian_name->value);
$guardian_surname_decoded = $crypt->decrypt($object->guardian_surname->value);
$guardian_fathername_decoded = $crypt->decrypt($object->guardian_fathername->value);
$guardian_mothername_decoded = $crypt->decrypt($object->guardian_mothername->value);
}
catch (\Exception $e) {
//print_r($e->getMessage());
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected error occured during DECODING data in getStudentApplications Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
unset($crypt);
$list[] = array( $list[] = array(
'applicationId' => $object->id(), 'applicationId' => $object->id(),
'name' => $object -> name ->value, //'name' => $object -> name ->value,
'studentsurname' => $object -> studentsurname ->value, 'name' => $name_decoded,
'fatherfirstname' => $object -> fatherfirstname ->value, //'studentsurname' => $object -> studentsurname ->value,
'studentsurname' => $studentsurname_decoded,
//'fatherfirstname' => $object -> fatherfirstname ->value,
'fatherfirstname' => $fatherfirstname_decoded,
'fathersurname' =>$object -> fathersurname ->value, 'fathersurname' =>$object -> fathersurname ->value,
'motherfirstname' => $object -> motherfirstname ->value, //'motherfirstname' => $object -> motherfirstname ->value,
'motherfirstname' => $motherfirstname_decoded,
'mothersurname' =>$object -> mothersurname ->value, 'mothersurname' =>$object -> mothersurname ->value,
'guardian_name' =>$object -> guardian_name ->value, //'guardian_name' =>$object -> guardian_name ->value,
'guardian_surname' =>$object -> guardian_surname ->value, 'guardian_name' =>$guardian_name_decoded,
'guardian_fathername' =>$object -> guardian_fathername ->value, //'guardian_surname' =>$object -> guardian_surname ->value,
'guardian_mothername' =>$object -> guardian_mothername ->value, 'guardian_surname' => $guardian_surname_decoded,
//'guardian_fathername' =>$object -> guardian_fathername ->value,
'guardian_fathername' =>$guardian_fathername_decoded,
//'guardian_mothername' =>$object -> guardian_mothername ->value,
'guardian_mothername' =>$guardian_mothername_decoded,
'lastschool_schoolname' =>$object -> lastschool_schoolname ->value, 'lastschool_schoolname' =>$object -> lastschool_schoolname ->value,
'lastschool_schoolyear' =>$object -> lastschool_schoolyear ->value, 'lastschool_schoolyear' =>$object -> lastschool_schoolyear ->value,
'lastschool_class' =>$object -> lastschool_class ->value, 'lastschool_class' =>$object -> lastschool_class ->value,
'currentclass' =>$object -> currentclass ->value, 'currentclass' =>$object -> currentclass ->value,
'currentsector' =>$sectorName, 'currentsector' =>$sectorName,
'currentcourse' =>$courseName, 'currentcourse' =>$courseName,
'regionaddress' =>$object -> regionaddress ->value, //'regionaddress' =>$object -> regionaddress ->value,
'regiontk' =>$object -> regiontk ->value, 'regionaddress' =>$regionaddress_decoded,
'regionarea' =>$object -> regionarea ->value, //'regiontk' =>$object -> regiontk ->value,
'certificatetype' =>$object -> certificatetype ->value, 'regiontk' =>$regiontk_decoded,
//'regionarea' =>$object -> regionarea ->value,
'regionarea' =>$regionarea_decoded,
//'certificatetype' =>$object -> certificatetype ->value,
'certificatetype' => $certificatetype_decoded,
'graduation_year' =>$object -> graduation_year ->value, 'graduation_year' =>$object -> graduation_year ->value,
'telnum' =>$object -> telnum ->value, //'telnum' =>$object -> telnum ->value,
'relationtostudent' =>$object -> relationtostudent ->value, 'telnum' =>$telnum_decoded,
//'relationtostudent' =>$object -> relationtostudent ->value,
'relationtostudent' => $relationtostudent_decoded,
'birthdate' => substr($object->birthdate->value, 8, 2) . '/' . substr($object->birthdate->value, 6, 2) . '/' . substr($object->birthdate->value, 0, 4), 'birthdate' => substr($object->birthdate->value, 8, 2) . '/' . substr($object->birthdate->value, 6, 2) . '/' . substr($object->birthdate->value, 0, 4),
'created' => date('d/m/Y H:i', $object -> created ->value), 'created' => date('d/m/Y H:i', $object -> created ->value),
......
...@@ -118,10 +118,4 @@ class WSConsumer extends ControllerBase ...@@ -118,10 +118,4 @@ class WSConsumer extends ControllerBase
return $randomString; return $randomString;
} }
// private function respondWithStatus($arr, $s)
// {
// $res = new JsonResponse($arr);
// $res->setStatusCode($s);
// return $res;
// }
} }
...@@ -11,7 +11,7 @@ class Crypt ...@@ -11,7 +11,7 @@ class Crypt
private $fname; // store private $fname; // store
public function __construct($fname) public function __construct($fname = null)
{ {
if (is_string($fname)) { if (is_string($fname)) {
$this->fname = $fname; $this->fname = $fname;
......
CREATE UNIQUE INDEX uidx_region_regno ON eepal_region_field_data(registry_no); CREATE UNIQUE INDEX uidx_region_regno ON eepal_region_field_data(registry_no);
CREATE UNIQUE INDEX uidx_adminarea_regno ON eepal_admin_area_field_data(registry_no); CREATE UNIQUE INDEX uidx_adminarea_regno ON eepal_admin_area_field_data(registry_no);
\ No newline at end of file CREATE UNIQUE INDEX uidx_taxis_userid ON epal_users(taxis_userid);
CREATE INDEX uidx_authtoken ON epal_users(authtoken(150));
...@@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; ...@@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use OAuth; use OAuth;
use DOMDocument;
use OAuthException; use OAuthException;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
...@@ -128,21 +129,25 @@ class CBController extends ControllerBase ...@@ -128,21 +129,25 @@ class CBController extends ControllerBase
public function authenticatePhase2($request, $authToken, $authVerifier) public function authenticatePhase2($request, $authToken, $authVerifier)
{ {
$taxis_userid = null;
$trx = $this->connection->startTransaction();
try { try {
$taxis_userid = null;
$trx = $this->connection->startTransaction();
$oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI); $oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug(); // $oauth->enableDebug();
$oauth->setToken($authToken, $this->requestTokenSecret); $oauth->setToken($authToken, $this->requestTokenSecret);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier); $accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']); $oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$oauth->fetch($this->api_url); $oauth->fetch($this->api_url);
$this->logger->warning($oauth->getLastResponse()); $dom = $this->loadXML($oauth->getLastResponse());
$taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText'); $taxis_userData = $this->getXMLElements($dom);
if (!$taxis_userData || sizeof($taxis_userData) === 0) {
return false;
}
$currentTime = time(); $currentTime = time();
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userid)); $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userData['tin']));
$epalUser = reset($epalUsers); $epalUser = reset($epalUsers);
$epalToken = md5(uniqid(mt_rand(), true)); $epalToken = md5(uniqid(mt_rand(), true));
...@@ -163,7 +168,6 @@ class CBController extends ControllerBase ...@@ -163,7 +168,6 @@ class CBController extends ControllerBase
$epalUser->save(); $epalUser->save();
} }
} }
if ($epalUser === null || !$epalUser) { if ($epalUser === null || !$epalUser) {
//Create a User //Create a User
...@@ -190,17 +194,15 @@ class CBController extends ControllerBase ...