Commit 2e84628d authored by Open Source Developer's avatar Open Source Developer

conflic

parents 8575ae21 52fe44e2
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -13,6 +13,8 @@ use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Cookie;
require ('RedirectResponseWithCookie.php');
class CASLogin extends ControllerBase
{
......@@ -21,6 +23,7 @@ class CASLogin extends ControllerBase
protected $serverHostname;
protected $serverPort;
protected $serverUri;
protected $redirectUrl;
protected $changeSessionId;
protected $CASServerCACert;
protected $CASServerCNValidate;
......@@ -75,6 +78,7 @@ class CASLogin extends ControllerBase
$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;
......@@ -175,8 +179,12 @@ class CASLogin extends ControllerBase
// $this->logger->warning('cn=' . $filterAttribute('cn'));
$epalToken = $this->authenticatePhase2($request, $CASUser, $filterAttribute('cn'));
if ($epalToken) {
$cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', 'director', 0, '/', null, false, false);
return new RedirectResponse('/angular/eepal-front/dist/#/school?auth_token=' . $epalToken.'&auth_role=director', 302, []);
return new RedirectResponseWithCookie($this->redirectUrl, 302, array ($cookie, $cookie2));
// $headers = array("auth_token" => $epalToken, "auth_role" => "director");
// return new RedirectResponse($this->redirectUrl, 302, $headers);
} else {
$response = new Response();
$response->setContent('forbidden');
......
......@@ -70,6 +70,7 @@ class CASLogout extends ControllerBase
$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;
......@@ -94,7 +95,7 @@ class CASLogout extends ControllerBase
// Enable debugging
// phpCAS::setDebug("/home/haris/devel/eepal/drupal/modules/casost/phpcas.log");
// Enable verbose error messages. Disable in production!
//phpCAS::setVerbose(true);
// phpCAS::setVerbose(true);
// Initialize phpCAS
phpCAS::client($this->serverVersion,
......@@ -116,15 +117,15 @@ class CASLogout extends ControllerBase
return $response;
}
// phpCAS::handleLogoutRequests();
// phpCAS::logout();
// phpCAS::logoutWithRedirectService('http://eduslim2.minedu.gov.gr/dist/#/school');
session_unset();
session_destroy();
$user->setPassword(uniqid('pw'));
$user->save();
$response = new Response();
$response->setContent('logout successful');
$response->setStatusCode(Response::HTTP_OK);
$response->headers->set('Content-Type', 'application/json');
$this->logger->warning("/dist/#/school?auth_token=&auth_role=");
// return new RedirectResponse('/dist/#/school?auth_token=&auth_role=', 302, []);
return $response;
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
......
<?php
/*
* A RedirectResponse object with cookie sending
*/
namespace Drupal\casost\Controller;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* RedirectResponseWithCookie represents an HTTP response doing a redirect and sending cookies.
*/
class RedirectResponseWithCookie extends RedirectResponse
{
/**
* 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);
}
}
}
......@@ -290,6 +290,26 @@ class CASOSTConfig extends ContentEntityBase implements CASOSTConfigInterface
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['redirecturl'] = BaseFieldDefinition::create('string')
->setLabel(t('Redirect Url'))
->setDescription(t('Redirect Url'))
->setSettings(array(
'max_length' => 200,
'text_processing' => 0,
))
->setDefaultValue('/dist/#/school')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['changesessionid'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Change Session Id'))
->setDescription(t('A boolean indicating whether we change session id.'))
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -105,9 +105,9 @@ confirmstudents:
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::ConfirmStudents'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
studentperschool:
path: '/epal/studentperSchool/{epalId}/{selectId}/{classId}'
path: '/epal/studentperSchool/{epalId}/{selectId}/{classId}/{limitdown}/{limitup}'
options:
_auth: [ 'basic_auth' ]
defaults:
......@@ -121,5 +121,12 @@ savecapacity:
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::SaveCapacity'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.log_in_go:
path: '/ministry/login'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\MinistryLogin::loginGo'
requirements:
_user_is_logged_in: 'TRUE'
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -155,7 +155,7 @@ public function getSpecialPerSchool(Request $request, $epalId , $sectorId)
}
public function getStudentPerSchool(Request $request, $epalId , $selectId, $classId)
public function getStudentPerSchool(Request $request, $epalId , $selectId, $classId, $limitdown, $limitup)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
......@@ -192,36 +192,49 @@ public function getStudentPerSchool(Request $request, $epalId , $selectId, $clas
if ($studentPerSchool) {
$list = array();
foreach ($studentPerSchool as $object)
{
$studentId = $object -> id() ;
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $studentId));
$epalStudent = reset($epalStudents);
$i = 0;
if ($epalStudents) {
$list[] = array(
'id' => $epalStudent -> id(),
'name' => $epalStudent -> name ->value,
'studentsurname' => $epalStudent -> studentsurname ->value,
'fatherfirstname' => $epalStudent -> fatherfirstname ->value,
'fathersurname' =>$epalStudent -> fathersurname ->value,
'motherfirstname' => $epalStudent -> motherfirstname ->value,
'mothersurname' =>$epalStudent -> mothersurname ->value,
'birthdate' =>$epalStudent -> birthdate ->value,
);
$i++;
$i = 0;
if ($limitdown==$limitup && $limitup == 0)
{
$list=array(
'id' => sizeof($studentPerSchool)
);
}
else
{
foreach ($studentPerSchool as $object)
{
$studentId = $object -> id() ;
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $studentId));
$epalStudent = reset($epalStudents);
if ($epalStudents) {
if ($i >= $limitdown && $i < $limitup)
{
$list[] = array(
'i' => $i,
'id' => $epalStudent -> id(),
'name' => $epalStudent -> name ->value,
'studentsurname' => $epalStudent -> studentsurname ->value,
'fatherfirstname' => $epalStudent -> fatherfirstname ->value,
'fathersurname' =>$epalStudent -> fathersurname ->value,
'motherfirstname' => $epalStudent -> motherfirstname ->value,
'mothersurname' =>$epalStudent -> mothersurname ->value,
'birthdate' =>$epalStudent -> birthdate ->value,
);
}
$i++;
}
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("No students found!!!"),
], Response::HTTP_OK);
$list = array();
return $this->respondWithStatus($list, Response::HTTP_OK);
}
......
File mode changed from 100644 to 100755
<?php
namespace Drupal\epal\Controller;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\user\Entity\User;
//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;
class MinistryLogin extends ControllerBase
{
//protected $entity_query;
protected $entityTypeManager;
protected $logger;
//protected $connection;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
//QueryFactory $entity_query,
// $connection,
LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
//$this->entity_query = $entity_query;
//$this->connection = $connection;
$this->logger = $loggerChannel->get('epal');
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity.manager'),
//$container->get('entity.query'),
//$container->get('database'),
$container->get('logger.factory')
);
}
public function loginGo(Request $request)
{
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
], Response::HTTP_METHOD_NOT_ALLOWED);
}
try {
//user validation
//Note: $authToken = $postData->username
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if (!$user) {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
//user role validation
//$user = \Drupal\user\Entity\User::load($user->id());
$roles = $user->getRoles();
$validRole = false;
foreach ($roles as $role)
if ($role === "ministry") {
$validRole = true;
break;
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
$currentRoleName = "supervisor";
$postData = null;
if ($content = $request->getContent()) {
$postData = json_decode($content);
//return new RedirectResponse("/drupal-8.2.6/eepal/dist/" . '?auth_token=' . $postData->username .'&auth_role=supervisor', 302, []);
return $this->respondWithStatus([
'auth_token' => $postData->username,
'userpassword' => $postData->userpassword,
'auth_role' => $currentRoleName,
], Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("post with no data"),
], Response::HTTP_BAD_REQUEST);
}
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
return $res;
}
}
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755