diff --git a/drupal/modules/casost/src/Controller/CASLogin.php b/drupal/modules/casost/src/Controller/CASLogin.php index 630237c2e38d2bc740c56d79ee8f2cb80f503149..080066afa8bde5c8078c06da7da0d6e96b0d256e 100755 --- 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 665765eafc087e4cecb739b92c095b6e4c1ef861..6e8cd07502123baee4e1cb8d07715ff530025538 100755 --- 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/drupal/modules/epal/epal.routing.yml b/drupal/modules/epal/epal.routing.yml index f6728216773acb259d99ea6bd87898b3f2ede312..5c093d46488e84d88f526eead0aa631d3970ce18 100755 --- a/drupal/modules/epal/epal.routing.yml +++ b/drupal/modules/epal/epal.routing.yml @@ -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' diff --git a/drupal/modules/epal/src/Controller/MinistryLogin.php b/drupal/modules/epal/src/Controller/MinistryLogin.php new file mode 100644 index 0000000000000000000000000000000000000000..7ca002726e864b9b519d264f61d658e6012a9638 --- /dev/null +++ b/drupal/modules/epal/src/Controller/MinistryLogin.php @@ -0,0 +1,122 @@ +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; + } + + + +} diff --git a/drupal/modules/epaldeploysystem/config/optional/user.role.ministry.yml b/drupal/modules/epaldeploysystem/config/optional/user.role.ministry.yml new file mode 100644 index 0000000000000000000000000000000000000000..1fac2522640c82a61862fdea9f9b9c6eab65fc84 --- /dev/null +++ b/drupal/modules/epaldeploysystem/config/optional/user.role.ministry.yml @@ -0,0 +1,45 @@ +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' diff --git a/drupal/modules/oauthost/src/Controller/CBController.php b/drupal/modules/oauthost/src/Controller/CBController.php index 6c8961f0a3b27f3a8cdc39141542ae55ace84575..e6cc9e6a306e862684a09e380e0d7fd52ff6ff34 100755 --- a/drupal/modules/oauthost/src/Controller/CBController.php +++ b/drupal/modules/oauthost/src/Controller/CBController.php @@ -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'); diff --git a/drupal/modules/oauthost/src/Controller/RedirectResponseWithCookie.php b/drupal/modules/oauthost/src/Controller/RedirectResponseWithCookie.php new file mode 100644 index 0000000000000000000000000000000000000000..8591b9f75d3b8eddd86a29c8c06c73fbbc9a5440 --- /dev/null +++ b/drupal/modules/oauthost/src/Controller/RedirectResponseWithCookie.php @@ -0,0 +1,38 @@ +headers->setCookie($cookie); + } + } +} diff --git a/package.json b/package.json index 4e41f3c98dedeb0fecbf200a224b905d79ffc15c..9d5e2eb5ccc61a4af790cfff8763c57c4f0735fa 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "ng2-redux": "^5.1.0", "ng2-smart-table": "^0.4.0-5", "ngx-bootstrap": "^1.6.6", + "ngx-cookie": "^1.0.0", "ngx-uploader": "^2.2.5", "raw-loader": "^0.5.1", "redux": "^3.6.0", diff --git a/source/actions/logininfo.actions.ts b/source/actions/logininfo.actions.ts index e8a10499d9d813340443ebfaae3f966b439ab835..2e86e71ecbc488652e8c46c55c227a23dc268884 100644 --- a/source/actions/logininfo.actions.ts +++ b/source/actions/logininfo.actions.ts @@ -11,7 +11,7 @@ export class LoginInfoActions { private _ngRedux: NgRedux, 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, diff --git a/source/app.settings.deployment.ts b/source/app.settings.deployment.ts index d8d45ae94e3b5082ac9cbbf59bfc0dd3b7ac53ea..ba1b15b3fae84928f4fceab6c383f979f238d3a0 100644 --- a/source/app.settings.deployment.ts +++ b/source/app.settings.deployment.ts @@ -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'; } } 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/home.ts b/source/components/home.ts index e7a6d6086164efc65e6662a7f9ec558f1f44a8e9..6d5ea6cdb52ca8fbe38b019ab73844351b270046 100644 --- a/source/components/home.ts +++ b/source/components/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 Home 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 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() { } diff --git a/source/components/minister/minister-view.ts b/source/components/minister/minister-view.ts new file mode 100644 index 0000000000000000000000000000000000000000..56cd5e9f8bc762c8a625f40e69aadaee6bf45982 --- /dev/null +++ b/source/components/minister/minister-view.ts @@ -0,0 +1,71 @@ +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: ` + +
+
+ +
+
+ + ` +}) + +@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() { + + } + + + +} diff --git a/source/components/ministry.home.ts b/source/components/ministry.home.ts new file mode 100644 index 0000000000000000000000000000000000000000..061c9ce2fb0e21d8b631ce0d9590c5f5f2610c69 --- /dev/null +++ b/source/components/ministry.home.ts @@ -0,0 +1,111 @@ +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: ` +
+
+ +
+ +
+
+ Το πεδίο δεν μπορεί να αφεθεί κενό! +
+ +
+ +
+
+ Το πεδίο δεν μπορεί να αφεθεί κενό! +
+ +
+
+ +
+ +
+
+
+
+ ` +}) + +export default class MinistryHome implements OnInit { + public userDataGroup: FormGroup; + private authRole: string; + private mineduUsername: string; + private mineduPassword: string; + private loginInfo$: Observable; + private apiEndPoint = API_ENDPOINT; + + constructor(private fb: FormBuilder, + private _ata: LoginInfoActions, + private _ngRedux: NgRedux, + 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) => { + this.mineduUsername = loginInfoToken.minedu_username; + this.mineduPassword = loginInfoToken.minedu_userpassword; + if (this.mineduUsername && this.mineduUsername.length > 0) + this.router.navigate(['/ministry/minister-view']); + return loginInfoToken; + }, {}); + } + return state.loginInfo; + }); + + } + + submitCredentials() { + let success = true; + this._hds.sendMinisrtyCredentials(this.userDataGroup.value['minedu_username'],this.userDataGroup.value['minedu_userpassword']) + .catch(err => {console.log(err); success = false;}) + .then(msg => { + if (success) { + this.authRole = 'supervisor'; + console.log("MPHKA"); + this._ata.saveMinEduloginInfo([this.userDataGroup.value]); + } + }); + } + + + +} diff --git a/source/components/school.home.ts b/source/components/school.home.ts index ed57e3e13561001f9f74de2a14cee9ef1c77c116..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,19 +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']; - this.authRole = params['auth_role']; - } - - 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/containers/main.routes.ts b/source/containers/main.routes.ts index b44e9a304e85b8c1a0b4776304058d7bc3d8c33f..798aabe803911a84642348a567cf5ff71cc7f5cf 100644 --- a/source/containers/main.routes.ts +++ b/source/containers/main.routes.ts @@ -10,6 +10,7 @@ import StudentApplicationMain from '../components/student-application-form/appli import StudentsList from '../components/students/students-list'; import Home from '../components/home'; import SchoolHome from '../components/school.home'; +import MinistryHome from '../components/ministry.home'; import CourseFieldsSelect from '../components/student-application-form/course.fields.select'; import EpalClassesSelect from '../components/student-application-form/epal.class.select'; import SectorFieldsSelect from '../components/student-application-form/sector.fields.select'; @@ -22,12 +23,14 @@ import SubmitedPreview from '../components/student-application-form/submited.apl import SubmitedPerson from '../components/student-application-form/submitedstudent.preview'; import DirectorView from '../components/director/director-view'; import DirectorClassCapacity from '../components/director/director-classcapacity'; +import MinisterView from '../components/minister/minister-view'; import SchoolAuthGuard from '../guards/school.auth.guard'; import StudentAuthGuard from '../guards/student.auth.guard'; export const MainRoutes: Routes = [ { path: '', component: Home }, { path: 'school', component: SchoolHome }, + { path: 'ministry', component: MinistryHome }, { path: 'parent-form', component: ParentForm, canActivate: [StudentAuthGuard] }, { path: 'student-application-form-main', component: StudentApplicationMain, canActivate: [StudentAuthGuard] }, // { path: 'students-list', component: StudentsList }, @@ -43,6 +46,7 @@ export const MainRoutes: Routes = [ { path: 'submited-person', component: SubmitedPerson, canActivate: [StudentAuthGuard] }, { path: 'school/director-view', component: DirectorView, canActivate: [SchoolAuthGuard] }, { path: 'school/director-classcapacity', component: DirectorClassCapacity, canActivate: [SchoolAuthGuard] }, + { path: 'ministry/minister-view', component: MinisterView }, ]; export const MainDeclarations = [ @@ -51,6 +55,7 @@ export const MainDeclarations = [ StudentsList, Home, SchoolHome, + MinistryHome, CourseFieldsSelect, EpalClassesSelect, SectorFieldsSelect, @@ -64,5 +69,6 @@ export const MainDeclarations = [ SubmitedPreview, SubmitedPerson, DirectorView, - DirectorClassCapacity + DirectorClassCapacity, + MinisterView ]; diff --git a/source/services/helper-data-service.ts b/source/services/helper-data-service.ts index 95acd74a0fcadf3528d351de1ae852309fd3d56b..49cdf8e775e1d70f46baaac50170efd036a0f2a0 100644 --- a/source/services/helper-data-service.ts +++ b/source/services/helper-data-service.ts @@ -46,17 +46,20 @@ export class HelperDataService implements OnInit, OnDestroy { ngOnDestroy() { this.loginInfo$.unsubscribe(); } + createAuthorizationHeader(headers: Headers) { headers.append('Authorization', 'Basic ' + btoa(this.authToken + ':' + this.authToken)); } + createMinistryAuthorizationHeader(headers: Headers, username: string, passwd: string) { + headers.append('Authorization', 'Basic ' + btoa(username + ':' + passwd)); + } + getEpalUserData() { this.loginInfo$.getValue().forEach(loginInfoToken => { this.authToken = loginInfoToken.auth_token; this.authRole = loginInfoToken.auth_role; }); - console.log("authToken=" + this.authToken); - console.log("authRole=" + this.authRole); let headers = new Headers({ "Content-Type": "application/json", }); @@ -425,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" @@ -632,6 +636,32 @@ export class HelperDataService implements OnInit, OnDestroy { } + sendMinisrtyCredentials(username, userpassword) { + + let headers = new Headers({ + "Content-Type": "application/json", + //"Accept": "*/*", + //"Access-Control-Allow-Credentials": "true", + //"X-CSRF-Token": "..." + //"Authorization": "Basic " + btoa("..."), + }); + this.createMinistryAuthorizationHeader(headers, username, userpassword); + let options = new RequestOptions({ headers: headers }); + return new Promise((resolve, reject) => { + this.http.post(`${AppSettings.API_ENDPOINT}/ministry/login`, {username: username, userpassword: userpassword}, options) + .map(response => response.json()) + .subscribe(data => { + resolve(data); + }, + error => { + //console.log("Error Sending Ministry Credentials"); + reject("Error Sending Ministry Credentials"); + }, + () => console.log("")); + }); + + } + diff --git a/source/store/logininfo/logininfo.reducer.ts b/source/store/logininfo/logininfo.reducer.ts index a2b90ff8c35a54999e50da27b80b3b0fc20f0636..45faf71c51fc6a4967356ac85ef5761c8baee1a4 100644 --- a/source/store/logininfo/logininfo.reducer.ts +++ b/source/store/logininfo/logininfo.reducer.ts @@ -13,7 +13,8 @@ export function loginInfoReducer(state: ILoginInfo = LOGININFO_INITIAL_STATE, ac let loginInfoTokens = Array(); let i=0; action.payload.loginInfos.forEach(loginInfo => { - loginInfoTokens.push({auth_token: loginInfo.auth_token, auth_role: loginInfo.auth_role, cu_name: loginInfo.cu_name}); + loginInfoTokens.push({auth_token: loginInfo.auth_token, auth_role: loginInfo.auth_role, cu_name: loginInfo.cu_name, + minedu_username: loginInfo.minedu_username, minedu_userpassword: loginInfo.minedu_userpassword}); i++; }); return Seq(loginInfoTokens).map(n => n).toList(); diff --git a/source/store/logininfo/logininfo.transformers.ts b/source/store/logininfo/logininfo.transformers.ts index 28a5c7924be71a504ffcc0862cbea0ecdeb0c8fa..0da95d27ac22cc661627a09ca3b08fdfba1f4106 100644 --- a/source/store/logininfo/logininfo.transformers.ts +++ b/source/store/logininfo/logininfo.transformers.ts @@ -3,7 +3,8 @@ import { ILoginInfo, ILoginInfoToken } from './logininfo.types'; export function deimmutifyLoginInfo(state: ILoginInfo): ILoginInfoToken[] { let fetchedLoginInfoTokens = new Array(); state.forEach(loginInfoToken => { - fetchedLoginInfoTokens.push({auth_token: loginInfoToken.auth_token, auth_role: loginInfoToken.auth_role, cu_name: loginInfoToken.cu_name}); + fetchedLoginInfoTokens.push({auth_token: loginInfoToken.auth_token, auth_role: loginInfoToken.auth_role, cu_name: loginInfoToken.cu_name, + minedu_username: loginInfoToken.minedu_username, minedu_userpassword: loginInfoToken.minedu_userpassword}); }); return fetchedLoginInfoTokens; }; diff --git a/source/store/logininfo/logininfo.types.ts b/source/store/logininfo/logininfo.types.ts index 76671c03b54441fe6135cb001c736a2cbb00cd02..4cd691f4ea1e867d99854e7dabe4c8cdad55131f 100644 --- a/source/store/logininfo/logininfo.types.ts +++ b/source/store/logininfo/logininfo.types.ts @@ -4,6 +4,8 @@ export interface ILoginInfoToken { auth_token: string; auth_role: string; cu_name: string; + minedu_username: string; + minedu_userpassword: string; } export type ILoginInfo = List;