mirror of
https://github.com/twisterarmy/cloud-server.git
synced 2025-03-13 05:51:46 +00:00
implement registration feature
This commit is contained in:
parent
2139747c75
commit
12b96ec3ea
@ -1,21 +1,79 @@
|
||||
<?php
|
||||
|
||||
// Redirect to the login page on active session
|
||||
if (isset($_SESSION['username'])) {
|
||||
header('Location: ' . PROJECT_HOST, true, 302);
|
||||
}
|
||||
|
||||
// Define variables
|
||||
$userName = false;
|
||||
$errorUserName = false;
|
||||
|
||||
$blockEstimated = $_modelBlock->getTotal() + 1;
|
||||
|
||||
$metaTitle = _('Register | Twisterarmy Cloud');
|
||||
|
||||
require(PROJECT_DIR . '/application/view/register.phtml');
|
||||
// Check registration enabled
|
||||
if (!APPLICATION_ALLOW_REGISTRATION) {
|
||||
|
||||
// @TODO welcome message
|
||||
require(PROJECT_DIR . '/application/view/register_off.phtml');
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
$metaTitle = _('Welcome | Twisterarmy Cloud');
|
||||
// Process form request
|
||||
if (isset($_POST) && $_POST) {
|
||||
|
||||
$blockEstimated = 0;
|
||||
$userName = 'userName';
|
||||
$userPrivateKey = '0000000000000000000000000000000000000000';
|
||||
// Validate userName
|
||||
if (!isset($_POST['userName'])) {
|
||||
|
||||
require(PROJECT_DIR . '/application/view/welcome.phtml');
|
||||
*/
|
||||
$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) {
|
||||
|
||||
$errorUserName = _('Username required.');
|
||||
}
|
||||
|
||||
if ($_modelUser->userNameExists($userName)) {
|
||||
|
||||
$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/register_on.phtml');
|
17
src/application/view/register_on.phtml
Normal file
17
src/application/view/register_on.phtml
Normal file
@ -0,0 +1,17 @@
|
||||
<?php include(PROJECT_DIR . '/application/controller/common/header.php') ?>
|
||||
<div class="mw-1024 mx-auto of-hidden">
|
||||
<div class="mw-360 mx-auto my-100 bg-c-4 b-r-3 py-28 px-24">
|
||||
<h1 class="f-size-20 f-normal mb-20"><?php echo _('Register') ?></h1>
|
||||
<form action="register" name="register" method="POST">
|
||||
<input type="text" name="userName" value="<?php echo $userName ?>" placeholder="<?php echo _('Username') ?>" class="input-text mb-22" />
|
||||
<?php if ($errorUserName) { ?>
|
||||
<div class="c-5 mb-22"><?php echo $errorUserName ?></div>
|
||||
<?php } ?>
|
||||
<div class="mt-4">
|
||||
<button type="submit" class="btn btn-1"><?php echo sprintf(_('~ %s'), $blockEstimated) ?></button>
|
||||
<a class="c-1 ml-16" href="login"><?php echo _('Login') ?></a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php include(PROJECT_DIR . '/application/controller/common/footer.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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user