added php encoding/decoding methods in appropriate Drupal Controllers

parent efb927c5
...@@ -13,6 +13,8 @@ use Symfony\Component\HttpFoundation\Request; ...@@ -13,6 +13,8 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Crypt;
class ApplicationSubmit extends ControllerBase { class ApplicationSubmit extends ControllerBase {
protected $entityTypeManager; protected $entityTypeManager;
...@@ -56,7 +58,37 @@ class ApplicationSubmit extends ControllerBase { ...@@ -56,7 +58,37 @@ class ApplicationSubmit extends ControllerBase {
"error_code" => 5002 "error_code" => 5002
], Response::HTTP_BAD_REQUEST); ], Response::HTTP_BAD_REQUEST);
} }
$transaction = $this->connection->startTransaction();
$crypt = new Crypt();
try {
$name_encoded = $crypt->encrypt($applicationForm[0]['name']);
$studentsurname_encoded = $crypt->encrypt($applicationForm[0]['studentsurname']);
$fatherfirstname_encoded = $crypt->encrypt($applicationForm[0]['fatherfirstname']);
$motherfirstname_encoded = $crypt->encrypt($applicationForm[0]['motherfirstname']);
$regionaddress_encoded = $crypt->encrypt($applicationForm[0]['regionaddress']);
$regiontk_encoded = $crypt->encrypt($applicationForm[0]['regiontk']);
$regionarea_encoded = $crypt->encrypt($applicationForm[0]['regionarea']);
$certificatetype_encoded = $crypt->encrypt($applicationForm[0]['certificatetype']);
$relationtostudent_encoded = $crypt->encrypt($applicationForm[0]['relationtostudent']);
$telnum_encoded = $crypt->encrypt($applicationForm[0]['telnum']);
$guardian_name_encoded = $crypt->encrypt($applicationForm[0]['cu_name']);
$guardian_surname_encoded = $crypt->encrypt($applicationForm[0]['cu_surname']);
$guardian_fathername_encoded = $crypt->encrypt($applicationForm[0]['cu_fathername']);
$guardian_mothername_encoded = $crypt->encrypt($applicationForm[0]['cu_mothername']);
}
catch (\Exception $e) {
print_r($e->getMessage());
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"error_code" => 5001
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
unset($crypt);
$transaction = $this->connection->startTransaction();
try { try {
//insert records in entity: epal_student //insert records in entity: epal_student
$authToken = $request->headers->get('PHP_AUTH_USER'); $authToken = $request->headers->get('PHP_AUTH_USER');
...@@ -84,29 +116,43 @@ class ApplicationSubmit extends ControllerBase { ...@@ -84,29 +116,43 @@ class ApplicationSubmit extends ControllerBase {
'points' => 0, 'points' => 0,
'user_id' => $epalUser->user_id->target_id, 'user_id' => $epalUser->user_id->target_id,
'epaluser_id' => $epalUser->id(), 'epaluser_id' => $epalUser->id(),
'name' => $applicationForm[0]['name'], //'name' => $applicationForm[0]['name'],
'studentsurname' => $applicationForm[0]['studentsurname'], 'name' => $name_encoded,
//'studentsurname' => $applicationForm[0]['studentsurname'],
'studentsurname' => $studentsurname_encoded,
'birthdate' => $applicationForm[0]['studentbirthdate'], 'birthdate' => $applicationForm[0]['studentbirthdate'],
'fatherfirstname' => $applicationForm[0]['fatherfirstname'], //'fatherfirstname' => $applicationForm[0]['fatherfirstname'],
'motherfirstname' => $applicationForm[0]['motherfirstname'], 'fatherfirstname' => $fatherfirstname_encoded,
'regionaddress' => $applicationForm[0]['regionaddress'], //'motherfirstname' => $applicationForm[0]['motherfirstname'],
'regionarea' => $applicationForm[0]['regionarea'], 'motherfirstname' => $motherfirstname_encoded,
'regiontk' => $applicationForm[0]['regiontk'], //'regionaddress' => $applicationForm[0]['regionaddress'],
'certificatetype' => $applicationForm[0]['certificatetype'], 'regionaddress' => $regionaddress_encoded,
//'regionarea' => $applicationForm[0]['regionarea'],
'regionarea' => $regionarea_encoded,
//'regiontk' => $applicationForm[0]['regiontk'],
'regiontk' => $regiontk_encoded,
//'certificatetype' => $applicationForm[0]['certificatetype'],
'certificatetype' => $certificatetype_encoded,
'graduation_year' => $applicationForm[0]['graduation_year'], 'graduation_year' => $applicationForm[0]['graduation_year'],
'lastschool_registrynumber' => $applicationForm[0]['lastschool_registrynumber'], 'lastschool_registrynumber' => $applicationForm[0]['lastschool_registrynumber'],
'lastschool_unittypeid' => $applicationForm[0]['lastschool_unittypeid'], 'lastschool_unittypeid' => $applicationForm[0]['lastschool_unittypeid'],
'lastschool_schoolname' => $applicationForm[0]['lastschool_schoolname'], 'lastschool_schoolname' => $applicationForm[0]['lastschool_schoolname'],
'lastschool_schoolyear' => $applicationForm[0]['lastschool_schoolyear'], 'lastschool_schoolyear' => $applicationForm[0]['lastschool_schoolyear'],
'lastschool_class' => $applicationForm[0]['lastschool_class'], 'lastschool_class' => $applicationForm[0]['lastschool_class'],
'currentclass' => $applicationForm[0]['currentclass'], 'currentclass' => $applicationForm[0]['currentclass'],
'guardian_name' => $applicationForm[0]['cu_name'], //'guardian_name' => $applicationForm[0]['cu_name'],
'guardian_surname' => $applicationForm[0]['cu_surname'], 'guardian_name' => $guardian_name_encoded,
'guardian_fathername' => $applicationForm[0]['cu_fathername'], //'guardian_surname' => $applicationForm[0]['cu_surname'],
'guardian_mothername' => $applicationForm[0]['cu_mothername'], 'guardian_surname' => $guardian_surname_encoded,
'agreement' => $applicationForm[0]['disclaimer_checked'], //'guardian_fathername' => $applicationForm[0]['cu_fathername'],
'relationtostudent' => $applicationForm[0]['relationtostudent'], 'guardian_fathername' => $guardian_fathername_encoded,
'telnum' => $applicationForm[0]['telnum'] //'guardian_mothername' => $applicationForm[0]['cu_mothername'],
'guardian_mothername' => $guardian_mothername_encoded,
'agreement' => $applicationForm[0]['disclaimer_checked'],
//'relationtostudent' => $applicationForm[0]['relationtostudent'],
'relationtostudent' => $relationtostudent_encoded,
//'telnum' => $applicationForm[0]['telnum']
'telnum' => $telnum_encoded
); );
if (($errorCode = $this->validateStudent($student)) > 0) { if (($errorCode = $this->validateStudent($student)) > 0) {
......
...@@ -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),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment