From 12b96ec3eac1853aeb098535514edb1bf2530f98 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 29 Dec 2021 05:42:09 +0200 Subject: [PATCH] implement registration feature --- src/application/controller/register.php | 76 ++++++++++++++++--- .../{register.phtml => register_off.phtml} | 0 src/application/view/register_on.phtml | 17 +++++ src/system/twister.php | 62 +++++++++++++++ 4 files changed, 146 insertions(+), 9 deletions(-) rename src/application/view/{register.phtml => register_off.phtml} (100%) create mode 100644 src/application/view/register_on.phtml diff --git a/src/application/controller/register.php b/src/application/controller/register.php index 7b6e62e..5efe332 100644 --- a/src/application/controller/register.php +++ b/src/application/controller/register.php @@ -1,21 +1,79 @@ getTotal() + 1; + $metaTitle = _('Register | Twisterarmy Cloud'); -require(PROJECT_DIR . '/application/view/register.phtml'); +// Check registration enabled +if (!APPLICATION_ALLOW_REGISTRATION) { + + require(PROJECT_DIR . '/application/view/register_off.phtml'); + exit; +} + +// Process form request +if (isset($_POST) && $_POST) { + + // Validate userName + if (!isset($_POST['userName'])) { + + $errorUserName = _('Username value required.'); + + } else { + + if (!Valid::userName($_POST['userName'])) { + + $errorUserName = _('Username must contain a-z_0-9 up to 16 chars.'); + } + + $userName = Filter::userName($_POST['userName']); + + if (!$userName) { -// @TODO welcome message + $errorUserName = _('Username required.'); + } -/* -$metaTitle = _('Welcome | Twisterarmy Cloud'); + if ($_modelUser->userNameExists($userName)) { -$blockEstimated = 0; -$userName = 'userName'; -$userPrivateKey = '0000000000000000000000000000000000000000'; + $errorUserName = _('Username already taken.'); + } + } + + // Request valid + if (!$errorUserName) { + + // Generate new wallet + if ($userPrivateKey = $_twister->createWalletUser($userName)) { + + // Post new user public key to the network + if ($transaction = $_twister->sendNewUserTransaction($userName)) { + + // Prepare Welcome page + $metaTitle = _('Welcome | Twisterarmy Cloud'); + + require(PROJECT_DIR . '/application/view/welcome.phtml'); + + exit; + + } else { + + trigger_error($_twister->getError()); + } + + } else { + + trigger_error($_twister->getError()); + } + } +} -require(PROJECT_DIR . '/application/view/welcome.phtml'); -*/ \ No newline at end of file +require(PROJECT_DIR . '/application/view/register_on.phtml'); \ No newline at end of file diff --git a/src/application/view/register.phtml b/src/application/view/register_off.phtml similarity index 100% rename from src/application/view/register.phtml rename to src/application/view/register_off.phtml diff --git a/src/application/view/register_on.phtml b/src/application/view/register_on.phtml new file mode 100644 index 0000000..3eeae89 --- /dev/null +++ b/src/application/view/register_on.phtml @@ -0,0 +1,17 @@ + +
+
+

+
+ + +
+ +
+ + +
+
+
+
+ \ No newline at end of file diff --git a/src/system/twister.php b/src/system/twister.php index 0355c3d..01cbade 100644 --- a/src/system/twister.php +++ b/src/system/twister.php @@ -108,4 +108,66 @@ class Twister { return false; } + + public function createWalletUser(string $userName) { + + $this->_curl->prepare( + '/', + 'POST', + 30, + [ + 'jsonrpc' => '2.0', + 'method' => 'createwalletuser', + 'params' => [ + $userName + ], + 'id' => time() + rand() + ] + ); + + if ($response = $this->_curl->execute()) { + + if ($response['error']) { + + $this->_error = _($response['error']['message']); + + } else { + + return $response['result']; + } + } + + return false; + } + + public function sendNewUserTransaction(string $userName) { + + $this->_curl->prepare( + '/', + 'POST', + 30, + [ + 'jsonrpc' => '2.0', + 'method' => 'sendnewusertransaction', + 'params' => [ + $userName + ], + 'id' => time() + rand() + ] + ); + + if ($response = $this->_curl->execute()) { + + if ($response['error']) { + + $this->_error = _($response['error']['message']); + + } else { + + return $response['result']; + } + } + + return false; + } } \ No newline at end of file