implement profile settings

This commit is contained in:
ghost 2022-01-03 01:11:11 +02:00
parent 5bb859b6d0
commit 91d0cdcc67
17 changed files with 398 additions and 11 deletions

View File

@ -47,12 +47,12 @@ if (isset($_SESSION['userName'])) {
} }
} }
// Get latest version available // Get latest version available
if ($profileInfo = $_modelProfile->get($userId)) { if ($profileInfo = $_modelProfile->get($userId)) {
$profile = [ $profile = [
'userName' => $userName, 'userName' => $userName,
'seq' => $profileInfo['seq'],
'fullName' => $profileInfo['fullName'], 'fullName' => $profileInfo['fullName'],
'location' => $profileInfo['location'], 'location' => $profileInfo['location'],
'url' => $profileInfo['url'], 'url' => $profileInfo['url'],

View File

@ -0,0 +1,3 @@
<?php
require(PROJECT_DIR . '/application/view/common/module/settings.phtml');

View File

@ -0,0 +1,173 @@
<?php
if (!isset($_SESSION['userName'])) {
header('Location: ' . PROJECT_HOST . '/login', true, 302);
}
$metaTitle = _('Profile Settings | Twisterarmy Cloud');
$pageTitle = _('Profile');
// Load dependencies
$metaStyles = [
'css/template/default/module/menu.css',
'css/template/default/module/settings.css',
'css/template/default/settings/profile.css',
];
$metaScripts = [
'js/module/menu.js',
'js/module/settings.js',
'js/settings/profile.js',
];
// Init variables
$seq = false;
$fullName = false;
$location = false;
$url = false;
$bitMessage = false;
$tox = false;
$bio = false;
$errorFullName = false;
$errorLocation = false;
$errorURL = false;
$errorBitMessage = false;
$errorTOX = false;
$errorBio = false;
// Save profile details
if (isset($_POST) && !empty($_POST)) {
// Prepare request
$seq = isset($_POST['seq']) ? $_POST['seq'] : 0;
$fullName = isset($_POST['fullName']) ? $_POST['fullName'] : '';
$location = isset($_POST['location']) ? $_POST['location'] : '';
$url = isset($_POST['url']) ? $_POST['url'] : '';
$bitMessage = isset($_POST['bitMessage']) ? $_POST['bitMessage'] : '';
$tox = isset($_POST['tox']) ? $_POST['tox'] : '';
$bio = isset($_POST['bio']) ? $_POST['bio'] : '';
// Increase revision number
$seq++;
// Get current block number
$blockId = $_modelBlock->getThisBlock();
// Save revision to DHT
$userProfileVersions = $_twister->putDHT( $_SESSION['userName'],
'profile',
's',
[
'fullname' => $fullName,
'location' => $location,
'url' => $url,
'bitmessage' => $bitMessage,
'tox' => $tox,
'bio' => $bio,
],
$_SESSION['userName'],
$seq);
// Save revision to DB
if (!$_modelProfile->versionExists($_SESSION['userId'],
$blockId,
$seq)) {
$_modelProfile->add($_SESSION['userId'],
$blockId,
$seq,
time(),
$fullName,
$bio,
$location,
$url,
$bitMessage,
$tox);
}
$_memcache->replace('api.user.profile.' . $_SESSION['userName'],
[
'userName' => $_SESSION['userName'],
'seq' => $seq,
'fullName' => $fullName,
'location' => $location,
'url' => $url,
'bitMessage' => $bitMessage,
'tox' => $tox,
'bio' => $bio,
],
MEMCACHE_COMPRESS,
MEMCACHE_DHT_PROFILE_TIMEOUT);
}
// Get profile details
if ($profile = $_memcache->get('api.user.profile.' . $_SESSION['userName'])) {
$seq = $profile['seq'];
$fullName = $profile['fullName'];
$location = $profile['location'];
$url = $profile['url'];
$bitMessage = $profile['bitMessage'];
$tox = $profile['tox'];
$bio = $profile['bio'];
} else if ($userProfileVersions = $_twister->getDHT($_SESSION['userName'], 'profile', 's')) {
// Check user exists
if ($userId = $_modelUser->getUserId($_SESSION['userName'])) {
// Add DHT version if not exists
foreach ($userProfileVersions as $userProfileVersion) {
if (!$_modelProfile->versionExists($userId,
$userProfileVersion['p']['height'],
$userProfileVersion['p']['seq'])) {
$profile = $userProfileVersion['p']['v'];
$_modelProfile->add($userId,
$userProfileVersion['p']['height'],
$userProfileVersion['p']['seq'],
$userProfileVersion['p']['time'],
isset($profile['fullname']) ? $profile['fullname'] : '',
isset($profile['bio']) ? $profile['bio'] : '',
isset($profile['location']) ? $profile['location'] : '',
isset($profile['url']) ? $profile['url'] : '',
isset($profile['bitmessage']) ? $profile['bitmessage'] : '',
isset($profile['tox']) ? $profile['tox'] : '');
}
}
}
// Get latest version available
if ($profileInfo = $_modelProfile->get($_SESSION['userId'])) {
$profile = [
'userName' => $_SESSION['userName'],
'seq' => $profileInfo['seq'],
'fullName' => $profileInfo['fullName'],
'location' => $profileInfo['location'],
'url' => $profileInfo['url'],
'bitMessage' => $profileInfo['bitMessage'],
'tox' => $profileInfo['tox'],
'bio' => $profileInfo['bio'],
];
$seq = $profile['seq'];
$fullName = $profile['fullName'];
$location = $profile['location'];
$url = $profile['url'];
$bitMessage = $profile['bitMessage'];
$tox = $profile['tox'];
$bio = $profile['bio'];
$_memcache->set('api.user.profile.' . $_SESSION['userName'], $profile, MEMCACHE_COMPRESS, MEMCACHE_DHT_PROFILE_TIMEOUT);
}
}
require(PROJECT_DIR . '/application/view/settings/profile.phtml');

View File

@ -17,6 +17,21 @@ class ModelBlock extends Model {
} }
} }
public function getThisBlock() {
try {
$query = $this->_db->query("SELECT MAX(`blockId`) AS `blockId` FROM `block`");
return $query->fetch()['blockId'];
} catch (PDOException $e) {
trigger_error($e->getMessage());
return false;
}
}
public function getNextBlock() { public function getNextBlock() {
try { try {

View File

@ -13,7 +13,7 @@
</a><a class="item" href="#todo" title="<?php echo _('Messages') ?>"> </a><a class="item" href="#todo" title="<?php echo _('Messages') ?>">
<i class="bi bi-envelope"></i> <i class="bi bi-envelope"></i>
<span></span> <span></span>
</a><a class="item" href="#todo" title="<?php echo _('Settings') ?>"> </a><a class="item" href="settings" title="<?php echo _('Settings') ?>">
<i class="bi bi-gear"></i> <i class="bi bi-gear"></i>
</a> </a>
</div> </div>

View File

@ -0,0 +1,6 @@
<div class="moduleSettings" id="moduleSettings">
<a href="settings" class="item"><?php echo _('Profile') ?></a>
<a href="#todo" class="item"><?php echo _('Interface') ?></a>
<a href="#todo" class="item"><?php echo _('Templates') ?></a>
<a href="#todo" class="item"><?php echo _('Stats') ?></a>
</div>

View File

@ -0,0 +1,48 @@
<?php include(PROJECT_DIR . '/application/controller/common/header/user.php') ?>
<div class="container">
<div class="right">
<?php include(PROJECT_DIR . '/application/controller/common/module/menu.php') ?>
<?php include(PROJECT_DIR . '/application/controller/common/module/settings.php') ?>
</div>
<div class="left">
<div class="settingsProfile">
<h1><?php echo $pageTitle ?></h1>
<form action="settings" name="profile" method="POST">
<input type="hidden" name="seq" value="<?php echo $seq ?>" />
<label for="fullName"><?php echo _('Full name') ?></label>
<input type="text" name="fullName" id="fullName" value="<?php echo $fullName ?>" placeholder="<?php echo _('Not provided') ?>" />
<?php if ($errorFullName) { ?>
<div class="c-5 mb-22"><?php echo $errorFullName ?></div>
<?php } ?>
<label for="location"><?php echo _('Location') ?></label>
<input type="text" name="location" id="location" value="<?php echo $location ?>" placeholder="<?php echo _('Not provided') ?>" />
<?php if ($errorLocation) { ?>
<div class="c-5 mb-22"><?php echo $errorLocation ?></div>
<?php } ?>
<label for="url"><?php echo _('Website') ?></label>
<input type="text" name="url" id="url" value="<?php echo $url ?>" placeholder="<?php echo _('Not provided') ?>" />
<?php if ($errorURL) { ?>
<div class="c-5 mb-22"><?php echo $errorURL ?></div>
<?php } ?>
<label for="bitMessage"><?php echo _('BitMessage') ?></label>
<input type="text" name="bitMessage" id="bitMessage" value="<?php echo $bitMessage ?>" placeholder="<?php echo _('Not provided') ?>" />
<?php if ($errorBitMessage) { ?>
<div class="c-5 mb-22"><?php echo $errorBitMessage ?></div>
<?php } ?>
<label for="tox"><?php echo _('TOX') ?></label>
<input type="text" name="tox" id="tox" value="<?php echo $tox ?>" placeholder="<?php echo _('Not provided') ?>" />
<?php if ($errorTOX) { ?>
<div class="c-5 mb-22"><?php echo $errorTOX ?></div>
<?php } ?>
<label for="bio"><?php echo _('Bio') ?></label>
<textarea name="bio" id="bio" placeholder="<?php echo _('Not provided') ?>"><?php echo $bio ?></textarea>
<?php if ($errorBio) { ?>
<div class="c-5 mb-22"><?php echo $errorBio ?></div>
<?php } ?>
<div class="actions">
<button type="submit"><?php echo _('Save') ?></button>
</div>
</form>
</div>
</div>
</div>

View File

@ -87,6 +87,9 @@ if (isset($_GET['_route_'])) {
case 'register': case 'register':
require(PROJECT_DIR . '/application/controller/register.php'); require(PROJECT_DIR . '/application/controller/register.php');
break; break;
case 'settings':
require(PROJECT_DIR . '/application/controller/settings/profile.php');
break;
// API calls // API calls
case 'api/image': case 'api/image':

View File

@ -6,12 +6,23 @@
transition: all .5s ease-in; */ transition: all .5s ease-in; */
} }
:focus {outline:none;}
::-moz-focus-inner {border:0;}
a, a,
a:visited, a:visited,
a:active { a:active {
color: #fff color: #fff
} }
input[type="text"],
textarea {
padding: 9px 16px;
width: 100%;
border-radius: 3px;
background: rgb(238, 238, 238);
}
.container { .container {
max-width: 1024px; max-width: 1024px;
margin: 16px auto; margin: 16px auto;

View File

@ -60,11 +60,11 @@
font-size: 13px; font-size: 13px;
} }
.moduleFollowing .item .info .username { .moduleFollowing .item .info .userName {
margin-bottom: 8px; margin-bottom: 8px;
} }
.moduleFollowing .item .info .username a { .moduleFollowing .item .info .userName a {
font-weight: bold; font-weight: bold;
} }
@ -86,10 +86,11 @@
.moduleFollowing .item .info .tox, .moduleFollowing .item .info .tox,
.moduleFollowing .item .info .bitMessage { .moduleFollowing .item .info .bitMessage {
display: inline-block; display: inline-block;
margin-right: 4px; margin: 2px 4px;
margin-top: 4px; font-size: 10px;
} }
.moduleFollowing .item .info .tox { .moduleFollowing .item .info .tox {
font-size: 10px font-size: 10px;
margin: 2px 4px;
} }

View File

@ -9,8 +9,10 @@
border-radius: 3px; border-radius: 3px;
cursor: pointer; cursor: pointer;
text-align: center; text-align: center;
padding: 8px 16px; padding: 0 16px;
margin: 0 2px 2px 2px; margin: 0 2px 2px 2px;
height: 36px;
line-height: 36px;
} }
.moduleMenu .item.active, .moduleMenu .item.active,

View File

@ -0,0 +1,13 @@
.moduleSettings .item {
display: block;
background: rgba(39, 46, 57, 0.28);
border-radius: 3px;
padding: 8px 16px;
margin: 0 2px 2px 2px;
}
.moduleSettings .item.active,
.moduleSettings .item:hover {
background: #272E39;
}

View File

@ -0,0 +1,57 @@
.settingsProfile form {
background: rgba(39, 46, 57, 0.28);
padding: 16px;
border-radius: 3px;
}
.settingsProfile form label {
color: #ccc;
display: block;
margin-bottom: 4px;
}
.settingsProfile form input {
background: transparent;
margin-bottom: 16px;
width: 360px;
font-size: 15px;
color: #fff
}
.settingsProfile form input:focus {
background: rgb(238, 238, 238);
color: #1c1d1e
}
.settingsProfile form textarea {
background: transparent;
margin-bottom: 8px;
min-height: 80px;
font-size: 14px;
color: #fff
}
.settingsProfile form textarea:focus {
background: rgb(238, 238, 238);
color: #1c1d1e
}
.settingsProfile form button {
float: right;
padding: 10px 16px;
border-radius: 3px;
cursor: pointer;
background-color: #337ab7;
color: #fff;
border: 0;
width: 100%;
}
.settingsProfile form button:hover {
background-color: #437baa;
}
.settingsProfile form .actions {
text-align: right;
overflow: hidden;
}

View File

@ -25,7 +25,7 @@ var ModuleFollowing = {
'class': 'info' 'class': 'info'
}).append( }).append(
$('<div/>', { $('<div/>', {
'class': 'username' 'class': 'userName'
}).append( }).append(
$('<a/>', { $('<a/>', {
'href': 'people/' + userName 'href': 'people/' + userName
@ -49,7 +49,7 @@ var ModuleFollowing = {
}) })
).append( ).append(
$('<div/>', { $('<div/>', {
'class': 'bitmessage' 'class': 'bitMessage'
}) })
) )
).append( ).append(
@ -79,7 +79,7 @@ var ModuleFollowing = {
if (response.success) { if (response.success) {
$(list).find('div[data-username="' + userName + '"] .username > a').html(response.profile.fullName ? response.profile.fullName : response.profile.userName); $(list).find('div[data-username="' + userName + '"] .userName > a').html(response.profile.fullName ? response.profile.fullName : response.profile.userName);
$(list).find('div[data-username="' + userName + '"] .location').html(response.profile.location); $(list).find('div[data-username="' + userName + '"] .location').html(response.profile.location);
$(list).find('div[data-username="' + userName + '"] .url').html(response.profile.url == '' ? '' : $('<a/>',{'href':response.profile.url,'class':'bi bi-link','target':'_blank','title':'Website'})); $(list).find('div[data-username="' + userName + '"] .url').html(response.profile.url == '' ? '' : $('<a/>',{'href':response.profile.url,'class':'bi bi-link','target':'_blank','title':'Website'}));
$(list).find('div[data-username="' + userName + '"] .bio').html(response.profile.bio); $(list).find('div[data-username="' + userName + '"] .bio').html(response.profile.bio);

View File

@ -0,0 +1,7 @@
var ModuleSettings = {
init: function(href) {
$('#moduleSettings a[href="' + href + '"]').addClass('active');
}
}

View File

@ -0,0 +1,7 @@
$(document).ready(function() {
// Init modules
ModuleMenu.init('settings');
ModuleSettings.init('settings');
});

View File

@ -276,6 +276,47 @@ class Twister {
return false; return false;
} }
public function putDHT(string $peerAlias,
string $command,
string $flag, // s(ingle)/m(ulti)
mixed $value,
string $sig_user,
int $seq) {
$this->_curl->prepare(
'/',
'POST',
30,
[
'jsonrpc' => '2.0',
'method' => 'dhtput',
'params' => [
$peerAlias,
$command,
$flag,
$value,
$sig_user,
$seq,
],
'id' => time() + rand()
]
);
if ($response = $this->_curl->execute()) {
if ($response['error']) {
$this->_error = _($response['error']['message']);
} else {
return $response['result']; // Array
}
}
return false;
}
public function createWalletUser(string $userName) { public function createWalletUser(string $userName) {
$this->_curl->prepare( $this->_curl->prepare(