casost module: redirect response with cookie, destroy session on logout. Front...

casost module: redirect response with cookie, destroy session on logout. Front end: retrieve cookie data
parent 6252fe24
......@@ -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);
}
}
}
// 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';
}
}
......@@ -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 SchoolHome 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 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() {
}
......
......@@ -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"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment