conflict resolution. Role checking in DirectorView controller

parents e4897f30 cc188496
...@@ -46,10 +46,15 @@ function epal_mail($key, &$message, $params) { ...@@ -46,10 +46,15 @@ function epal_mail($key, &$message, $params) {
$message['subject'] = t('Σύστημα υποβολής αιτήσεων εγγραφής σε ΕΠΑΛ: Επιβεβαίωση e-mail', $options); $message['subject'] = t('Σύστημα υποβολής αιτήσεων εγγραφής σε ΕΠΑΛ: Επιβεβαίωση e-mail', $options);
$message['body'][] = $params['message']; $message['body'][] = $params['message'];
break; break;
case 'massive_mail': case 'massive_mail_unallocated':
$message['from'] = \Drupal::config('system.site')->get('mail'); $message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('Μη ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options); $message['subject'] = t('Μη ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options);
$message['body'][] = $params['message']; $message['body'][] = $params['message'];
break; break;
case 'massive_mail_located':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('Ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options);
$message['body'][] = $params['message'];
break;
} }
} }
...@@ -151,7 +151,7 @@ epal.ministry.report-completeness: ...@@ -151,7 +151,7 @@ epal.ministry.report-completeness:
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.report-all-stat: epal.ministry.report-all-stat:
path: '/ministry/report-all-stat/{regionId}/{adminId}/{schId}/{classId}/{sectorId}/{courseId}' path: '/ministry/report-all-stat/{regionId}/{adminId}/{schId}/{classId}/{sectorId}/{courseId}/{finalized}'
options: options:
_auth: [ 'basic_auth' ] _auth: [ 'basic_auth' ]
defaults: defaults:
...@@ -174,12 +174,20 @@ epal.ministry.retrieve-registry-id: ...@@ -174,12 +174,20 @@ epal.ministry.retrieve-registry-id:
_controller: '\Drupal\epal\Controller\ReportsCreator::retrieveUserRegistryNo' _controller: '\Drupal\epal\Controller\ReportsCreator::retrieveUserRegistryNo'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.massive_mail: epal.ministry.massive_mail_unallocated:
path: '/ministry/send-massive-mail' path: '/ministry/send-unallocated-massive-mail'
options: options:
_auth: [ 'basic_auth' ] _auth: [ 'basic_auth' ]
defaults: defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToStudents' _controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToUnallocatedStudents'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail_located:
path: '/ministry/send-located-massive-mail'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToLocatedStudents'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.retrievesettings: epal.ministry.retrievesettings:
...@@ -203,7 +211,7 @@ epal.perfectureschools: ...@@ -203,7 +211,7 @@ epal.perfectureschools:
options: options:
_auth: [ 'basic_auth' ] _auth: [ 'basic_auth' ]
defaults: defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getSchoolsPerPerfecture' _controller: '\Drupal\epal\Controller\DirectorView::getSchools'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.coursesperschools: epal.coursesperschools:
...@@ -246,3 +254,11 @@ epal.gettypeofschool: ...@@ -246,3 +254,11 @@ epal.gettypeofschool:
_controller: '\Drupal\epal\Controller\DirectorView::gettypeofschool' _controller: '\Drupal\epal\Controller\DirectorView::gettypeofschool'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
getlimitspercourse:
path: '/epal/getlimitsperCourse/{classid}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getlimitsperCourse'
requirements:
_user_is_logged_in: 'TRUE'
...@@ -426,8 +426,7 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit) ...@@ -426,8 +426,7 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
} }
public function getSchools(Request $request)
public function getSchoolsPerPerfecture(Request $request)
{ {
$authToken = $request->headers->get('PHP_AUTH_USER'); $authToken = $request->headers->get('PHP_AUTH_USER');
...@@ -436,14 +435,32 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit) ...@@ -436,14 +435,32 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
$user = reset($users); $user = reset($users);
if ($user) if ($user)
{ {
$perfectureId = $user -> init -> value; $selectionId = $user -> init -> value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $perfectureId )); $userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if (($tmpRole === 'epal') || ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
$userRole = $tmpRole;
}
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
}
else if ($userRole === 'regioneduadmin') {
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $selectionId ));
}
else if ($userRole === 'eduadmin') {
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('edu_admin_id'=> $selectionId ));
}
if ($schools) if ($schools)
{ {
$list = array(); $list = array();
foreach ($schools as $object) { foreach ($schools as $object) {
$status = $this->returnstatus(147); $status = $this->returnstatus($object -> id());
$list[] = array( $list[] = array(
'id' =>$object -> id(), 'id' =>$object -> id(),
'name' => $object -> name ->value, 'name' => $object -> name ->value,
...@@ -595,10 +612,74 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit) ...@@ -595,10 +612,74 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
public function returnstatus($id) public function returnstatus($id)
{ {
if ($id == 147) $schoolid = $id;
return true ; $SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
return false; $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;
} }
...@@ -784,6 +865,115 @@ public function gettypeofschool(Request $request) ...@@ -784,6 +865,115 @@ public function gettypeofschool(Request $request)
} }
public function getlimitsperCourse(Request $request, $classid)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user)
{
$schoolid = $user -> init -> value;
$list= array();
$SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
$SchoolCat = reset($SchoolCats);
if ($SchoolCat){
$categ = $SchoolCat-> metathesis_region -> value;
$list = array();
if ($classid == 1)
{
$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;
}
$list[] = array(
'id' => '1',
'name' => 'Α Λυκείου',
'categ' => $categ,
'classes' => 1,
'limitdown' => $limit,
);
}
if ($classid == 2){
$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;
}
$list[] = array(
'name' => 'Β Λυκείου ',
'categ' => $categ,
'classes' => 2,
'limitdown' => $limit,
);
}
if ($classid == 3){
$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;
}
$list[] = array(
'categ' => $categ,
'classes' => 3,
'limitdown' => $limit,
);
}
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);
}
}
private function respondWithStatus($arr, $s) { private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr); $res = new JsonResponse($arr);
$res->setStatusCode($s); $res->setStatusCode($s);
......
...@@ -87,7 +87,7 @@ class MinisterSettings extends ControllerBase { ...@@ -87,7 +87,7 @@ class MinisterSettings extends ControllerBase {
//minister settings retrieve //minister settings retrieve
$config_storage = $this->entityTypeManager->getStorage('epal_config'); $config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1)); $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs); $epalConfig = reset($epalConfigs);
if (!$epalConfig) { if (!$epalConfig) {
return $this->respondWithStatus([ return $this->respondWithStatus([
...@@ -157,7 +157,7 @@ public function storeSettings(Request $request, $capacityDisabled, $directorView ...@@ -157,7 +157,7 @@ public function storeSettings(Request $request, $capacityDisabled, $directorView
} }
$config_storage = $this->entityTypeManager->getStorage('epal_config'); $config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1)); $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs); $epalConfig = reset($epalConfigs);
if (!$epalConfig) { if (!$epalConfig) {
return $this->respondWithStatus([ return $this->respondWithStatus([
......
...@@ -128,116 +128,111 @@ class CBController extends ControllerBase ...@@ -128,116 +128,111 @@ class CBController extends ControllerBase
public function authenticatePhase2($request, $authToken, $authVerifier) public function authenticatePhase2($request, $authToken, $authVerifier)
{ {
$taxis_userid = null; $taxis_userid = null;
$trx = $this->connection->startTransaction(); $trx = $this->connection->startTransaction();
try { try {
$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()); $this->logger->warning($oauth->getLastResponse());
$taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText'); $taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText');
$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_userid));
$epalUser = reset($epalUsers); $epalUser = reset($epalUsers);
$epalToken = md5(uniqid(mt_rand(), true)); $epalToken = md5(uniqid(mt_rand(), true));
if ($epalUser) { if ($epalUser) {
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id); $user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) { if ($user) {
// $user->setPassword('harispass'); $user->setPassword($epalToken);
// $user->setUsername('harisp'); $user->setUsername($epalToken);
$user->setPassword($epalToken); $user->save();
$user->setUsername($epalToken); $epalUser->set('authtoken', $epalToken);
$user->save(); $epalUser->set('accesstoken', $accessToken['oauth_token']);
$epalUser->set('authtoken', $epalToken); $epalUser->set('accesstoken_secret', $accessToken['oauth_token_secret']);
$epalUser->set('accesstoken', $accessToken['oauth_token']); $epalUser->set('requesttoken',$this->requestToken);
$epalUser->set('accesstoken_secret', $accessToken['oauth_token_secret']); $epalUser->set('requesttoken_secret', $this->requestTokenSecret);
$epalUser->set('requesttoken',$this->requestToken); $epalUser->set('timelogin', $currentTime);
$epalUser->set('requesttoken_secret', $this->requestTokenSecret); $epalUser->set('userip', $request->getClientIp());
$epalUser->set('timelogin', $currentTime);
$epalUser->set('userip', $request->getClientIp()); $epalUser->save();
}
$epalUser->save();
} }
}
if ($epalUser === null || !$epalUser) { 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;
}
} //Create a User
$this->oauthostSession->set('authtoken', $epalToken); $user = User::create();
$this->oauthostSession->save(); //Mandatory settings
// $this->oauthostSession->delete(); $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->oauthostSession->set('authtoken', $epalToken);
$this->logger->warning($e->getMessage()); $this->oauthostSession->save();
$trx->rollback(); // $this->oauthostSession->delete();
return false;
} catch (\Exception $ee) { return $epalToken;
$this->logger->warning($ee->getMessage()); } catch (OAuthException $e) {
$trx->rollback(); $this->logger->warning($e->getMessage());
return false; $trx->rollback();
} return false;
} catch (\Exception $ee) {
$this->logger->warning($ee->getMessage());
$trx->rollback();
return false;
}
return false; return false;
} }
......
...@@ -56,6 +56,27 @@ import { ...@@ -56,6 +56,27 @@ import {
</form> </form>
</div> </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">
<p>Η αποθήκευση δε μπορεί να γίνει αν δεν συμπληρώσετε όλα τα στοιχεία της φόρμας!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
</div>
</div>
</div>
</div>
<div id="capacitysaved" (onHidden)="onHidden('#capacitysaved')" <div id="capacitysaved" (onHidden)="onHidden('#capacitysaved')"
class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
...@@ -77,6 +98,9 @@ import { ...@@ -77,6 +98,9 @@ import {
</div> </div>