Commit 21f6547a authored by Νίκος Κατσαούνος's avatar Νίκος Κατσαούνος

updated schools_order_select component

parents 088ea251 27b48325
......@@ -14,7 +14,7 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Cookie;
require ('RedirectResponseWithCookie.php');
require ('RedirectResponseWithCookieExt.php');
class CASLogin extends ControllerBase
{
......@@ -70,8 +70,11 @@ class CASLogin extends ControllerBase
{
try {
$CASOSTConfigs = $this->entityTypeManager->getStorage('casost_config')->loadByProperties(array('name' => 'casost_sch_sso_config'));
$configRowName = 'casost_sch_sso_config';
$configRowId = $request->query->get('config');
if ($configRowId)
$configRowName = $configRowName . '_' . $configRowId;
$CASOSTConfigs = $this->entityTypeManager->getStorage('casost_config')->loadByProperties(array('name' => $configRowName));
$CASOSTConfig = reset($CASOSTConfigs);
if ($CASOSTConfig) {
$this->serverVersion = $CASOSTConfig->serverversion->value;
......@@ -91,9 +94,9 @@ class CASLogin extends ControllerBase
$this->allowed2 = $CASOSTConfig->allowed2->value;
$this->allowed2Value = $CASOSTConfig->allowed2value->value;
}
phpCAS::setDebug("/home/haris/devel/eepal/drupal/modules/casost/phpcas.log");
phpCAS::setDebug("phpcas.log");
// Enable verbose error messages. Disable in production!
phpCAS::setVerbose(true);
//phpCAS::setVerbose(true);
phpCAS::client($this->serverVersion,
$this->serverHostname,
......@@ -196,13 +199,17 @@ class CASLogin extends ControllerBase
return $response;
}
// $this->logger->warning('cn=' . $filterAttribute('cn'));
// $this->logger->warning('redirecturl=' . $this->redirectUrl);
$epalToken = $this->authenticatePhase2($request, $CASUser, $internalRole, $filterAttribute('cn'));
if ($epalToken) {
$cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', $exposedRole, 0, '/', null, false, false);
if ('casost_sch_sso_config' === $configRowName) {
/* $cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', $exposedRole, 0, '/', null, false, false); */
return new RedirectResponseWithCookie($this->redirectUrl, 302, array ($cookie, $cookie2));
return new RedirectResponse($this->redirectUrl . $epalToken.'&auth_role=' . $exposedRole, 302, []);
} else {
return new RedirectResponseWithCookieExt($this->redirectUrl . $epalToken.'&auth_role=' . $exposedRole, 302, []);
}
// $headers = array("auth_token" => $epalToken, "auth_role" => "director");
// return new RedirectResponse($this->redirectUrl, 302, $headers);
} else {
......
......@@ -11,8 +11,6 @@ use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use phpCAS;
class CASLogout extends ControllerBase
......@@ -63,34 +61,38 @@ class CASLogout extends ControllerBase
public function logoutGo(Request $request)
{
try {
$CASOSTConfigs = $this->entityTypeManager->getStorage('casost_config')->loadByProperties(array('name' => 'casost_sch_sso_config'));
$CASOSTConfig = reset($CASOSTConfigs);
if ($CASOSTConfig) {
$this->serverVersion = $CASOSTConfig->serverversion->value;
$this->serverHostname = $CASOSTConfig->serverhostname->value;
$this->serverPort = $CASOSTConfig->serverport->value;
$this->serverUri = $CASOSTConfig->serveruri->value === null ? '' : $CASOSTConfig->serveruri->value;
$this->redirectUrl = $CASOSTConfig->redirecturl->value;
$this->changeSessionId = $CASOSTConfig->changesessionid->value;
$this->CASServerCACert = $CASOSTConfig->casservercacert->value;
$this->CASServerCNValidate = $CASOSTConfig->casservercnvalidate->value;
$this->noCASServerValidation = $CASOSTConfig->nocasservervalidation->value;
$this->proxy = $CASOSTConfig->proxy->value;
$this->handleLogoutRequests = $CASOSTConfig->handlelogoutrequests->value;
$this->CASLang = $CASOSTConfig->caslang->value;
$this->allowed1 = $CASOSTConfig->allowed1->value;
$this->allowed1Value = $CASOSTConfig->allowed1value->value;
$this->allowed2 = $CASOSTConfig->allowed2->value;
$this->allowed2Value = $CASOSTConfig->allowed2value->value;
} else {
$response = new Response();
$response->setContent('forbidden. No config');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$configRowName = 'casost_sch_sso_config';
$configRowId = $request->query->get('config');
if ($configRowId) {
$configRowName = $configRowName.'_'.$configRowId;
}
$CASOSTConfigs = $this->entityTypeManager->getStorage('casost_config')->loadByProperties(array('name' => $configRowName));
$CASOSTConfig = reset($CASOSTConfigs);
if ($CASOSTConfig) {
$this->serverVersion = $CASOSTConfig->serverversion->value;
$this->serverHostname = $CASOSTConfig->serverhostname->value;
$this->serverPort = $CASOSTConfig->serverport->value;
$this->serverUri = $CASOSTConfig->serveruri->value === null ? '' : $CASOSTConfig->serveruri->value;
$this->redirectUrl = $CASOSTConfig->redirecturl->value;
$this->changeSessionId = $CASOSTConfig->changesessionid->value;
$this->CASServerCACert = $CASOSTConfig->casservercacert->value;
$this->CASServerCNValidate = $CASOSTConfig->casservercnvalidate->value;
$this->noCASServerValidation = $CASOSTConfig->nocasservervalidation->value;
$this->proxy = $CASOSTConfig->proxy->value;
$this->handleLogoutRequests = $CASOSTConfig->handlelogoutrequests->value;
$this->CASLang = $CASOSTConfig->caslang->value;
$this->allowed1 = $CASOSTConfig->allowed1->value;
$this->allowed1Value = $CASOSTConfig->allowed1value->value;
$this->allowed2 = $CASOSTConfig->allowed2->value;
$this->allowed2Value = $CASOSTConfig->allowed2value->value;
} else {
$response = new Response();
$response->setContent('forbidden. No config');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
// Enable debugging
// phpCAS::setDebug("/home/haris/devel/eepal/drupal/modules/casost/phpcas.log");
......@@ -109,12 +111,13 @@ class CASLogout extends ControllerBase
$user = reset($users);
if (!$user) {
$this->logger->warning("user not found");
$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;
}
// phpCAS::handleLogoutRequests();
......@@ -127,6 +130,7 @@ class CASLogout extends ControllerBase
$response->setContent('logout successful');
$response->setStatusCode(Response::HTTP_OK);
$response->headers->set('Content-Type', 'application/json');
return $response;
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
......@@ -134,8 +138,8 @@ class CASLogout extends ControllerBase
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}
}
<?php
/*
* A RedirectResponse object with cookie sending
*/
namespace Drupal\casost\Controller;
use Symfony\Component\HttpFoundation\Cookie;
// use Symfony\Component\HttpFoundation\RedirectResponse;
use \Drupal\Core\Routing\TrustedRedirectResponse;
/**
* RedirectResponseWithCookie represents an HTTP response doing a redirect and sending cookies.
*/
class RedirectResponseWithCookieExt extends TrustedRedirectResponse
{
/**
* Creates a redirect response so that it conforms to the rules defined for a redirect status code.
*
* @param string $url The URL to redirect to
* @param integer $status The status code (302 by default)
* @param Symfony\Component\HttpFoundation\Cookie[] $cookies An array of Cookie objects
*/
public function __construct($url, $status = 302, $cookies = array ())
{
parent::__construct($url, $status);
foreach ($cookies as $cookie)
{
if (!$cookie instanceof Cookie)
{
throw new \InvalidArgumentException(sprintf('Third parameter is not a valid Cookie object.'));
}
$this->headers->setCookie($cookie);
}
}
}
......@@ -7,7 +7,7 @@ epal.user.send_verification_code:
requirements:
_user_is_logged_in: 'TRUE'
epal.user.verify_verification_code:
path: '/epal/user/verifyvercode'
path: '/epal/user/verifyvercode'
options:
_auth: [ 'basic_auth' ]
defaults:
......@@ -156,3 +156,19 @@ epal.ministry.report1:
_controller: '\Drupal\epal\Controller\ReportsCreator::makeReportCompleteness'
requirements:
_user_is_logged_in: 'TRUE'
regionview:
path: '/epal/ScoolperPerf/{perfectureId}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getSchoolsPerPerfetcure'
requirements:
_user_is_logged_in: 'TRUE'
coursesperschools:
path: '/epal/CoursesperSch/{schoolid}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getCoursesPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
\ No newline at end of file
......@@ -34,13 +34,14 @@ class CurrentUser extends ControllerBase
$container->get('entity_type.manager'),
$container->get('database'),
$container->get('logger.factory')
);
);
}
public function getLoginInfo(Request $request)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
// echo("authtoken in controller=" . $authToken);
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if (!$user) {
......@@ -51,14 +52,14 @@ class CurrentUser extends ControllerBase
$userRoles = $user->getRoles();
foreach ($userRoles as $userRole) {
if ($userRole === 'epal') {
if (($userRole === 'epal') || ($userRole === 'regioneduadmin') || ($userRole === 'eduadmin')) {
return $this->respondWithStatus([
'name' => $user->mail->value,
'title' => $user->init->value,
], Response::HTTP_OK);
} else if ($userRole === 'applicant') {
break;
}
}
}
......
......@@ -402,6 +402,179 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit,$schoolid
public function getSchoolsPerPerfetcure(Request $request, $perfectureId)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user)
{
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $perfectureId ));
if ($schools)
{
$list = array();
foreach ($schools as $object) {
$status = $this->returnstatus(147);
$list[] = array(
'id' =>$object -> id(),
'name' => $object -> name ->value,
'status' => $status
);
$i++;
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else
{
return $this->respondWithStatus([
'message' => t("Perfecture not found!"),
], Response::HTTP_FORBIDDEN);
}
}
else
{
return $this->respondWithStatus([
'message' => t("User not found!"),
], Response::HTTP_FORBIDDEN);
}
}
public function getCoursesPerSchool(Request $request, $schoolid)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user)
{
$list= array();
$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 ));
$list = array();
foreach ($CourseA as $object) {
$list[] = array(
'id' => '1',
'name' => 'Α Λυκείου',
'size' => sizeof($studentPerSchool),
'categ' => $categ,
'classes' => 1,
'limitdown' => $limit,
);
} }
$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 ));
$list[] = array(
'id' => $object -> sector_id -> entity -> id(),
'name' => 'Β Λυκείου '.$object -> sector_id -> entity-> get('name')->value,
'size' => sizeof($studentPerSchool),
'categ' => $categ,
'classes' => 2,
'limitdown' => $limit,
);
}
}
$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 ));
$list[] = array(
'id'=> $object -> specialty_id -> entity -> id(),
'name' => 'Γ Λυκείου '.$object -> specialty_id -> entity-> get('name')->value,
'size' => sizeof($studentPerSchool),
'categ' => $categ,
'classes' => 3,
'limitdown' => $limit,
);
}
}
if ($CourseA || $CourseB || $CourseC)
{
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else
{
return $this->respondWithStatus([
'message' => t("Perfecture not found!"),
], Response::HTTP_FORBIDDEN);
}
}
else
{
return $this->respondWithStatus([
'message' => t("User not found!"),
], Response::HTTP_FORBIDDEN);
}
}
public function returnstatus($id)
{
if ($id == 147)
return true ;
return false;
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
......
......@@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Symfony\Component\HttpFoundation\Cookie;
require ('RedirectResponseWithCookie.php');
require ('RedirectResponseWithCookieExt.php');
class CBController extends ControllerBase
{
......@@ -65,7 +65,21 @@ class CBController extends ControllerBase
public function loginCB(Request $request)
{
$ostauthConfigs = $this->entityTypeManager->getStorage('oauthost_config')->loadByProperties(array('name' => 'oauthost_taxisnet_config'));
$oauthostSessions = $this->entityTypeManager->getStorage('oauthost_session')->loadByProperties(array('name' => $request->query->get('sid_ost')));
$this->oauthostSession = reset($oauthostSessions);
$this->logger->warning('$configRowName=gjvjvjgvjhvjhv'.'***sid='.$this->oauthostSession->id());
if ($this->oauthostSession) {
$this->requestToken = $this->oauthostSession->request_token->value;
$this->requestTokenSecret = $this->oauthostSession->request_token_secret->value;
$configRowName = $this->oauthostSession->configrowname->value;
} else {
$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;
......@@ -86,18 +100,7 @@ class CBController extends ControllerBase
return $response;
}
$oauthostSessions = $this->entityTypeManager->getStorage('oauthost_session')->loadByProperties(array('name' => $request->query->get('sid_ost')));
$this->oauthostSession = reset($oauthostSessions);
if ($this->oauthostSession) {
$this->requestToken = $this->oauthostSession->request_token->value;
$this->requestTokenSecret = $this->oauthostSession->request_token_secret->value;
} else {
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$authToken = $request->query->get('oauth_token');
$authVerifier = $request->query->get('oauth_verifier');
......@@ -106,13 +109,21 @@ class CBController extends ControllerBase
$epalToken = $this->authenticatePhase2($request, $authToken, $authVerifier);
if ($epalToken) {
$cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', 'student', 0, '/', null, false, false);
if ('oauthost_taxisnet_config' === $configRowName) {
/* $this->logger->notice('$configRowName='.$configRowName.'***url='.$this->redirect_url);
$cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', 'student', 0, '/', null, false, false); */
return new RedirectResponse($this->redirect_url . $epalToken.'&auth_role=student', 302, []);
} else {
// $this->logger->notice('***url2='.$this->redirect_url);
return new RedirectResponseWithCookieExt($this->redirect_url . $epalToken.'&auth_role=student', 302, []);
}
return new RedirectResponseWithCookie($this->redirect_url, 302, array ($cookie, $cookie2));
// return new RedirectResponse($this->redirect_url . $epalToken.'&auth_role=student', 302, []);
} else {
$this->logger->notice('epalToken false');
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
......@@ -144,6 +155,8 @@ class CBController extends ControllerBase
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();
......@@ -216,7 +229,10 @@ class CBController extends ControllerBase
}
}
$this->oauthostSession->delete();
$this->oauthostSession->set('authtoken', $epalToken);
$this->oauthostSession->save();
// $this->oauthostSession->delete();
return $epalToken;
} catch (OAuthException $e) {
......
......@@ -56,7 +56,11 @@ class OAuthLogin extends ControllerBase
public function loginGo(Request $request)
{
$ostauthConfigs = $this->entityTypeManager->getStorage('oauthost_config')->loadByProperties(array('name' => 'oauthost_taxisnet_config'));
$configRowName = 'oauthost_taxisnet_config';
$configRowId = $request->query->get('config');
if ($configRowId)
$configRowName = $configRowName . '_' . $configRowId;
$ostauthConfigs = $this->entityTypeManager->getStorage('oauthost_config')->loadByProperties(array('name' => $configRowName));
$ostauthConfig = reset($ostauthConfigs);
if ($ostauthConfig) {
$this->consumer_key = $ostauthConfig->consumer_key->value;
......@@ -85,11 +89,15 @@ class OAuthLogin extends ControllerBase
$requestToken = $oauth->getRequestToken($this->request_token_url, $this->callback_url . '?sid_ost=' . $uniqid);
// store auth token
// $this->logger->warning($request->headers->get('referer'));
$oauthostSession = $this->entityTypeManager()->getStorage('oauthost_session')->create(array(
// 'langcode' => $language_interface->getId(),
'langcode' => 'el',
'user_id' => \Drupal::currentUser()->id(),
'name' => $uniqid,
'referer' => $request->headers->get('referer'),
'configrowname' => $configRowName,
'authtoken' => '---',
'request_token' => $requestToken['oauth_token'],
'request_token_secret' => $requestToken['oauth_token_secret'],
'status' => 1
......
......@@ -56,9 +56,24 @@ class OAuthLogout extends ControllerBase
public function logoutGo(Request $request)
{
$trx = $this->connection->startTransaction();
try {
$ostauthConfigs = $this->entityTypeManager->getStorage('oauthost_config')->loadByProperties(array('name' => 'oauthost_taxisnet_config'));
$user = null;
$username = $request->headers->get('PHP_AUTH_USER');
$oauthostSessions = $this->entityTypeManager->getStorage('oauthost_session')->loadByProperties(array('authtoken' => $username));
$this->oauthostSession = reset($oauthostSessions);
if ($this->oauthostSession) {
$configRowName = $this->oauthostSession->configrowname->value;
} else {
$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;
......@@ -79,8 +94,7 @@ class OAuthLogout extends ControllerBase
return $response;