Commit 050610d3 authored by Open Source Developer's avatar Open Source Developer

userdata

parent ed2b052e
......@@ -23,8 +23,10 @@ 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:
_access: 'TRUE'
_user_is_logged_in: 'TRUE'
......@@ -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() {
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();
// $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');
$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,
};
......@@ -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,
......@@ -26,6 +27,9 @@ import { AppSettings } from '../app.settings';
<div class="col-md-6">
{{loginInfoToken$.auth_role}}
</div>
<div>
{{loginInfoToken$.cu_name}}
</div>
</div>
</div>
<div class="row">
......@@ -57,14 +61,17 @@ export default class Home implements OnInit {
public formGroup: FormGroup;
private authToken: string;
private authRole: string;
private name :any;
private loginInfo$: Observable<ILoginInfo>;
constructor(private fb: FormBuilder,
private _ata: LoginInfoActions,
private _ngRedux: NgRedux<IAppState>,
private activatedRoute: ActivatedRoute
private activatedRoute: ActivatedRoute,
private _hds: HelperDataService,
) {
this.authToken = '';
this.authRole = '';
this.name ='';
this.formGroup = this.fb.group({
Username: [],
Paswd: []
......@@ -77,19 +84,28 @@ export default class Home implements OnInit {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
this.name = loginInfoToken.cu_name;
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 });
// console.log(this.authToken);
this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole, cu_name:this.name });
// console.log(this.authToken,"token");
});
}
......
......@@ -9,7 +9,7 @@
</a>
<div class="collapse navbar-collapse flex-row-reverse" id="navbarNav">
<ul class="navbar-nav">
<b>Όνομα Χρήστη:</b> {{this.cuser}}
<!--
<li class="nav-item" [ngClass]="{active: path=='application-preview'}">
......
import {Component, OnInit} from '@angular/core';
import { Injectable } from "@angular/core";
import { HelperDataService } from '../../services/helper-data-service';
@Component({
selector: 'reg-navbar',
......@@ -9,22 +12,14 @@ import { HelperDataService } from '../../services/helper-data-service';
@Injectable() export default class NavbarComponent implements OnInit{
public cuser :any;
constructor( private _hds: HelperDataService) {
};
ngOnInit() {
this._hds.getCurrentUser().then( cuser => this.cuser= cuser );
}
}
......@@ -18,6 +18,10 @@ 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 CRITERIA_SAVE = 'CRITERIA_SAVE';
......
......@@ -12,6 +12,7 @@ import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../store/store';
import { ILoginInfo } from '../store/logininfo/logininfo.types';
const HEADER = { headers: new Headers({ 'Content-Type': 'application/json' }) };
@Injectable()
......@@ -232,20 +233,29 @@ export class HelperDataService {
getCurrentUser() {
getCurrentUser(oauthtoken) {
console.log(oauthtoken, "tokenlalalala");
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())
.subscribe(data => {
resolve(data);
},
}, // 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("Sector Fields Received"));
});
};
}
......
......@@ -10,7 +10,7 @@ export function loginInfoReducer(state: ILoginInfo = INITIAL_STATE, action): ILo
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});
loginInfoTokens.push(<ILoginInfoToken>{auth_token: action.payload.loginInfo.auth_token, auth_role: action.payload.loginInfo.auth_role, cu_name: action.payload.loginInfo.cu_name });
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});
fetchedLoginInfoTokens.push(<ILoginInfoToken>{auth_token: loginInfoToken.auth_token, auth_role: loginInfoToken.auth_role, cu_name: loginInfoToken.cu_name});
});
return fetchedLoginInfoTokens;
};
......@@ -3,6 +3,7 @@ import { List } from 'immutable';
export interface ILoginInfoToken {
auth_token: string;
auth_role: string;
cu_name: 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