reset php changes

This commit is contained in:
einhorn_b 2021-09-23 16:44:23 +02:00
parent 7d723986ce
commit 1952844c80
24 changed files with 85 additions and 75 deletions

View File

@ -223,22 +223,22 @@ class AppController extends Controller
$public_key_bin = hex2bin($json['user']['public_hex']);
$stateUserQuery = $stateUserTable
->find('all')
->where(['pubkey' => $public_key_bin])
->where(['public_key' => $public_key_bin])
->contain('StateBalances', function ($q) {
return $q->order(['record_date' => 'DESC'])
->limit(1);
});
if ($stateUserQuery->count() == 1) {
$stateUser = $stateUserQuery->first();
if ($stateUser->firstName != $json['user']['first_name'] ||
$stateUser->lastName != $json['user']['last_name'] ||
if ($stateUser->first_name != $json['user']['first_name'] ||
$stateUser->last_name != $json['user']['last_name'] ||
$stateUser->disabled != $json['user']['disabled'] ||
//$stateUser->username != $json['user']['username'] ||
// -> throws error
$stateUser->email != $json['user']['email']
) {
$stateUser->firstName = $json['user']['first_name'];
$stateUser->lastName = $json['user']['last_name'];
$stateUser->first_name = $json['user']['first_name'];
$stateUser->last_name = $json['user']['last_name'];
$stateUser->disabled = intval($json['user']['disabled']);
//$stateUser->username = $json['user']['username'];
$stateUser->email = $json['user']['email'];
@ -250,9 +250,9 @@ class AppController extends Controller
//echo $stateUser['id'];
} else {
$newStateUser = $stateUserTable->newEntity();
$newStateUser->pubkey = $public_key_bin;
$newStateUser->firstName = $json['user']['first_name'];
$newStateUser->lastName = $json['user']['last_name'];
$newStateUser->public_key = $public_key_bin;
$newStateUser->first_name = $json['user']['first_name'];
$newStateUser->last_name = $json['user']['last_name'];
$newStateUser->disabled = intval($json['user']['disabled']);
//$newStateUser->username = $json['user']['username'];
$newStateUser->email = $json['user']['email'];

View File

@ -308,7 +308,7 @@ class JsonRequestHandlerController extends AppController {
$stateError = $stateErrorTable->newEntity();
//
$pubkey = hex2bin($jsonData->public_key);
$user_query = $stateUsersTable->find('all')->select(['id'])->where(['pubkey' => $pubkey]);
$user_query = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $pubkey]);
if($user_query->count() != 1) {
return $this->returnJson(['state' => 'error', 'msg' => 'user not found', 'details' => 'user pubkey hex:' . $jsonData->public_key]);
}
@ -412,7 +412,7 @@ class JsonRequestHandlerController extends AppController {
//$pubkeys->sender
//$pubkeys->receiver
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
$user = $stateUserTable->find('all')->where(['pubkey' => hex2bin($pubkeys->sender)])->contain(['StateBalances']);
$user = $stateUserTable->find('all')->where(['public_key' => hex2bin($pubkeys->sender)])->contain(['StateBalances']);
if(!$user->count()) {
return $this->returnJson(['state' => 'not found', 'msg' => 'user not found or empty balance']);
}
@ -461,7 +461,7 @@ class JsonRequestHandlerController extends AppController {
private function userDelete($userPubkeyHex) {
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
$user = $stateUserTable->find('all')->where(['pubkey' => hex2bin($userPubkeyHex)]);
$user = $stateUserTable->find('all')->where(['public_key' => hex2bin($userPubkeyHex)]);
if(!$user || $user->count == 0) {
return $this->returnJson(['state' => 'error', 'msg' => 'user not found']);
}

View File

@ -132,7 +132,7 @@ class StateUserRolesController extends AppController
$public_hex = hex2bin($requestData['public_hex']);
$stateUser = $this->StateUsers->find('all')->where(['pubkey' => $public_hex])->first();
$stateUser = $this->StateUsers->find('all')->where(['public_key' => $public_hex])->first();
foreach($requestData['role_id'] as $role_id)
{
@ -158,7 +158,7 @@ class StateUserRolesController extends AppController
$publichex = hex2bin($public_hex);
$stateUser = $this->StateUsers->find('all')->where(['pubkey' => $publichex])->first();
$stateUser = $this->StateUsers->find('all')->where(['public_key' => $publichex])->first();
$stateUserRoles = $this->StateUserRoles->find('all')->where(['state_user_id' => $stateUser->id])->all();

View File

@ -182,15 +182,15 @@ class StateUsersController extends AppController
if($account_state == 'email not activated') {
if(count($pubkeySorted) > 0) {
$communityUsers->where(['hex(pubkey) IN' => array_keys($pubkeySorted)]);
$communityUsers->where(['hex(public_key) IN' => array_keys($pubkeySorted)]);
} else {
$communityUsers = null;
}
} else {
$globalSearch = '%' . $searchString . '%';
$communityUsers->where(['OR' => [
'firstName LIKE' => $globalSearch,
'lastName LIKE' => $globalSearch,
'first_name LIKE' => $globalSearch,
'last_name LIKE' => $globalSearch,
'email LIKE' => $globalSearch
]]);
}
@ -199,7 +199,7 @@ class StateUsersController extends AppController
//var_dump($communityUsers->toArray());
if($communityUsers) {
foreach($communityUsers as $u) {
$pubkey_hex = bin2hex(stream_get_contents($u->pubkey));
$pubkey_hex = bin2hex(stream_get_contents($u->public_key));
$u->public_hex = $pubkey_hex;
if(!isset($pubkeySorted[$pubkey_hex])) {
$pubkeySorted[$pubkey_hex] = ['login' => [], 'community' => []];
@ -229,9 +229,9 @@ class StateUsersController extends AppController
$color = 'danger';
if(count($user['community']) == 1) {
$c_user = $user['community'][0];
$finalUser['name'] = $c_user->firstName . ' ' . $c_user->lastName;
$finalUser['first_name'] = $c_user->firstName;
$finalUser['last_name'] = $c_user->lastName;
$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['email'] = $c_user->email;
}
} else if(count($user['login']) == 1) {
@ -415,7 +415,7 @@ class StateUsersController extends AppController
//$user = $jsonData['user'];
//var_dump($jsonData);
$pubkey = hex2bin($jsonData['pubkeyhex']);
$stateUsers = $this->StateUsers->find('all')->where(['pubkey' => $pubkey]);
$stateUsers = $this->StateUsers->find('all')->where(['public_key' => $pubkey]);
if($stateUsers->count() != 1) {
return $this->returnJson(['state' => 'error', 'msg' => 'invalid result count']);
}
@ -448,7 +448,7 @@ class StateUsersController extends AppController
$pubkey = hex2bin($jsonData['pubkeyhex']);
$stateUsers = $this->StateUsers
->find('all')
->where(['pubkey' => $pubkey])
->where(['public_key' => $pubkey])
->select(['id']);
if($stateUsers->count() != 1) {
return $this->returnJson(['state' => 'error', 'msg' => 'invalid result count']);

View File

@ -101,7 +101,7 @@ class TransactionCreationsController extends AppController
$receiverProposal = [];
foreach ($stateUsers as $stateUser) {
$name = $stateUser->email;
$keyHex = bin2hex(stream_get_contents($stateUser->pubkey));
$keyHex = bin2hex(stream_get_contents($stateUser->public_key));
if ($name === null) {
$name = $stateUser->first_name . ' ' . $stateUser->last_name;
}
@ -241,14 +241,14 @@ class TransactionCreationsController extends AppController
$this->log("search for text: ".$requestData['searchText'], 'debug');
$stateUsers = $stateUserTable
->find('all')
->select(['id', 'firstName', 'lastName', 'email'])
->order(['firstName', 'lastName'])
->select(['id', 'first_name', 'last_name', 'email'])
->order(['first_name', 'last_name'])
->where(
['AND' => [
'disabled' => 0,
'OR' => [
'LOWER(firstName) LIKE' => '%'.strtolower($requestData['searchText']).'%',
'LOWER(lastName) LIKE' => '%'.strtolower($requestData['searchText']).'%',
'LOWER(first_name) LIKE' => '%'.strtolower($requestData['searchText']).'%',
'LOWER(last_name) LIKE' => '%'.strtolower($requestData['searchText']).'%',
'LOWER(email) LIKE' => '%'.strtolower($requestData['searchText']).'%'
]
]
@ -265,10 +265,10 @@ class TransactionCreationsController extends AppController
} else {
$stateUsers = $stateUserTable
->find('all')
->select(['id', 'firstName', 'lastName', 'email'])
->select(['id', 'first_name', 'last_name', 'email'])
//->order(['id'])
->where(['disabled' => 0])
->order(['firstName', 'lastName'])
->order(['first_name', 'last_name'])
->contain(['TransactionCreations' => [
'fields' => [
'TransactionCreations.amount',
@ -300,7 +300,7 @@ class TransactionCreationsController extends AppController
//if($sumAmount < 20000000) {
array_push($possibleReceivers, [
'name' => $stateUser->firstName . '&nbsp;' . $stateUser->lastName,
'name' => $stateUser->first_name . '&nbsp;' . $stateUser->last_name,
'id' => $stateUser->id,
'email' => $stateUser->email,
'amount' => $sumAmount,
@ -353,7 +353,7 @@ class TransactionCreationsController extends AppController
}
$receiverUsers = $stateUserTable->find('all')
->where(['id IN' => array_keys($users)])
->select(['pubkey', 'email', 'id'])
->select(['public_key', 'email', 'id'])
->contain(false);
foreach ($receiverUsers as $receiverUser) {
@ -371,7 +371,7 @@ class TransactionCreationsController extends AppController
} else {
$pendings[$id] = $localAmountCent;
}
$pubKeyHex = bin2hex(stream_get_contents($receiverUser->pubkey));
$pubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key));
$requestAnswear = $this->JsonRequestClient->sendRequest(json_encode([
'session_id' => $session->read('session_id'),
'email' => $receiverUser->email,

View File

@ -30,14 +30,16 @@ class StateUser extends Entity
* @var array
*/
protected $_accessible = [
'groupId' => true,
'pubkey' => true,
'index_id' => true,
'state_group_id' => true,
'public_key' => true,
'email' => true,
'firstName' => true,
'lastName' => true,
'first_name' => true,
'last_name' => true,
'disabled' => true,
'username' => true,
'index' => true,
'state_group' => true,
'state_balances' => true,
'state_created' => true,
'transaction_creations' => true,
@ -46,11 +48,11 @@ class StateUser extends Entity
public function getEmailWithName()
{
return $this->firstName . ' ' . $this->lastName . ' <' . $this->email . '>';
return $this->first_name . ' ' . $this->last_name . ' <' . $this->email . '>';
}
public function getNames()
{
return $this->firstName . ' ' . $this->lastName;
return $this->first_name . ' ' . $this->last_name;
}
}

View File

@ -40,7 +40,7 @@ class AdminErrorsTable extends Table
$this->addBehavior('Timestamp');
$this->belongsTo('User', [
$this->belongsTo('StateUsers', [
'foreignKey' => 'state_user_id',
'joinType' => 'INNER'
]);
@ -100,7 +100,7 @@ class AdminErrorsTable extends Table
*/
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn(['state_user_id'], 'User'));
$rules->add($rules->existsIn(['state_user_id'], 'StateUsers'));
return $rules;
}

View File

@ -37,10 +37,18 @@ class StateUsersTable extends Table
{
parent::initialize($config);
$this->setTable('user');
$this->setTable('state_users');
$this->setDisplayField('email');
$this->setPrimaryKey('id');
/*$this->belongsTo('Indices', [
'foreignKey' => 'index_id',
'joinType' => 'INNER'
]);*/
$this->belongsTo('StateGroups', [
'foreignKey' => 'state_group_id',
'joinType' => 'INNER'
]);
$this->hasMany('StateBalances', [
'foreignKey' => 'state_user_id'
]);
@ -72,8 +80,8 @@ class StateUsersTable extends Table
->allowEmptyString('id', null, 'create');
$validator
->requirePresence('pubkey', 'create')
->notEmptyString('pubkey');
->requirePresence('public_key', 'create')
->notEmptyString('public_key');
return $validator;
}
@ -116,7 +124,7 @@ class StateUsersTable extends Table
$involvedUser = $this->find('all', [
'contain' => [],
'where' => ['id IN' => $involvedUserIds],
'fields' => ['id', 'firstName', 'lastName', 'email'],
'fields' => ['id', 'first_name', 'last_name', 'email'],
]);
//var_dump($involvedUser->toArray());
$involvedUserIndices = [];

View File

@ -49,13 +49,13 @@ class TransactionBase {
protected function getStateUserId($publicKey) {
$stateUsersTable = self::getTable('state_users');
$stateUser = $stateUsersTable->find('all')->select(['id'])->where(['pubkey' => $publicKey])->first();
$stateUser = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $publicKey])->first();
if($stateUser) {
return $stateUser->id;
}
// create new entry
$stateUserEntity = $stateUsersTable->newEntity();
$stateUserEntity->pubkey = $publicKey;
$stateUserEntity->public_key = $publicKey;
if($stateUsersTable->save($stateUserEntity)) {
return $stateUserEntity->id;
} else {
@ -77,7 +77,7 @@ class TransactionBase {
protected function getStateUserFromPublickey($publicKey) {
$stateUsersTable = self::getTable('state_users');
$stateUser = $stateUsersTable->find('all')->where(['pubkey' => $publicKey])->first();
$stateUser = $stateUsersTable->find('all')->where(['public_key' => $publicKey])->first();
if($stateUser) {
return $stateUser;
}

View File

@ -95,7 +95,7 @@ class TransactionCreation extends TransactionBase {
$existingCreations2 = $this->transactionCreationsTable
->find('all')
->select(['amount', 'state_user_id', 'target_date'])
->contain(['StateUsers' => ['fields' => ['StateUsers.pubkey']]]);
->contain(['StateUsers' => ['fields' => ['StateUsers.public_key']]]);
$q = $existingCreations2;
$targetDate = $this->protoTransactionCreation->getTargetDate();
@ -230,7 +230,7 @@ class TransactionCreation extends TransactionBase {
$receiverAmount = new \Proto\Gradido\TransferAmount();
$receiverAmount->setPubkey(stream_get_contents($stateUser->pubkey));
$receiverAmount->setPubkey(stream_get_contents($stateUser->public_key));
$receiverAmount->setAmount($transactionCreationEntity->amount);
$protoCreation->setReceiver($receiverAmount);

View File

@ -96,7 +96,7 @@ class TransactionTransfer extends TransactionBase {
$user = $stateUsersTable
->find('all')
->select(['id'])
->where(['pubkey' => $senderPublic])
->where(['public_key' => $senderPublic])
->contain(['StateBalances' => ['fields' => ['amount', 'state_user_id']]])->first();
if(!$user) {
$this->addError($functionName, 'couldn\'t find sender in db' );
@ -114,7 +114,7 @@ class TransactionTransfer extends TransactionBase {
return false;
}
// check if receiver exist
$receiver_user = $stateUsersTable->find('all')->select(['id'])->where(['pubkey' => $receiver_public_key])->first();
$receiver_user = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $receiver_public_key])->first();
if(!$receiver_user) {
$this->addError($functionName, 'couldn\'t find receiver in db' );
return false;

View File

@ -6,9 +6,8 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* StateUsersFixture
*/
class UserFixture extends BaseTestFixture
class StateUsersFixture extends BaseTestFixture
{
public $import = [ 'model' => 'StateUsers', 'connection' => 'test' ];
/**
* Fields
*
@ -17,16 +16,17 @@ class UserFixture extends BaseTestFixture
// @codingStandardsIgnoreStart
public $fields = [
'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'groupId' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'pubkey' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'index_id' => ['type' => 'smallinteger', 'length' => 6, 'unsigned' => false, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null],
'group_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'public_key' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'email' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'firstNname' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'lastName' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'first_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'last_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'username' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'disabled' => ['type' => 'tinyinteger', 'length' => 4, 'unsigned' => false, 'null' => true, 'default' => '0', 'comment' => '', 'precision' => null],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
'pubkey' => ['type' => 'unique', 'columns' => ['pubkey'], 'length' => []],
'public_key' => ['type' => 'unique', 'columns' => ['public_key'], 'length' => []],
],
'_options' => [
'engine' => 'InnoDB',
@ -44,9 +44,9 @@ class UserFixture extends BaseTestFixture
public function init()
{
$sql_entrys = [
[1, 0, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0],
[3, 0, '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6', 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0],
[4, 0, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0]
[1, 0, 0, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0],
[3, 0, 0, '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6', 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0],
[4, 0, 0, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0]
];
$this->records = $this->sqlEntrysToRecords($sql_entrys, $this->fields);
parent::init();

View File

@ -21,7 +21,7 @@ class AdminErrorsControllerTest extends TestCase
*/
public $fixtures = [
'app.AdminErrors',
'app.User'
'app.StateUsers'
];
/**

View File

@ -21,7 +21,7 @@ class JsonRequestHandlerControllerTest extends TestCase
public $fixtures = [
'app.TransactionCreations',
'app.Transactions',
'app.User',
'app.StateUsers',
'app.StateUserTransactions',
'app.StateErrors',
'app.TransactionSignatures',

View File

@ -20,7 +20,7 @@ class ProfilesControllerTest extends TestCase
* @var array
*/
public $fixtures = [
'app.User',
'app.StateUsers',
'app.CommunityProfiles',
];

View File

@ -24,7 +24,7 @@ class StateBalancesControllerTest extends TestCase
public $fixtures = [
'app.TransactionCreations',
'app.Transactions',
'app.User',
'app.StateUsers',
'app.StateUserTransactions',
'app.StateErrors',
'app.TransactionSignatures',

View File

@ -21,7 +21,7 @@ class StateErrorsControllerTest extends TestCase
*/
public $fixtures = [
'app.StateErrors',
'app.User',
'app.StateUsers',
'app.TransactionTypes'
];

View File

@ -21,7 +21,7 @@ class StateUserTransactionsControllerTest extends TestCase
*/
public $fixtures = [
'app.StateUserTransactions',
'app.User',
'app.StateUsers',
'app.Transactions',
'app.TransactionTypes',
];

View File

@ -22,7 +22,7 @@ class TransactionCreationsControllerTest extends TestCase
public $fixtures = [
'app.TransactionCreations',
'app.Transactions',
'app.User'
'app.StateUsers'
];
/**

View File

@ -24,7 +24,7 @@ class AdminErrorsTableTest extends TestCase
*/
public $fixtures = [
'app.AdminErrors',
'app.User'
'app.StateUsers'
];
/**

View File

@ -24,7 +24,7 @@ class StateBalancesTableTest extends TestCase
*/
public $fixtures = [
'app.StateBalances',
'app.User',
'app.StateUsers',
];
/**

View File

@ -24,7 +24,7 @@ class StateErrorsTableTest extends TestCase
*/
public $fixtures = [
'app.StateErrors',
'app.User',
'app.StateUsers',
'app.TransactionTypes'
];

View File

@ -24,7 +24,7 @@ class StateUserTransactionsTableTest extends TestCase
*/
public $fixtures = [
'app.StateUserTransactions',
'app.User',
'app.StateUsers',
'app.Transactions',
'app.TransactionTypes',
];

View File

@ -23,7 +23,7 @@ class StateUsersTableTest extends TestCase
* @var array
*/
public $fixtures = [
'app.User',
'app.StateUsers',
'app.StateGroups',
'app.StateBalances',
'app.StateCreated',
@ -39,8 +39,8 @@ class StateUsersTableTest extends TestCase
public function setUp()
{
parent::setUp();
$config = TableRegistry::getTableLocator()->exists('User') ? [] : ['className' => StateUsersTable::class];
$this->StateUsersTable = TableRegistry::getTableLocator()->get('User', $config);
$config = TableRegistry::getTableLocator()->exists('StateUsers') ? [] : ['className' => StateUsersTable::class];
$this->StateUsersTable = TableRegistry::getTableLocator()->get('StateUsers', $config);
}
/**