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

Merge branch 'userinformations' into 'develop'

Userinformations

See merge request !29
parents 95c962f4 8f3ed10c
...@@ -23,7 +23,9 @@ epal_auth_test: ...@@ -23,7 +23,9 @@ epal_auth_test:
_permission: 'access content' _permission: 'access content'
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
current_user: current_user:
path: '/epal/curuser' path: '/epal/curuser/{token_name}'
options:
_auth: [ 'basic_auth' ]
defaults: defaults:
_controller: '\Drupal\epal\Controller\CurrentUser::content' _controller: '\Drupal\epal\Controller\CurrentUser::content'
requirements: requirements:
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
* Contains \Drupal\query_example\Controller\QueryExampleController. * Contains \Drupal\query_example\Controller\QueryExampleController.
*/ */
namespace Drupal\epal\Controller; namespace Drupal\epal\Controller;
use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Entity\Query\QueryFactory;
...@@ -13,26 +17,22 @@ use Symfony\Component\HttpFoundation\JsonResponse; ...@@ -13,26 +17,22 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
class CurrentUser extends ControllerBase { class CurrentUser extends ControllerBase {
public function content() { public function content($token_name) {
$query = \Drupal::database()->select('epal_users', 'nfd');
$query->fields('nfd', ['name']);
// $name = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id()); $query->condition('nfd.authtoken', $token_name);
$name = "LALALA"; $field = $query->execute()->fetchAssoc();
$authToken = "no authToken";
$accessKey = "no accessKey";
if (\Drupal::request()->headers->has('X-AUTH-TOKEN')) {
$authToken = \Drupal::request()->headers->get( 'X-AUTH-TOKEN' ); $response = new JsonResponse($field);
}
if (\Drupal::request()->headers->has('X-ACCESS-KEY')) {
$accessKey = \Drupal::request()->headers->get( 'X-ACCESS-KEY' );
}
$response = new JsonResponse([$name]);
$response->headers->set('X-AUTH-TOKEN', 'HELLOTOKEN');
return $response; return $response;
} }
......
...@@ -8,8 +8,9 @@ import { AmkaFillsActions} from './amkafill.actions'; ...@@ -8,8 +8,9 @@ import { AmkaFillsActions} from './amkafill.actions';
import { LoginInfoActions} from './logininfo.actions'; import { LoginInfoActions} from './logininfo.actions';
import { CriteriaActions} from './criteria.actions'; import { CriteriaActions} from './criteria.actions';
const ACTION_PROVIDERS = [ CourseFieldsActions, SectorFieldsActions, RegionSchoolsActions, SectorCoursesActions, StudentDataFieldsActions, const ACTION_PROVIDERS = [ CourseFieldsActions, SectorFieldsActions, RegionSchoolsActions, SectorCoursesActions, StudentDataFieldsActions,
EpalClassesActions, AmkaFillsActions, LoginInfoActions, CriteriaActions ]; EpalClassesActions, AmkaFillsActions, LoginInfoActions, CriteriaActions];
export { export {
CourseFieldsActions, CourseFieldsActions,
...@@ -21,5 +22,6 @@ export { ...@@ -21,5 +22,6 @@ export {
AmkaFillsActions, AmkaFillsActions,
LoginInfoActions, LoginInfoActions,
CriteriaActions, CriteriaActions,
ACTION_PROVIDERS, ACTION_PROVIDERS,
}; };
import { LOGININFO_SAVE, LOGININFO_INIT } from '../constants'; import { LOGININFO_SAVE, LOGININFO_RECEIVED } from '../constants';
import { LOGININFO_INIT } from '../constants';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux'; import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store'; import { IAppState } from '../store';
...@@ -10,14 +11,17 @@ export class LoginInfoActions { ...@@ -10,14 +11,17 @@ export class LoginInfoActions {
private _ngRedux: NgRedux<IAppState>, private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService) {} private _hds: HelperDataService) {}
saveLoginInfo = (loginInfo) => {
getloginInfo = (loginInfo) => {
return this._hds.getCurrentUser(loginInfo.auth_token, loginInfo.auth_role).then (loginInfos => {
return this._ngRedux.dispatch({ return this._ngRedux.dispatch({
type: LOGININFO_SAVE, type: LOGININFO_SAVE,
payload: { payload: {
loginInfo loginInfos
} }
}); });
}; });
}
initLoginInfo = () => { initLoginInfo = () => {
return this._ngRedux.dispatch({ return this._ngRedux.dispatch({
...@@ -27,4 +31,5 @@ export class LoginInfoActions { ...@@ -27,4 +31,5 @@ export class LoginInfoActions {
}); });
}; };
} }
export const API_ENDPOINT = 'http://localhost/drupal-8.2.5'; export const API_ENDPOINT = 'http://localhost/angular/eepal-front/drupal';
export class AppSettings { export class AppSettings {
public static get API_ENDPOINT(): string { public static get API_ENDPOINT(): string {
return 'http://localhost/drupal-8.2.5'; return 'http://localhost/angular/eepal-front/drupal';
// return 'http://localhost/angular/eepal-front/drupal'; // return 'http://localhost/angular/eepal-front/drupal';
// return 'http://localhost/drupal'; // return 'http://localhost/drupal';
// return 'http://localhost/angular/eepal-front/drupal'; // return 'http://localhost/angular/eepal-front/drupal';
// return 'http://localhost/drupal'; // return 'http://localhost/angular/eepal-front/drupal';
// return 'http://eepal.dev/drupal'; // return 'http://eepal.dev/drupal';
// return 'http://localhost/drupal';
// return 'http://eduslim2.minedu.gov.gr/drupal'; // return 'http://eduslim2.minedu.gov.gr/drupal';
} }
} }
...@@ -5,6 +5,7 @@ import { ILoginInfo } from '../store/logininfo/logininfo.types'; ...@@ -5,6 +5,7 @@ import { ILoginInfo } from '../store/logininfo/logininfo.types';
import { NgRedux, select } from 'ng2-redux'; import { NgRedux, select } from 'ng2-redux';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { IAppState } from '../store/store'; import { IAppState } from '../store/store';
import { HelperDataService } from '../services/helper-data-service';
import { import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
...@@ -17,7 +18,7 @@ import { API_ENDPOINT } from '../app.settings'; ...@@ -17,7 +18,7 @@ import { API_ENDPOINT } from '../app.settings';
selector: 'home', selector: 'home',
template: ` template: `
<div> <div>
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/oauth/login" #form> <form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/oauth/login" #form>
<!-- <input type="hidden" name="X-oauth-enabled" value="true"> --> <!-- <input type="hidden" name="X-oauth-enabled" value="true"> -->
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div> <div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
...@@ -57,10 +58,13 @@ import { API_ENDPOINT } from '../app.settings'; ...@@ -57,10 +58,13 @@ import { API_ENDPOINT } from '../app.settings';
</div> </div>
` `
}) })
export default class Home implements OnInit { export default class Home implements OnInit {
public formGroup: FormGroup; public formGroup: FormGroup;
private authToken: string; private authToken: string;
private authRole: string; private authRole: string;
private name :any;
private xcsrftoken :any;
private loginInfo$: Observable<ILoginInfo>; private loginInfo$: Observable<ILoginInfo>;
private apiEndPoint = API_ENDPOINT; private apiEndPoint = API_ENDPOINT;
...@@ -68,10 +72,12 @@ export default class Home implements OnInit { ...@@ -68,10 +72,12 @@ export default class Home implements OnInit {
private _ata: LoginInfoActions, private _ata: LoginInfoActions,
private _ngRedux: NgRedux<IAppState>, private _ngRedux: NgRedux<IAppState>,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private _hds: HelperDataService,
private router: Router private router: Router
) { ) {
this.authToken = ''; this.authToken = '';
this.authRole = ''; this.authRole = '';
this.name ='';
this.formGroup = this.fb.group({ this.formGroup = this.fb.group({
// Username: [], // Username: [],
// Paswd: [] // Paswd: []
...@@ -79,30 +85,36 @@ export default class Home implements OnInit { ...@@ -79,30 +85,36 @@ export default class Home implements OnInit {
}; };
ngOnInit() { ngOnInit() {
this.loginInfo$ = this._ngRedux.select(state => { this.loginInfo$ = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) { if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => { state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role; this.authRole = loginInfoToken.auth_role;
if (this.authToken && this.authToken.length > 0)
this.router.navigate(['/epal-class-select']);
return loginInfoToken; return loginInfoToken;
}, {}); }, {});
} }
return state.loginInfo; return state.loginInfo;
}); });
// subscribe to router event // subscribe to router event
this.activatedRoute.queryParams.subscribe((params: Params) => { this.activatedRoute.queryParams.subscribe((params: Params) => {
this.authToken = params['auth_token'];
this.authRole = params['auth_role'];
if (params) { if (params) {
this.authToken = params['auth_token']; this.authToken = params['auth_token'];
this.authRole = params['auth_role']; this.authRole = params['auth_role'];
} }
if (this.authToken && this.authRole) if (this.authToken && this.authRole)
this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole }); this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole});
// console.log(this.authToken); console.log(this.authToken, "tttttttt");
if (this.authToken && this.authToken.length > 0)
this.router.navigate(['/epal-class-select']);
// this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole, cu_name:this.name });
}); });
} }
......
...@@ -10,14 +10,18 @@ ...@@ -10,14 +10,18 @@
<div class="collapse navbar-collapse flex-row-reverse" id="navbarNav"> <div class="collapse navbar-collapse flex-row-reverse" id="navbarNav">
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div> <div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<ul class="navbar-nav"> <ul class="navbar-nav">
<b>Όνομα Χρήστη:</b> {{this.cuser}} <div *ngFor="let username$ of loginInfo$ | async;">
<b>Όνομα Χρήστη:</b> {{username$.cu_name}}
&nbsp;&nbsp; &nbsp;&nbsp;
<div *ngIf="authToken"> <div *ngIf="authToken">
<button type="button" class="btn-primary btn-sm pull-right" (click)="oauthSignOut()"> <button type="button" class="btn-primary btn-sm pull-right" (click)="oauthSignOut()">
<i class="fa fa-sign-out"></i> <i class="fa fa-sign-out"></i>
</button> </button>
</div> </div>
</div>
<!-- <!--
<li class="nav-item" [ngClass]="{active: path=='application-preview'}"> <li class="nav-item" [ngClass]="{active: path=='application-preview'}">
<a class="nav-link" [routerLink]="['/application-preview']" [routerLinkActive]="['active']">Προεπισκόπηση</a> <a class="nav-link" [routerLink]="['/application-preview']" [routerLinkActive]="['active']">Προεπισκόπηση</a>
......
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { HelperDataService } from '../../services/helper-data-service';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { LoginInfoActions } from '../../actions/logininfo.actions';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { NgRedux, select } from 'ng2-redux'; import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store'; import { IAppState } from '../../store/store';
import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types';
import { HelperDataService } from '../../services/helper-data-service';
import { LoginInfoActions } from '../../actions/logininfo.actions';
@Component({ @Component({
selector: 'reg-navbar', selector: 'reg-navbar',
...@@ -19,6 +22,10 @@ import { IAppState } from '../../store/store'; ...@@ -19,6 +22,10 @@ import { IAppState } from '../../store/store';
private loginInfo$: Observable<ILoginInfo>; private loginInfo$: Observable<ILoginInfo>;
public cuser :any; public cuser :any;
constructor( private _ata: LoginInfoActions, constructor( private _ata: LoginInfoActions,
private _hds: HelperDataService, private _hds: HelperDataService,
private _ngRedux: NgRedux<IAppState>, private _ngRedux: NgRedux<IAppState>,
...@@ -43,7 +50,7 @@ import { IAppState } from '../../store/store'; ...@@ -43,7 +50,7 @@ import { IAppState } from '../../store/store';
return state.loginInfo; return state.loginInfo;
}); });
this._hds.getCurrentUser().then( cuser => this.cuser= cuser );
} }
oauthSignOut() { oauthSignOut() {
...@@ -56,5 +63,4 @@ import { IAppState } from '../../store/store'; ...@@ -56,5 +63,4 @@ import { IAppState } from '../../store/store';
} }
} }
...@@ -21,6 +21,12 @@ export const EPALCLASSES_SAVE = 'EPALCLASSES_SAVE'; ...@@ -21,6 +21,12 @@ export const EPALCLASSES_SAVE = 'EPALCLASSES_SAVE';
export const AMKAFILL_SAVE = 'AMKAFILL_SAVE'; export const AMKAFILL_SAVE = 'AMKAFILL_SAVE';
export const LOGININFO_SAVE = 'LOGININFO_SAVE'; export const LOGININFO_SAVE = 'LOGININFO_SAVE';
export const LOGININFO_RECEIVED = 'LOGININFO_RECEIVED';
export const USERINFOS_RECEIVED = 'USERINFOS_RECEIVED';
export const USERINFO_SELECTED_SAVE = 'USERINFO_SELECTED_SAVE';
export const LOGININFO_INIT = 'LOGININFO_INIT'; export const LOGININFO_INIT = 'LOGININFO_INIT';
export const CRITERIA_SAVE = 'CRITERIA_SAVE'; export const CRITERIA_SAVE = 'CRITERIA_SAVE';
......
...@@ -10,7 +10,8 @@ import { ISector, ISectors, ISectorCourse } from '../store/sectorcourses/sectorc ...@@ -10,7 +10,8 @@ import { ISector, ISectors, ISectorCourse } from '../store/sectorcourses/sectorc
import { AppSettings } from '../app.settings'; import { AppSettings } from '../app.settings';
import { NgRedux, select } from 'ng2-redux'; import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../store/store'; import { IAppState } from '../store/store';
import { ILoginInfo } from '../store/logininfo/logininfo.types'; import { ILoginInfo, ILoginInfoToken } from '../store/logininfo/logininfo.types';
const HEADER = { headers: new Headers({ 'Content-Type': 'application/json' }) }; const HEADER = { headers: new Headers({ 'Content-Type': 'application/json' }) };
...@@ -231,20 +232,29 @@ export class HelperDataService { ...@@ -231,20 +232,29 @@ export class HelperDataService {
getCurrentUser() { getCurrentUser(oauthtoken, oauthrole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`) this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser/${oauthtoken} `)
.map(response => response.json()) .map(response => response.json())
.subscribe(data => { .subscribe(data => {
resolve(data); resolve(this.transformUserSchema(data, oauthtoken, oauthrole));
}, }, // put the data returned from the server in our variable
error => { error => {
console.log("Error HTTP GET Service"); console.log("Error HTTP GET Service"); // in case of failure show this message
reject("Error HTTP GET Service"); reject("Error HTTP GET Service");
}, },
() => console.log("Course Fields Received")); () => console.log("UserName Received"));
}); });
}; }
transformUserSchema(userlogin:any,oauthtoken:string, oauthrole:string){
let rsa = Array<ILoginInfoToken>();
rsa.push(<ILoginInfoToken>{'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name':userlogin.name});
return rsa;
}
signOut() { signOut() {
this.loginInfo$.forEach(loginInfoToken => { this.loginInfo$.forEach(loginInfoToken => {
...@@ -255,7 +265,8 @@ export class HelperDataService { ...@@ -255,7 +265,8 @@ export class HelperDataService {
//"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
// "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=", // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
"Content-Type": "application/json",
"Content-Type": "application/json",
"Accept": "*/*", "Accept": "*/*",
"Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Credentials": "true",
// "Content-Type": "text/plain", // try to skip preflight // "Content-Type": "text/plain", // try to skip preflight
...@@ -282,4 +293,5 @@ export class HelperDataService { ...@@ -282,4 +293,5 @@ export class HelperDataService {
}); });
} }
} }
...@@ -10,9 +10,14 @@ import { ...@@ -10,9 +10,14 @@ import {
export function loginInfoReducer(state: ILoginInfo = INITIAL_STATE, action): ILoginInfo { export function loginInfoReducer(state: ILoginInfo = INITIAL_STATE, action): ILoginInfo {
switch (action.type) { switch (action.type) {
case LOGININFO_SAVE: case LOGININFO_SAVE:
let loginInfoTokens = Array<ILoginInfoToken>(); let loginInfoTokens = Array<ILoginInfoToken>();
loginInfoTokens.push(<ILoginInfoToken>{auth_token: action.payload.loginInfo.auth_token, auth_role: action.payload.loginInfo.auth_role}); let i=0;
action.payload.loginInfos.forEach(loginInfo => {
loginInfoTokens.push(<ILoginInfoToken>{auth_token: loginInfo.auth_token, auth_role: loginInfo.auth_role, cu_name: loginInfo.cu_name, xcsrftoken: loginInfo.xcsrftoken });
i++;
});
return Seq(loginInfoTokens).map(n => n).toList(); return Seq(loginInfoTokens).map(n => n).toList();
case LOGININFO_INIT: case LOGININFO_INIT:
return INITIAL_STATE; return INITIAL_STATE;
default: default:
......
...@@ -3,7 +3,7 @@ import { ILoginInfo, ILoginInfoToken } from './logininfo.types'; ...@@ -3,7 +3,7 @@ import { ILoginInfo, ILoginInfoToken } from './logininfo.types';
export function deimmutifyLoginInfo(state: ILoginInfo): ILoginInfoToken[] { export function deimmutifyLoginInfo(state: ILoginInfo): ILoginInfoToken[] {
let fetchedLoginInfoTokens = new Array(); let fetchedLoginInfoTokens = new Array();
state.forEach(loginInfoToken => { state.forEach(loginInfoToken => {
fetchedLoginInfoTokens.push(<ILoginInfoToken>{auth_token: loginInfoToken.auth_token, auth_role: loginInfoToken.auth_role}); fetchedLoginInfoTokens.push(<ILoginInfoToken>{auth_token: loginInfoToken.auth_token, auth_role: loginInfoToken.auth_role, cu_name: loginInfoToken.cu_name, xcsrftoken: loginInfoToken.xcsrftoken});
}); });
return fetchedLoginInfoTokens; return fetchedLoginInfoTokens;
}; };
...@@ -3,6 +3,8 @@ import { List } from 'immutable'; ...@@ -3,6 +3,8 @@ import { List } from 'immutable';
export interface ILoginInfoToken { export interface ILoginInfoToken {
auth_token: string; auth_token: string;
auth_role: string; auth_role: string;
cu_name: string;
xcsrftoken:string;
} }
export type ILoginInfo = List<ILoginInfoToken>; export type ILoginInfo = List<ILoginInfoToken>;
...@@ -23,6 +23,7 @@ export interface IAppState { ...@@ -23,6 +23,7 @@ export interface IAppState {
amkafills?: amkafills.IAmkaFills; amkafills?: amkafills.IAmkaFills;
loginInfo?: loginInfo.ILoginInfo; loginInfo?: loginInfo.ILoginInfo;
criter?: criter.ICriter; criter?: criter.ICriter;
}; };
export const rootReducer = combineReducers<IAppState>({ export const rootReducer = combineReducers<IAppState>({
...@@ -35,6 +36,7 @@ export const rootReducer = combineReducers<IAppState>({ ...@@ -35,6 +36,7 @@ export const rootReducer = combineReducers<IAppState>({
amkafills: amkafills.amkafillReducer, amkafills: amkafills.amkafillReducer,
loginInfo: loginInfo.loginInfoReducer, loginInfo: loginInfo.loginInfoReducer,
criter: criter.criteriaReducer, criter: criter.criteriaReducer,
}); });
export function deimmutify(state: IAppState): Object { export function deimmutify(state: IAppState): Object {
...@@ -48,6 +50,7 @@ export function deimmutify(state: IAppState): Object { ...@@ -48,6 +50,7 @@ export function deimmutify(state: IAppState): Object {
amkafills: amkafills.deimmutifyAmkaFills(state.amkafills), amkafills: amkafills.deimmutifyAmkaFills(state.amkafills),
loginInfo: loginInfo.deimmutifyLoginInfo(state.loginInfo), loginInfo: loginInfo.deimmutifyLoginInfo(state.loginInfo),
criter: criter.deimmutifyCriteria(state.criter), criter: criter.deimmutifyCriteria(state.criter),
}; };
} }
......
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