add account state as parameter for user search, transmit to login-server and update handling by selecting from community server

This commit is contained in:
Dario Rekowski on RockPI 2021-03-22 12:07:52 +00:00
parent 83ab670858
commit ffe6aefa13
4 changed files with 59 additions and 23 deletions

View File

@ -55,7 +55,7 @@ class JsonRequestClientComponent extends Component
]), '/getRunningUserTasks'); ]), '/getRunningUserTasks');
} }
public function getUsers($session_id, $searchString) public function getUsers($session_id, $searchString, $accountState)
{ {
if($searchString == "") { if($searchString == "") {
return ['state' => 'error', 'type' => 'parameter error', 'msg' => 'search string is empty']; return ['state' => 'error', 'type' => 'parameter error', 'msg' => 'search string is empty'];
@ -66,7 +66,8 @@ class JsonRequestClientComponent extends Component
return $this->sendRequest(json_encode([ return $this->sendRequest(json_encode([
'session_id' => $session_id, 'session_id' => $session_id,
'search' => $searchString 'search' => $searchString,
'account_state' => $accountState,
]), '/getUsers'); ]), '/getUsers');
} }

View File

@ -99,9 +99,14 @@ class StateUsersController extends AppController
//$this->set('timeUsed', $timeUsed); //$this->set('timeUsed', $timeUsed);
$csfr_token = $this->request->getParam('_csrfToken'); $csfr_token = $this->request->getParam('_csrfToken');
$this->set(compact('timeUsed', 'searchForm', 'csfr_token')); $this->set(compact('timeUsed', 'searchForm', 'csfr_token'));
$empty_string = '... empty ...';
if ($this->request->is('post')) { if ($this->request->is('post')) {
$finalUserEntrys = [];
$requestData = $this->request->getData(); $requestData = $this->request->getData();
$account_state = $requestData['account_state'];
if($requestData['search'] == '' && $account_state != 'all') {
$requestData['search'] = $empty_string;
}
if ($searchForm->validate($requestData)) { if ($searchForm->validate($requestData)) {
//var_dump($requestData); //var_dump($requestData);
@ -111,7 +116,7 @@ class StateUsersController extends AppController
$searchType = 'email'; $searchType = 'email';
} }
// find users on login server // find users on login server
$resultJson = $this->JsonRequestClient->getUsers($session->read('session_id'), $searchString); $resultJson = $this->JsonRequestClient->getUsers($session->read('session_id'), $searchString, $account_state);
$loginServerUser = []; $loginServerUser = [];
if ($resultJson['state'] == 'success') { if ($resultJson['state'] == 'success') {
$dataJson = $resultJson['data']; $dataJson = $resultJson['data'];
@ -139,19 +144,32 @@ class StateUsersController extends AppController
} }
} }
// find user on community server db // find user on community server db
$globalSearch = '%' . $searchString . '%';
$communityUsers = $this->StateUsers $communityUsers = $this->StateUsers
->find('all') ->find('all')
->contain(['StateBalances' => ['fields' => ['amount', 'state_user_id']]]); ->contain(['StateBalances' => ['fields' => ['amount', 'state_user_id']]]);
if($account_state == 'email not activated') {
if(count($pubkeySorted) > 0) {
$communityUsers->where(['hex(public_key) IN' => array_keys($pubkeySorted)]);
} else {
$communityUsers = null;
}
} else {
$globalSearch = '%' . $searchString . '%';
$communityUsers->where(['OR' => [ $communityUsers->where(['OR' => [
'first_name LIKE' => $globalSearch, 'first_name LIKE' => $globalSearch,
'last_name LIKE' => $globalSearch, 'last_name LIKE' => $globalSearch,
//'username LIKE' => $globalSearch, //'username LIKE' => $globalSearch,
'email LIKE' => $globalSearch 'email LIKE' => $globalSearch
]]); ]]);
}
//var_dump($communityUsers->toArray()); //var_dump($communityUsers->toArray());
if($communityUsers) {
foreach ($communityUsers as $u) { foreach ($communityUsers as $u) {
$pubkey_hex = bin2hex(stream_get_contents($u->public_key)); $pubkey_hex = bin2hex(stream_get_contents($u->public_key));
$u->public_hex = $pubkey_hex; $u->public_hex = $pubkey_hex;
@ -160,7 +178,8 @@ class StateUsersController extends AppController
} }
array_push($pubkeySorted[$pubkey_hex]['community'], $u); array_push($pubkeySorted[$pubkey_hex]['community'], $u);
} }
$finalUserEntrys = []; }
// detect states // detect states
foreach ($pubkeySorted as $pubhex => $user) { foreach ($pubkeySorted as $pubhex => $user) {
$finalUser = []; $finalUser = [];

View File

@ -11,7 +11,9 @@ class UserSearchForm extends Form
protected function _buildSchema(Schema $schema) protected function _buildSchema(Schema $schema)
{ {
return $schema->addField('search', ['type' => 'string']); return $schema
->addField('search', ['type' => 'string'])
->addField('account_state', ['type' => 'select']);
} }
function validationDefault(Validator $validator) function validationDefault(Validator $validator)

View File

@ -11,6 +11,19 @@ $this->assign('title', __('Benutzer suchen'));
$this->loadHelper('Form', [ $this->loadHelper('Form', [
'templates' => 'horizontal_form', 'templates' => 'horizontal_form',
]); ]);
$stateOptions = [
'all' => __('Alle'),
//'account created'=>__('Konto angelegt'),
//'account not on login-server' => __('Konto nicht auf Login-Server'),
//'email activated' => __('Konto aktiviert'),
//'account copied to community' => __('Konto auf Gemeinschafts-Server'),
'email not activated' => __('Konto nicht aktiviert'),
//'account multiple times on login-server' => __('Konto mehrfach vorhanden'),
//'account not on community server' => __('Konto nicht auf Gemeinschafts-Server'),
//'no keys' => __('Keine Schlüssel generiert')
];
?> ?>
<?= $this->Html->css([ <?= $this->Html->css([
'loginServer/style.css', 'loginServer/style.css',
@ -41,7 +54,8 @@ $this->loadHelper('Form', [
<p class="form-header">Benutzer suchen</p> <p class="form-header">Benutzer suchen</p>
<div class="form-body"> <div class="form-body">
<?= $this->Form->create($searchForm, []) ?> <?= $this->Form->create($searchForm, []) ?>
<?= $this->Form->control('search', ['label' => __('Suchbegriff'), 'class' => 'form-control', 'id' => 'inlineFormInputGroup', 'placeholder' => __('Vorname/Nachname/E-Mail')]) ?> <?= $this->Form->control('search', ['label' => __('Suchbegriff'), 'class' => 'form-control', 'id' => 'inlineFormInputGroup', 'placeholder' => __('Vorname/Nachname/E-Mail'), 'required' => false]) ?>
<?= $this->Form->control('account_state', ['label' => __('Konto Status'), 'class' => 'form-control', 'type' => 'select', 'options' => $stateOptions]) ?>
<?= $this->Form->button('<i class="material-icons-outlined">search</i>&nbsp;' . __('Suchen'), ['class' => 'form-button']) ?> <?= $this->Form->button('<i class="material-icons-outlined">search</i>&nbsp;' . __('Suchen'), ['class' => 'form-button']) ?>
<?= $this->Form->hidden('order_row', ['id' => 'input-order-row']) ?> <?= $this->Form->hidden('order_row', ['id' => 'input-order-row']) ?>
</div> </div>