diff --git a/drupal/modules/epal/epal.routing.yml b/drupal/modules/epal/epal.routing.yml index e3475f52641f1d7aa310420141046dc45d8789d3..d1d9414b541ab922825b8c2eaa66ac939309858f 100644 --- a/drupal/modules/epal/epal.routing.yml +++ b/drupal/modules/epal/epal.routing.yml @@ -23,13 +23,13 @@ epal_auth_test: _permission: 'access content' _user_is_logged_in: 'TRUE' current_user: - path: '/epal/curuser/{token_name}' + path: '/epal/curuser' options: _auth: [ 'basic_auth' ] defaults: _controller: '\Drupal\epal\Controller\CurrentUser::content' requirements: - _access: 'TRUE' + _user_is_logged_in: 'TRUE' epal.application_submit: path: '/epal/appsubmit' options: diff --git a/drupal/modules/epal/src/Controller/CurrentUser.php b/drupal/modules/epal/src/Controller/CurrentUser.php index 70977ef56b333cf59c4f29376de6c591d895398e..218e3adc1e245f64d5d9ce2115efdf98d93f5e90 100644 --- a/drupal/modules/epal/src/Controller/CurrentUser.php +++ b/drupal/modules/epal/src/Controller/CurrentUser.php @@ -1,12 +1,4 @@ select('epal_users', 'nfd'); - $query->fields('nfd', ['name']); - $query->condition('nfd.authtoken', $token_name); - $field = $query->execute()->fetchAssoc(); - - - - - $response = new JsonResponse($field); - return $response; - - } + protected $entityTypeManager; + + public function __construct(EntityTypeManagerInterface $entityTypeManager ) + { + $this->entityTypeManager1 = $entityTypeManager; + + } + + +public static function create(ContainerInterface $container) { + return new static( + $container->get('entity_type.manager'), + $container->get('entity.query'), + $container->get('entity_field.manager') + ); +} + + public function content(Request $request) { + + $authToken = $request->headers->get('PHP_AUTH_USER'); + + + $epalUsers = $this->entityTypeManager1->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken)); + $epalUser = reset($epalUsers); + if ($epalUser) + { + $currentUserName = $epalUser->name->value; + + $response = new JsonResponse(['name' =>$currentUserName]); + } + else { + $response = new Response(); + $response->setContent('forbidden'); + $response->setStatusCode(Response::HTTP_FORBIDDEN); + $response->headers->set('Content-Type', 'application/json'); + } + + return $response; + + } } diff --git a/source/components/home.ts b/source/components/home.ts index 46832fa2304fe4a142b3481af6968eb079f7989e..8e8efa416d65820b4cb8147a4f529547e20e9015 100644 --- a/source/components/home.ts +++ b/source/components/home.ts @@ -90,7 +90,8 @@ export default class Home implements OnInit { 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; }, {}); } @@ -100,9 +101,6 @@ export default class Home implements OnInit { // 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']; @@ -110,10 +108,6 @@ export default class Home implements OnInit { if (this.authToken && this.authRole) 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 }); }); } diff --git a/source/components/navbar/navbar.component.html b/source/components/navbar/navbar.component.html index c424ab88363ae76e4a96548adc0973f7d9904979..e7ec39c431afccc68aab3cd7d78b67a9702a5bda 100644 --- a/source/components/navbar/navbar.component.html +++ b/source/components/navbar/navbar.component.html @@ -1,4 +1,4 @@ -