diff --git a/drupal/modules/epal/epal.routing.yml b/drupal/modules/epal/epal.routing.yml index 1601e1d0a560951d52ec9814c5041b2797631e11..cd6b6b26e2ec858eab28a223bbcd774aca235e5b 100644 --- a/drupal/modules/epal/epal.routing.yml +++ b/drupal/modules/epal/epal.routing.yml @@ -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' diff --git a/drupal/modules/epal/src/Controller/CurrentUser.php b/drupal/modules/epal/src/Controller/CurrentUser.php index 26525760c83391fe4bbd3723993d463c058425f9..70977ef56b333cf59c4f29376de6c591d895398e 100644 --- a/drupal/modules/epal/src/Controller/CurrentUser.php +++ b/drupal/modules/epal/src/Controller/CurrentUser.php @@ -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; } diff --git a/source/actions/index.ts b/source/actions/index.ts index c1e589b007cb52c5d2c4f487a86c8318a929b010..e25292b9f95b161b87cc9b1aa859bf600230ed24 100644 --- a/source/actions/index.ts +++ b/source/actions/index.ts @@ -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, }; diff --git a/source/components/home.ts b/source/components/home.ts index 9392061b7327d503e781dae55b5da1d333cdb82a..75771ae665f9d3de0ddda537e14f8d22802e6efb 100644 --- a/source/components/home.ts +++ b/source/components/home.ts @@ -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';
{{loginInfoToken$.auth_role}}
+
+ {{loginInfoToken$.cu_name}} +
@@ -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; constructor(private fb: FormBuilder, private _ata: LoginInfoActions, private _ngRedux: NgRedux, - 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"); }); } diff --git a/source/components/navbar/navbar.component.html b/source/components/navbar/navbar.component.html index a14a01098d1634be588e721918df92c1b97c9b71..51be1786921c36fdd177695a567c5cc1f086c5f8 100644 --- a/source/components/navbar/navbar.component.html +++ b/source/components/navbar/navbar.component.html @@ -9,8 +9,8 @@