From 409fc1ce086df6fc54a5d668d9c2d9a2ef668587 Mon Sep 17 00:00:00 2001 From: Open Source Developer Date: Tue, 14 Mar 2017 15:19:02 +0200 Subject: [PATCH] currentuser --- drupal/modules/epal/epal.routing.yml | 4 +- .../epal/src/Controller/CurrentUser.php | 66 ++++++++++++------- source/components/home.ts | 10 +-- .../components/navbar/navbar.component.html | 2 +- source/services/helper-data-service.ts | 19 +++++- source/store/logininfo/logininfo.reducer.ts | 2 +- .../store/logininfo/logininfo.transformers.ts | 2 +- source/store/logininfo/logininfo.types.ts | 1 - 8 files changed, 67 insertions(+), 39 deletions(-) diff --git a/drupal/modules/epal/epal.routing.yml b/drupal/modules/epal/epal.routing.yml index e3475f5..d1d9414 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 70977ef..218e3ad 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 46832fa..8e8efa4 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 c424ab8..e7ec39c 100644 --- a/source/components/navbar/navbar.component.html +++ b/source/components/navbar/navbar.component.html @@ -1,4 +1,4 @@ -