diff --git a/drupal/modules/casost/src/Controller/CASLogin.php b/drupal/modules/casost/src/Controller/CASLogin.php index e76d04848f747c8c020a77cc7a9ebe6e15ebad60..d85a62acd7141b228cab956a3717fb9ff295baed 100644 --- a/drupal/modules/casost/src/Controller/CASLogin.php +++ b/drupal/modules/casost/src/Controller/CASLogin.php @@ -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'); diff --git a/drupal/modules/casost/src/Controller/CASLogout.php b/drupal/modules/casost/src/Controller/CASLogout.php index 639f327adcd8da6877aca917ca3f64876dd95adc..7385ce7f523febb5fb6ebe4870cfb92e0c92aa47 100644 --- a/drupal/modules/casost/src/Controller/CASLogout.php +++ b/drupal/modules/casost/src/Controller/CASLogout.php @@ -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()); diff --git a/drupal/modules/casost/src/Controller/RedirectResponseWithCookie.php b/drupal/modules/casost/src/Controller/RedirectResponseWithCookie.php new file mode 100644 index 0000000000000000000000000000000000000000..c0e0e3d56e8bcfd6847111bd612ecf1abb2dc973 --- /dev/null +++ b/drupal/modules/casost/src/Controller/RedirectResponseWithCookie.php @@ -0,0 +1,38 @@ +headers->setCookie($cookie); + } + } +} diff --git a/package.json b/package.json index cb45897f5c53008ff7e429c4b17c1696ca35e158..a71d8323282ce40cf8751da366886e52d36b57e7 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "ng2-bootstrap": "^1.4.2", "ng2-redux": "^5.1.0", "ng2-smart-table": "^0.4.0-5", + "ngx-cookie": "^1.0.0", "ngx-uploader": "^2.2.5", "raw-loader": "^0.5.1", "redux": "^3.6.0", diff --git a/source/app.settings.ts b/source/app.settings.ts index d1ebeedb0cbe698d6e15cec5be6f8632add2297e..91d0eac52125ed1a214b1ae8e571b12c7a8fea11 100644 --- a/source/app.settings.ts +++ b/source/app.settings.ts @@ -1,8 +1,8 @@ // export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal'; -export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal-8.2.6'; +export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal'; export class AppSettings { public static get API_ENDPOINT(): string { // return 'http://eduslim2.minedu.gov.gr/drupal'; - return 'http://eduslim2.minedu.gov.gr/drupal-8.2.6'; + return 'http://eduslim2.minedu.gov.gr/drupal'; } } diff --git a/source/app.ts b/source/app.ts index d475f40013db78e0ab11567c73e2329636ab4e6a..f3af806e1ab6d21792864636b5900676ce1650dc 100644 --- a/source/app.ts +++ b/source/app.ts @@ -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, diff --git a/source/components/school.home.ts b/source/components/school.home.ts index 46a8ff27f3712dae3894ed60e4f99e714dedf582..41e50f633870b2d6244ff6b038c6839144d65de7 100644 --- a/source/components/school.home.ts +++ b/source/components/school.home.ts @@ -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 SchoolHome implements OnInit { private _ngRedux: NgRedux, 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 SchoolHome 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) => { @@ -72,26 +82,16 @@ export default class SchoolHome implements OnInit { return state.loginInfo; }); + } - // subscribe to router event - this.activatedRoute.queryParams.subscribe((params: Params) => { - if (params) { - - this.authToken = params['auth_token']; - console.log("NIKOS1"); - console.log(this.authToken ); - - - this.authRole = params['auth_role']; - console.log("NIKOS2"); - console.log(this.authRole ); - } - - 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() { } diff --git a/source/services/helper-data-service.ts b/source/services/helper-data-service.ts index 735ac9da06b11c2c00eda64f286820df9ea7685f..20fc59b66c8f334aeb0507f14a5ec9c093021819 100644 --- a/source/services/helper-data-service.ts +++ b/source/services/helper-data-service.ts @@ -428,6 +428,7 @@ export class HelperDataService implements OnInit, OnDestroy { "Content-Type": "application/json", "Accept": "*/*", "Access-Control-Allow-Credentials": "true", + "Access-Control-Allow-Origin": "*", // "Content-Type": "text/plain", // try to skip preflight //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY" //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"