Commit c5c776d3 authored by Open Source Developer's avatar Open Source Developer

currentuser inforamtion from drupal

parent 050610d3
import { LOGININFO_SAVE } from '../constants';
import { LOGININFO_SAVE, LOGININFO_RECEIVED } from '../constants';
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
......@@ -10,13 +10,16 @@ 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
}
});
};
});
}
}
\ No newline at end of file
......@@ -27,9 +27,7 @@ import { AppSettings } from '../app.settings';
<div class="col-md-6">
{{loginInfoToken$.auth_role}}
</div>
<div>
{{loginInfoToken$.cu_name}}
</div>
</div>
</div>
<div class="row">
......@@ -62,6 +60,7 @@ export default class Home implements OnInit {
private authToken: string;
private authRole: string;
private name :any;
private xcsrftoken :any;
private loginInfo$: Observable<ILoginInfo>;
constructor(private fb: FormBuilder,
private _ata: LoginInfoActions,
......@@ -85,28 +84,25 @@ export default class Home implements OnInit {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
this.name = loginInfoToken.cu_name;
this.xcsrftoken = loginInfoToken.xcsrftoken;
return loginInfoToken;
}, {});
}
return state.loginInfo;
});
this._hds.getCurrentUser(this.authToken).then(cu_name =>{ return this._ngRedux.dispatch({
type: "aaaaaa",
payload: {
cu_name
}
});
});
// subscribe to router event
this.activatedRoute.queryParams.subscribe((params: 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, cu_name:this.name });
// console.log(this.authToken,"token");
if (this.authToken && this.authRole)
this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole});
// this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole, cu_name:this.name });
});
}
......
......@@ -9,8 +9,11 @@
</a>
<div class="collapse navbar-collapse flex-row-reverse" id="navbarNav">
<ul class="navbar-nav">
<div *ngFor="let username$ of loginInfo$ | async;">
<b>Όνομα Χρήστη:</b> {{username$.cu_name}}
</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 { Injectable } from "@angular/core";
import { Observable } from 'rxjs/Rx';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types';
......@@ -12,11 +15,26 @@ import { Injectable } from "@angular/core";
@Injectable() export default class NavbarComponent implements OnInit{
private loginInfo$: Observable<ILoginInfo>;
constructor(private _ngRedux: NgRedux<IAppState>,
) {
};
ngOnInit() {
this.loginInfo$ = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
return loginInfoToken;
}, {});
}
return state.loginInfo;
});
}
......
......@@ -10,7 +10,7 @@ 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' }) };
......@@ -233,30 +233,30 @@ export class HelperDataService {
getCurrentUser(oauthtoken) {
console.log(oauthtoken, "tokenlalalala");
return new Promise((resolve, reject) => {
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"); // in case of failure show this message
reject("Error HTTP GET Service");
},
() => console.log("Sector 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;
}
......
......@@ -9,9 +9,16 @@ 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, cu_name: action.payload.loginInfo.cu_name });
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();
default:
return state;
}
......
......@@ -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, cu_name: loginInfoToken.cu_name});
fetchedLoginInfoTokens.push(<ILoginInfoToken>{auth_token: loginInfoToken.auth_token, auth_role: loginInfoToken.auth_role, cu_name: loginInfoToken.cu_name, xcsrftoken: loginInfoToken.xcsrftoken});
});
return fetchedLoginInfoTokens;
};
......@@ -4,6 +4,7 @@ export interface ILoginInfoToken {
auth_token: string;
auth_role: string;
cu_name: string;
xcsrftoken:string;
}
export type ILoginInfo = List<ILoginInfoToken>;
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