Add rout to logout from CAS only; add error control on frontend

parent 3c04d310
......@@ -12,3 +12,9 @@ casost.log_out_go:
_controller: '\Drupal\casost\Controller\CASLogout::logoutGo'
requirements:
_user_is_logged_in: 'TRUE'
casost.log_out_cas_go:
path: /cas/logoutcas
defaults:
_controller: '\Drupal\casost\Controller\CASLogout::logoutCasGo'
requirements:
_access: 'TRUE'
......@@ -38,11 +38,12 @@ class CASLogout extends ControllerBase
protected $connection;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel)
{
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel
) {
$this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query;
$this->connection = $connection;
......@@ -56,14 +57,13 @@ class CASLogout extends ControllerBase
$container->get('entity.query'),
$container->get('database'),
$container->get('logger.factory')
);
);
}
public function logoutGo(Request $request)
{
$configRowName = 'casost_sch_sso_config';
try {
$configRowId = $request->query->get('config');
if ($configRowId) {
$configRowName = $configRowName.'_'.$configRowId;
......@@ -136,7 +136,57 @@ class CASLogout extends ControllerBase
}
}
private function redirectForbidden($configRowName, $errorCode) {
public function logoutCasGo(Request $request)
{
$configRowName = 'casost_sch_sso_config';
try {
$configRowId = $request->query->get('config');
if ($configRowId) {
$configRowName = $configRowName.'_'.$configRowId;
}
$CASOSTConfigs = $this->entityTypeManager->getStorage('casost_config')->loadByProperties(array('name' => $configRowName));
$CASOSTConfig = reset($CASOSTConfigs);
if ($CASOSTConfig) {
$this->serverVersion = $CASOSTConfig->serverversion->value;
$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->logoutRedirectUrl = $CASOSTConfig->logoutredirecturl->value;
$this->CASServerCACert = $CASOSTConfig->casservercacert->value;
$this->CASServerCNValidate = $CASOSTConfig->casservercnvalidate->value;
$this->noCASServerValidation = $CASOSTConfig->nocasservervalidation->value;
$this->proxy = $CASOSTConfig->proxy->value;
$this->handleLogoutRequests = $CASOSTConfig->handlelogoutrequests->value;
$this->CASLang = $CASOSTConfig->caslang->value;
$this->allowed1 = $CASOSTConfig->allowed1->value;
$this->allowed1Value = $CASOSTConfig->allowed1value->value;
$this->allowed2 = $CASOSTConfig->allowed2->value;
$this->allowed2Value = $CASOSTConfig->allowed2value->value;
} else {
return $this->redirectForbidden($configRowName, '7001');
}
$response = new Response();
$response->setContent("{\"message\": \"Server logout continue\",\"next\": \"{$this->logoutRedirectUrl}\"}");
$response->setStatusCode(Response::HTTP_OK);
$response->headers->set('Content-Type', 'application/json');
session_unset();
session_destroy();
\Drupal::service('page_cache_kill_switch')->trigger();
session_start();
return $response;
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->redirectForbidden($configRowName, '8000');
}
}
private function redirectForbidden($configRowName, $errorCode)
{
session_unset();
session_destroy();
\Drupal::service('page_cache_kill_switch')->trigger();
......@@ -146,4 +196,4 @@ class CASLogout extends ControllerBase
return new RedirectResponseWithCookieExt($this->redirectUrl .'&error_code=' . $errorCode, 302, []);
}
}
}
\ No newline at end of file
}
import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, OnDestroy, Component} from '@angular/core';
import { LoginInfoActions } from '../actions/logininfo.actions';
import { ILoginInfo } from '../store/logininfo/logininfo.types';
import { LOGININFO_INITIAL_STATE } from '../store/logininfo/logininfo.initial-state';
import { NgRedux, select } from 'ng2-redux';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { IAppState } from '../store/store';
import { HelperDataService } from '../services/helper-data-service';
import { CookieService } from 'ngx-cookie';
import {
FormBuilder,
FormGroup,
FormControl,
FormArray
} from '@angular/forms';
import { Router, ActivatedRoute, Params } from "@angular/router";
import { OnInit, OnDestroy, Component } from "@angular/core";
import { LoginInfoActions } from "../actions/logininfo.actions";
import { ILoginInfo } from "../store/logininfo/logininfo.types";
import { LOGININFO_INITIAL_STATE } from "../store/logininfo/logininfo.initial-state";
import { NgRedux, select } from "ng2-redux";
import { BehaviorSubject, Subscription } from "rxjs/Rx";
import { IAppState } from "../store/store";
import { HelperDataService } from "../services/helper-data-service";
import { CookieService } from "ngx-cookie";
import { FormBuilder, FormGroup, FormControl, FormArray } from "@angular/forms";
import { API_ENDPOINT, API_ENDPOINT_PARAMS } from "../app.settings";
import { API_ENDPOINT, API_ENDPOINT_PARAMS } from '../app.settings';
@Component({
selector: 'school-home',
selector: "school-home",
template: `
<div>
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/cas/login{{apiEndPointParams}}" #form>
<!-- <input type="hidden" name="X-oauth-enabled" value="true"> -->
<div>
<div *ngIf="errorCode != undefined && errorCode != ''" style="min-height: 300px;">
<div [ngSwitch]="errorCode">
<p class="text-danger" *ngSwitchCase="5001">Προέκυψε σφάλμα κατά την διαδικασία αυθεντικοποίησης σας.</p>
<p class="text-danger" *ngSwitchCase="5002">Πρέπει να συνδεθείτε με λογαριασμό του Πανελλήνιου Σχολικού Δικτύου, για να χρησιμοποιήσετε την εφαρμογή.</p>
<p class="text-danger" *ngSwitchCase="5003">Πρέπει να συνδεθείτε με τον επίσημο λογαριασμό μονάδας στο Πανελλήνιο Σχολικό Δίκτυο, για να χρησιμοποιήσετε την εφαρμογή.</p>
<p class="text-danger" *ngSwitchCase="5004">Ο ρόλος που αντιστοιχεί στον λογαριασμό σας στο Πανελλήνιο Σχολικό Δίκτυο δεν επιτρέπεται να χρησιμοποιήσετε την εφαρμογή.</p>
<p class="text-danger" *ngSwitchCase="5005">Προέκυψε σφάλμα κατά την διαδικασία αυθεντικοποίησης σας.</p>
<p class="text-danger" *ngSwitchCase="6000">Προέκυψε σφάλμα κατά την διαδικασία αυθεντικοποίησης σας. <br/>Παρακαλώ συνδεθείτε χρησιμοποιώντας τα στοιχεία του επίσημου λογαριασμού που διαθέτει η μονάδα στο Πανελλήνιο Σχολικό Δίκτυο.</p>
<p class="text-danger" *ngSwitchDefault>Προέκυψε σφάλμα {{ errorCode }}</p>
</div>
<div class="alert alert-danger" role="alert">Για να επαναλάβετε τη διαδικασία σύνδεσης πρέπει πρώτα να αποσυνδεθείτε.</div>
<div class="row">
<div class="col-sm-4">&nbsp;</div>
<div class="col-sm-4">
<button type="submit" class="btn btn-lg btn-block isclickable" (click)="casSignOut()">Αποσύνδεση</button>
</div>
</div>
</div>
<div *ngIf="errorCode == undefined || erroCode == ''">
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/cas/login{{apiEndPointParams}}" #form>
<!-- <input type="hidden" name="X-oauth-enabled" value="true"> -->
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<div class="row" style="min-height: 300px; margin-top: 100px;">
<div *ngIf="!authToken" class="col-md-8 offset-md-4">
<button type="submit" class="btn-primary btn-lg" (click)="form.submit()">
Είσοδος μέσω Π.Σ.Δ<span class="glyphicon glyphicon-menu-right"></span>
</button>
<div *ngIf="!authToken" class="col-md-8 offset-md-4">
<button type="submit" class="btn-primary btn-lg" (click)="form.submit()">
Είσοδος μέσω Π.Σ.Δ<span class="glyphicon glyphicon-menu-right"></span>
</button>
</div>
</div>
</div>
</form>
</div>
`
</form>
</div>
</div>
`
})
export default class SchoolHome implements OnInit, OnDestroy {
public formGroup: FormGroup;
private authToken: string;
private errorCode: string;
private authRole: string;
private name: any;
private xcsrftoken: any;
......@@ -54,11 +68,12 @@ export default class SchoolHome implements OnInit, OnDestroy {
private activatedRoute: ActivatedRoute,
private _hds: HelperDataService,
private router: Router,
private _cookieService:CookieService
private _cookieService: CookieService
) {
this.authToken = '';
this.authRole = '';
this.name = '';
this.authToken = "";
this.errorCode = "";
this.authRole = "";
this.name = "";
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
this.formGroup = this.fb.group({
});
......@@ -71,28 +86,19 @@ export default class SchoolHome implements OnInit, OnDestroy {
};
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.loginInfoSub = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
state.loginInfo.reduce(({ }, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
if (this.authToken && this.authToken.length > 0) {
if (this.authRole === 'director') {
this.router.navigate(['/school/director-buttons']);
if (this.authRole === "director") {
this.router.navigate(["/school/director-buttons"]);
}
else if (this.authRole === 'pde')
this.router.navigate(['/school/perfecture-view']);
else if (this.authRole === 'dide')
this.router.navigate(['/school/eduadmin-view']);
else if (this.authRole === "pde")
this.router.navigate(["/school/perfecture-view"]);
else if (this.authRole === "dide")
this.router.navigate(["/school/eduadmin-view"]);
}
return loginInfoToken;
}, {});
......@@ -101,29 +107,49 @@ export default class SchoolHome implements OnInit, OnDestroy {
return state.loginInfo;
}).subscribe(this.loginInfo$);
// subscribe to router event
this.activatedRoute.queryParams.subscribe((params: Params) => {
if (params) {
this.authToken = params['auth_token'];
this.authRole = params['auth_role'];
this.authToken = params["auth_token"];
this.authRole = params["auth_role"];
this.errorCode = params["error_code"];
} else {
this.authToken = "";
this.authRole = "";
this.errorCode = "";
}
if (this.authToken && this.authRole)
if (this.authToken && this.authRole && this.errorCode != "") {
this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole });
}
});
}
getCookie(key: string){
getCookie(key: string) {
return this._cookieService.get(key);
}
removeCookie(key: string){
removeCookie(key: string) {
return this._cookieService.remove(key);
}
checkvalidation() {
}
/**
* Logout from CAS only helper
*/
casSignOut() {
this._hds.casSignOut().then(data => {
this._ata.initLoginInfo();
// this.router.navigate(['/school']);
this.authToken = '';
this.authRole = '';
window.location.assign((<any>data).next);
}).catch(err => {
console.log(err)
});
}
}
This diff is collapsed.
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