From 35b14d7480c66f54c40392fd01a68f1335503d41 Mon Sep 17 00:00:00 2001 From: team-devstage Date: Fri, 25 Sep 2020 15:01:33 +0200 Subject: [PATCH] cleanup samirs code, remove not needed stuff from my old code -Dario --- src/Controller/StateUserRolesController.php | 142 ++------------------ src/Template/StateUserRoles/search.ctp | 27 ---- 2 files changed, 10 insertions(+), 159 deletions(-) diff --git a/src/Controller/StateUserRolesController.php b/src/Controller/StateUserRolesController.php index b61d6b82b..9f83dc0bc 100644 --- a/src/Controller/StateUserRolesController.php +++ b/src/Controller/StateUserRolesController.php @@ -34,7 +34,7 @@ class StateUserRolesController extends AppController parent::initialize(); $this->loadComponent('JsonRequestClient'); $this->Auth->allow([ - 'search' +// 'search' ]); $this->set( 'naviHierarchy', @@ -49,22 +49,12 @@ class StateUserRolesController extends AppController $startTime = microtime(true); I18n::setLocale('de_DE'); $this->viewBuilder()->setLayout('frontend'); - $session = $this->getRequest()->getSession(); - $result = $this->requestLogin(); - if ($result !== true) { - return $result; - } - $user = $session->read('StateUser'); - if ($user['role'] != 'admin') { - return $this->redirect(['controller' => 'dashboard', 'action' => 'index']); - } $searchForm = new UserSearchForm(); $timeUsed = microtime(true) - $startTime; //$this->set('timeUsed', $timeUsed); - $csfr_token = $this->request->getParam('_csrfToken'); - $this->set(compact('timeUsed', 'searchForm', 'csfr_token')); + $this->set(compact('timeUsed', 'searchForm')); if ($this->request->is('post')) { $requestData = $this->request->getData(); @@ -72,43 +62,12 @@ class StateUserRolesController extends AppController if ($searchForm->validate($requestData)) { //var_dump($requestData); $searchString = $requestData['search']; - $searchType = 'unknown'; - if (GenericValidation::email($searchString, [])) { - $searchType = 'email'; - } - // find users on login server - $resultJson = $this->JsonRequestClient->getUsers($session->read('session_id'), $searchString); - $loginServerUser = []; - if ($resultJson['state'] == 'success') { - $dataJson = $resultJson['data']; - if ($dataJson['state'] != 'success') { - if ($dataJson['msg'] == 'session not found') { - $session->destroy(); - return $this->redirect(Router::url('/', true) . 'account', 303); - } - } - //var_dump($dataJson); - if (isset($dataJson['users'])) { - $loginServerUser = $dataJson['users']; - } - } - $pubkeySorted = []; - $emptyPubkeys = []; - foreach ($loginServerUser as $u) { - if (!isset($u['public_hex']) || $u['public_hex'] == '') { - array_push($emptyPubkeys, $u); - } else { - if (!isset($pubkeySorted[$u['public_hex']])) { - $pubkeySorted[$u['public_hex']] = ['login' => [], 'community' => []]; - } - array_push($pubkeySorted[$u['public_hex']]['login'], $u); - } - } + // find user on community server db $globalSearch = '%' . $searchString . '%'; $communityUsers = $this->StateUsers ->find('all') - ->contain(['StateBalances' => ['fields' => ['amount', 'state_user_id']]]); + ->contain([]); $communityUsers->where(['OR' => [ 'first_name LIKE' => $globalSearch, @@ -118,71 +77,15 @@ class StateUserRolesController extends AppController ]]); //var_dump($communityUsers->toArray()); - foreach ($communityUsers as $u) { - $pubkey_hex = bin2hex(stream_get_contents($u->public_key)); - $u->public_hex = $pubkey_hex; - if (!isset($pubkeySorted[$pubkey_hex])) { - $pubkeySorted[$pubkey_hex] = ['login' => [], 'community' => []]; - } - array_push($pubkeySorted[$pubkey_hex]['community'], $u); - } $finalUserEntrys = []; // detect states - foreach ($pubkeySorted as $pubhex => $user) { - $finalUser = []; - $state = 'account created'; - $color = 'secondary'; - $finalUser['balance'] = 0; - $finalUser['pubkeyhex'] = $pubhex; - $finalUser['created'] = null; - - if (count($user['community']) == 1) { - if (isset($user['community'][0]->state_balances) && - isset($user['community'][0]->state_balances[0]['amount'])) { - $finalUser['balance'] = $user['community'][0]->state_balances[0]->amount; - } - } - - if (count($user['login']) == 0) { - $state = 'account not on login-server'; - $color = 'danger'; - if (count($user['community']) == 1) { - $c_user = $user['community'][0]; - $finalUser['name'] = $c_user->first_name . ' ' . $c_user->last_name; - $finalUser['first_name'] = $c_user->first_name; - $finalUser['last_name'] = $c_user->last_name; - //$finalUser['username'] = $c_user->username; - $finalUser['email'] = $c_user->email; - } - } elseif (count($user['login']) == 1) { - if ($user['login'][0]['email_checked'] == true) { - $state = 'email activated'; - $color = 'primary'; - - if (count($user['community']) == 1) { - $state = 'account copied to community'; - $color = 'success'; - //var_dump($user['community'][0]->state_balances[0]['amount']); - } - } else { - $state = 'email not activated'; - $color = 'warning'; - } - - $l_user = $user['login'][0]; - $finalUser['name'] = $l_user['first_name'] . ' ' . $l_user['last_name']; - $finalUser['first_name'] = $l_user['first_name']; - $finalUser['last_name'] = $l_user['last_name']; - //$finalUser['username'] = $l_user['username']; - $finalUser['email'] = $l_user['email']; - $finalUser['created'] = new FrozenTime($l_user['created']); - } else { - $state = 'account multiple times on login-server'; - $color = 'danger'; - } + $this->loadModel('Roles'); +// foreach ($pubkeySorted as $pubhex => $user) { + foreach($communityUsers as $communityUser) { + $finalUser = $communityUser; + $finalUser['pubkeyhex'] = bin2hex(stream_get_contents($communityUser->public_key)); - $this->loadModel('Roles'); - $state_user_id = $user['community'][0]->id; + $state_user_id = $communityUser->id; $stateUserRole = $this->StateUserRoles->find('all')->where(['state_user_id' => $state_user_id])->all(); $role_ids = ""; @@ -206,34 +109,9 @@ class StateUserRolesController extends AppController $finalUser['role_name'] = $role_names; - $finalUser['indicator'] = ['name' => $state, 'color' => $color]; array_push($finalUserEntrys, $finalUser); } - foreach ($emptyPubkeys as $user) { - $finalUser = []; - $state = 'account not on community server'; - $color = 'secondary'; - if ($user['email_checked'] == false) { - $state = 'email not activated'; - $color = 'warning'; - } else { - $state = 'no keys'; - $color = 'warning'; - } - $finalUser['balance'] = 0; - $finalUser['pubkeyhex'] = ''; - $finalUser['name'] = $user['first_name'] . ' ' . $user['last_name']; - $finalUser['first_name'] = $user['first_name']; - $finalUser['last_name'] = $user['last_name']; - //$finalUser['username'] = $user['username']; - $finalUser['email'] = $user['email']; - - - $finalUser['created'] = new FrozenTime($user['created']); - $finalUser['indicator'] = ['name' => $state, 'color' => $color]; - array_push($finalUserEntrys, $finalUser); - } //var_dump($pubkeySorted); } else { $this->Flash->error(__('Something was invalid, please try again!')); diff --git a/src/Template/StateUserRoles/search.ctp b/src/Template/StateUserRoles/search.ctp index c1234d245..aff7fbbcb 100644 --- a/src/Template/StateUserRoles/search.ctp +++ b/src/Template/StateUserRoles/search.ctp @@ -12,31 +12,6 @@ $this->loadHelper('Form', [ 'templates' => 'horizontal_form', ]); ?> -Html->css([ - 'loginServer/style.css', - 'rippleUI/style.css', - 'materialdesignicons.min.css' -]) ?> -

Benutzer suchen

@@ -76,5 +51,3 @@ $this->loadHelper('Form', [
- -