Commit 4da93296 authored by Open Source Developer's avatar Open Source Developer

package.json

parents 11ecb322 2b3a433f
......@@ -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
{
......@@ -177,7 +179,12 @@ class CASLogin extends ControllerBase
// $this->logger->warning('cn=' . $filterAttribute('cn'));
$epalToken = $this->authenticatePhase2($request, $CASUser, $filterAttribute('cn'));
if ($epalToken) {
return new RedirectResponse($this->redirectUrl . '?auth_token=' . $epalToken.'&auth_role=director', 302, []);
$cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', 'director', 0, '/', null, false, false);
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;
......@@ -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);
}
}
}
......@@ -105,7 +105,7 @@ 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}/{limitdown}/{limitup}'
options:
......@@ -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'
<?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;
}
}
langcode: el
status: true
dependencies: { }
id: ministry
label: ministry
weight: 4
is_admin: null
permissions:
- 'add epal student course field entities'
- 'add epal student epal chosen entities'
- 'add epal student sector field entities'
- 'add epal users entities'
- 'delete epal student course field entities'
- 'delete epal student epal chosen entities'
- 'delete epal student sector field entities'
- 'delete epal users entities'
- 'edit epal class limits entities'
- 'edit epal student course field entities'
- 'edit epal student epal chosen entities'
- 'edit epal student sector field entities'
- 'edit epal users entities'
- 'view published epal student course field entities'
- 'view published epal student epal chosen entities'
- 'view published epal student sector field entities'
- 'view published epal users entities'
- 'view unpublished epal student course field entities'
- 'view unpublished epal student epal chosen entities'
- 'view unpublished epal student sector field entities'
- 'view unpublished epal users entities'
- 'view published eepal admin area entities'
- 'view published eepal prefecture entities'
- 'view published eepal region entities'
- 'view published eepal school entities'
- 'view published eepal sectors entities'
- 'view published eepal sectors in epal entities'
- 'view published eepal specialties in epal entities'
- 'view published eepal specialty entities'
- 'view unpublished eepal admin area entities'
- 'view unpublished eepal prefecture entities'
- 'view unpublished eepal region entities'
- 'view unpublished eepal school entities'
- 'view unpublished eepal sectors entities'
- 'view unpublished eepal sectors in epal entities'
- 'view unpublished eepal specialties in epal entities'
- 'view unpublished eepal specialty entities'
......@@ -15,6 +15,8 @@ use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Symfony\Component\HttpFoundation\Cookie;
require ('RedirectResponseWithCookie.php');
class CBController extends ControllerBase
{
......@@ -104,7 +106,12 @@ class CBController extends ControllerBase
$epalToken = $this->authenticatePhase2($request, $authToken, $authVerifier);
if ($epalToken) {
return new RedirectResponse($this->redirect_url . $epalToken.'&auth_role=student', 302, []);
$cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', 'student', 0, '/', null, false, false);
return new RedirectResponseWithCookie($this->redirect_url, 302, array ($cookie, $cookie2));
// return new RedirectResponse($this->redirect_url . $epalToken.'&auth_role=student', 302, []);
} else {
$response = new Response();
$response->setContent('forbidden');
......
<?php
/*
* A RedirectResponse object with cookie sending
*/
namespace Drupal\oauthost\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);
}
}
}
......@@ -11,7 +11,7 @@ export class LoginInfoActions {
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService) {}
getloginInfo = (loginInfo) => {
return this._hds.getCurrentUser(loginInfo.auth_token, loginInfo.auth_role).then (loginInfos => {
return this._ngRedux.dispatch({
......@@ -23,6 +23,16 @@ export class LoginInfoActions {
});
}
saveMinEduloginInfo = (loginInfos) => {
return this._ngRedux.dispatch({
type: LOGININFO_SAVE,
payload: {
loginInfos
}
});
};
initLoginInfo = () => {
return this._ngRedux.dispatch({
type: LOGININFO_INIT,
......
......@@ -2,6 +2,6 @@ export const API_ENDPOINT = 'http://localhost/drupal-8.2.6';
export class AppSettings {
public static get API_ENDPOINT(): string {
return 'http://localhost/drupal-8.2.5';
return 'http://localhost/drupal-8.2.6';
}
}
......@@ -5,6 +5,7 @@ import 'core-js/es7/reflect';
import { NgModule } from '@angular/core';
import { NgReduxModule, DevToolsExtension, NgRedux } from 'ng2-redux';
import {BrowserModule} from '@angular/platform-browser';
import { CookieModule } from 'ngx-cookie';
import {
FormsModule,
ReactiveFormsModule,
......@@ -63,7 +64,8 @@ class MyLocalization extends NgLocalization {
Ng2SmartTableModule,
NgReduxModule,
ModalModule.forRoot(),
AlertModule.forRoot()
AlertModule.forRoot(),
CookieModule.forRoot()
],
declarations: [
Main, FooterComponent, HeaderComponent, NavbarComponent, MainComponent,
......
......@@ -6,6 +6,7 @@ import { NgRedux, select } from 'ng2-redux';
import { Observable } from 'rxjs/Rx';
import { IAppState } from '../store/store';
import { HelperDataService } from '../services/helper-data-service';
import { CookieService } from 'ngx-cookie';
import {
FormBuilder,
FormGroup,
......@@ -49,7 +50,8 @@ export default class Home implements OnInit {
private _ngRedux: NgRedux<IAppState>,
private activatedRoute: ActivatedRoute,
private _hds: HelperDataService,
private router: Router
private router: Router,
private _cookieService:CookieService
) {
this.authToken = '';
this.authRole = '';
......@@ -59,6 +61,14 @@ export default class Home implements OnInit {
};
ngOnInit() {
this.authToken = this.getCookie('auth_token');
this.authRole = this.getCookie('auth_role');
if (this.authToken && this.authRole) {
this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole });
this.removeCookie('auth_token');
this.removeCookie('auth_role');
}
this.loginInfo$ = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
......@@ -74,7 +84,7 @@ export default class Home implements OnInit {
});
// subscribe to router event
this.activatedRoute.queryParams.subscribe((params: Params) => {
/* this.activatedRoute.queryParams.subscribe((params: Params) => {
if (params) {
this.authToken = params['auth_token'];
this.authRole = params['auth_role'];
......@@ -83,8 +93,17 @@ export default class Home implements OnInit {
if (this.authToken && this.authRole)
this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole });
});
}); */
}
getCookie(key: string){
return this._cookieService.get(key);
}
removeCookie(key: string){
return this._cookieService.remove(key);
}
checkvalidation() {
}
......
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import {Observable} from "rxjs/Observable";
import {Http, Headers, RequestOptions} from '@angular/http';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import {
FormBuilder,
FormGroup,
FormControl,
FormArray,
Validators,
} from '@angular/forms';
import { API_ENDPOINT } from '../../app.settings';
@Component({
selector: 'minister-view',
template: `
<div>
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/epal/distribution" #form>
<button type="submit" class="btn-primary btn-md" (click)="form.submit()" [disabled]="true">
Εκτέλεση Κατανομής Μαθητών
</button>
</form>
</div>
`
})
@Injectable() export default class MinisterView implements OnInit, OnDestroy {
public formGroup: FormGroup;
private apiEndPoint = API_ENDPOINT;
constructor(private fb: FormBuilder,
private _hds: HelperDataService,
private activatedRoute: ActivatedRoute,
private router: Router) {
this.formGroup = this.fb.group({
});
}
ngOnDestroy() {
}
ngOnInit() {
}
runDistribution() {
}
}
import {Router, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core';
import { LoginInfoActions } from '../actions/logininfo.actions';
import { ILoginInfo } from '../store/logininfo/logininfo.types';
import { NgRedux, select } from 'ng2-redux';
import { Observable } from 'rxjs/Rx';
import { IAppState } from '../store/store';
import { HelperDataService } from '../services/helper-data-service';
import {Http, Response, RequestOptions} from '@angular/http';
import {
FormBuilder,
FormGroup,
FormControl,
FormArray,
Validators
} from '@angular/forms';
import { API_ENDPOINT } from '../app.settings';
@Component({
selector: 'ministry-home',
template: `
<div>
<form novalidate [formGroup]="userDataGroup" #form>
<div class="form-group">
<label for="minedu_username">Όνομα διαχειριστή</label><input class="form-control" type="text" formControlName="minedu_username">
</div>
<div class="alert alert-danger" *ngIf="userDataGroup.get('minedu_username').touched && userDataGroup.get('minedu_username').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό!
</div>
<div class="form-group">
<label for="minedu_userpassword">Κωδικός πρόσβασης</label><input class="form-control" type="password" formControlName="minedu_userpassword">
</div>
<div class="alert alert-danger" *ngIf="userDataGroup.get('minedu_userpassword').touched && userDataGroup.get('minedu_userpassword').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό!
</div>
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<div class="row" style="min-height: 300px; margin-top: 100px;">
<div *ngIf="!mineduUsername" class="col-md-8 offset-md-4">
<button type="submit" class="btn-primary btn-lg" (click)="submitCredentials()" [disabled]="userDataGroup.invalid">
Είσοδος<span class="glyphicon glyphicon-menu-right"></span>
</button>
</div>
</div>
</form>
</div>
`
})
export default class MinistryHome implements OnInit {
public userDataGroup: FormGroup;
private authRole: string;
private mineduUsername: string;
private mineduPassword: string;
private loginInfo$: Observable<ILoginInfo>;
private apiEndPoint = API_ENDPOINT;
constructor(private fb: FormBuilder,
private _ata: LoginInfoActions,
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService,
private http: Http,
private router: Router
) {
this.mineduUsername = '';
this.mineduPassword = '';
this.authRole = '';
this.userDataGroup = this.fb.group({
minedu_username: ['minedu01', [Validators.required]],
minedu_userpassword: ['12345678', [Validators.required]],
});
};
ngOnInit() {
this.loginInfo$ = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {