Commit 843dead1 authored by Χάρης Παπαδόπουλος's avatar Χάρης Παπαδόπουλος
Browse files

fixed logout session issues

parent 62aca96a
...@@ -134,13 +134,14 @@ class CASLogout extends ControllerBase ...@@ -134,13 +134,14 @@ class CASLogout extends ControllerBase
// phpCAS::logout(array('url'=>$this->redirectUrl)); // phpCAS::logout(array('url'=>$this->redirectUrl));
// phpCAS::logout(); // phpCAS::logout();
// session_unset(); session_unset();
// session_destroy(); session_destroy();
$this->logger->warning("hello from logout"); \Drupal::service('page_cache_kill_switch')->trigger();
// \Drupal::service('page_cache_kill_switch')->trigger(); // phpCAS::logoutWithRedirectServiceAndUrl('https://sso-test.sch.gr/logout','');
// header('Location: '.'https://sso-test.sch.gr/login?service=https%3A%2F%2Feduslim2.minedu.gov.gr%2Fdrupal%2Fcas%2Flogin%3Fconfig%3D2');
// header('Location: https://sso-test.sch.gr/logout'); // header('Location: https://sso-test.sch.gr/logout');
// exit; // exit(0);
// return new RedirectResponseWithCookieExt("https://sso-test.sch.gr/logout", 302, []); // return new RedirectResponseWithCookieExt("https://sso-test.sch.gr/logout", 302, []);
return $response; return $response;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
......
...@@ -134,6 +134,9 @@ class OAuthLogout extends ControllerBase ...@@ -134,6 +134,9 @@ class OAuthLogout extends ControllerBase
$response->headers->set('Content-Type', 'application/json'); $response->headers->set('Content-Type', 'application/json');
return $response; return $response;
} }
session_unset();
session_destroy();
\Drupal::service('page_cache_kill_switch')->trigger();
$response = new Response(); $response = new Response();
$response->setContent('logout successful'); $response->setContent('logout successful');
$response->setStatusCode(Response::HTTP_OK); $response->setStatusCode(Response::HTTP_OK);
......
...@@ -13,6 +13,8 @@ import { IAppState } from '../store/store'; ...@@ -13,6 +13,8 @@ import { IAppState } from '../store/store';
import { ILoginInfo, ILoginInfoToken } from '../store/logininfo/logininfo.types'; import { ILoginInfo, ILoginInfoToken } from '../store/logininfo/logininfo.types';
import { LOGININFO_INITIAL_STATE } from '../store/logininfo/logininfo.initial-state'; import { LOGININFO_INITIAL_STATE } from '../store/logininfo/logininfo.initial-state';
import { SCHOOL_ROLE, STUDENT_ROLE, PDE_ROLE, DIDE_ROLE, MINISTRY_ROLE } from '../constants'; import { SCHOOL_ROLE, STUDENT_ROLE, PDE_ROLE, DIDE_ROLE, MINISTRY_ROLE } from '../constants';
import { CookieService } from 'ngx-cookie';
const HEADER = { headers: new Headers({ 'Content-Type': 'application/json' }) }; const HEADER = { headers: new Headers({ 'Content-Type': 'application/json' }) };
...@@ -27,9 +29,11 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -27,9 +29,11 @@ export class HelperDataService implements OnInit, OnDestroy {
constructor( constructor(
private http: Http, private http: Http,
private _ngRedux: NgRedux<IAppState>) { private _ngRedux: NgRedux<IAppState>,
private _cookieService:CookieService) {
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE); this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
}; };
ngOnInit() { ngOnInit() {
...@@ -421,14 +425,8 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -421,14 +425,8 @@ export class HelperDataService implements OnInit, OnDestroy {
}); });
let headers = new Headers({ let headers = new Headers({
//"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
"Content-Type": "application/json", "Content-Type": "application/json",
// "Accept": "*/*",
// "Access-Control-Allow-Credentials": "true",
// "Access-Control-Allow-Origin": "*",
//"X-CSRF-Token": "EoAZ0APpIbbewK5MNzRrCFkvEeZZoGQsBslWFTrZ8bI",
// "X-oauth-enabled": "true",
// "X-Auth-Token": this.authToken
}); });
if (this.authRole === MINISTRY_ROLE) if (this.authRole === MINISTRY_ROLE)
...@@ -437,8 +435,23 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -437,8 +435,23 @@ export class HelperDataService implements OnInit, OnDestroy {
this.createAuthorizationHeader(headers); this.createAuthorizationHeader(headers);
let options = new RequestOptions({ headers: headers, withCredentials: true }); let options = new RequestOptions({ headers: headers, withCredentials: true });
let logoutRoute = '/oauth/logout'; let logoutRoute = '/oauth/logout';
if (this.authRole === SCHOOL_ROLE || this.authRole === PDE_ROLE || this.authRole === DIDE_ROLE) if (this.authRole === SCHOOL_ROLE || this.authRole === PDE_ROLE || this.authRole === DIDE_ROLE) {
logoutRoute = '/cas/logout'; logoutRoute = '/cas/logout';
return new Promise((resolve, reject) => {
this.http.get(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, options)
.map(response => response)
.subscribe(data => {
this._cookieService.removeAll();
resolve(data);
}, // put the data returned from the server in our variable
error => {
console.log("Error Logout"); // in case of failure show this message
reject("Error Logout");
},
() => console.log("Logging out"));//run this code in all cases); */
});
}
else if (this.authRole === MINISTRY_ROLE) else if (this.authRole === MINISTRY_ROLE)
logoutRoute = '/ministry/logout'; logoutRoute = '/ministry/logout';
...@@ -446,6 +459,7 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -446,6 +459,7 @@ export class HelperDataService implements OnInit, OnDestroy {
this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, {}, options) this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, {}, options)
.map(response => response) .map(response => response)
.subscribe(data => { .subscribe(data => {
this._cookieService.removeAll();
resolve(data); resolve(data);
}, // put the data returned from the server in our variable }, // put the data returned from the server in our variable
error => { error => {
......
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