Merge branch 'userinformations' into 'develop'

Userinformations

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