Make new accounts accepted 1 by 1 instead of fetching all

This commit is contained in:
Bofh 2022-11-28 15:45:55 +01:00
parent 7c4fe4b62a
commit 3646579d15
4 changed files with 36 additions and 19 deletions

View File

@ -4,9 +4,17 @@
$pg = new PgDatabase();
if ($pg->is_ok()) {
$result = $pg->fetch_all('SELECT a.id, a.username, u.sign_up_ip, u.email, ui.text FROM users AS u INNER JOIN user_invite_requests AS ui ON ui.user_id = u.id INNER JOIN accounts AS a ON a.id = u.account_id WHERE NOT confirmed_at IS NULL AND approved = false ORDER BY ui.id ASC');
$result = $pg->query('SELECT COUNT(1) FROM users AS u INNER JOIN user_invite_requests AS ui ON ui.user_id = u.id INNER JOIN accounts AS a ON a.id = u.account_id WHERE NOT confirmed_at IS NULL AND approved = false');
$count = (pg_fetch_object($result))->count;
$result = $pg->query('SELECT a.id, a.username, u.sign_up_ip, u.email, ui.text FROM users AS u INNER JOIN user_invite_requests AS ui ON ui.user_id = u.id INNER JOIN accounts AS a ON a.id = u.account_id WHERE NOT confirmed_at IS NULL AND approved = false ORDER BY ui.id ASC LIMIT 1');
$account = pg_fetch_object($result);
if ($account === false)
$account = null;
$pg->close();
apiresult($result);
apiresult([
'count' => intval($count),
'account' => $account,
]);
}
apiresult(['error' => 'Server has failed connecting to database'], 503);

View File

@ -1,3 +1,8 @@
<?php
$clr = [
'background' => '#e3e3e3'
];
?>
<style>
body {
padding: 0;
@ -81,6 +86,11 @@ button, .btn {
border: 1px solid black;
}
h1.normal,h2.normal,h3.normal,
h4.normal,h5.normal,h6.normal {
font-weight: normal;
}
textarea {
max-width: -moz-available;
}
@ -93,7 +103,7 @@ a {
/* specific styles */
#window-home {
background: #d7d7d7;
background: <?php echo $clr['background'] ?>;
}
#window-home #instances .item {
padding: .5em;
@ -147,7 +157,7 @@ a {
#window-instance #content {
display: flex;
width: 100vw;
background: #d7d7d7;
background: <?php echo $clr['background'] ?>;
height: 100vh;
}
#window-instance #content #container {
@ -174,7 +184,7 @@ a {
}
#window-instance_config {
background: #d7d7d7;
background: <?php echo $clr['background'] ?>;
}
#window-instance_config #title {
margin-top: 0;

View File

@ -1,5 +1,6 @@
<div id="new-accounts"></div>
<div id="new-accounts-item" data-id="user-{id}">
<h3 class="normal">Accounts pending: <b>{count}</b></h3>
<div class="card">
<h4>@{username}</h4>
<div style="color:#686868">

View File

@ -30,9 +30,7 @@ window.view.instance = {
const hargs = get_hash_arguments();
http.get(`api/v1/http/${hargs.software}/accounts/${action}/?instance=${hargs.instance}&id=${_id}`,
{}, function(js) {
E.removeAll(`#user-${_id}`);
// TODO: do a animation to remove stuff
console.log(js);
window.view.instance.load_content('new-accounts');
});
},
},
@ -45,17 +43,17 @@ window.view.instance = {
http.get(`api/v1/database/${hargs.software}/get-pending-users/?instance=${hargs.instance}`,
{}, function(js) {
E.template('new-accounts', function(TPL) {
var html = '';
for (var i = 0; i < js.length; i++) {
var tpl = TPL;
tpl = tpl.replaceAll('{id}', js[i].id);
tpl = tpl.replaceAll('{text}', html2text(js[i].text));
tpl = tpl.replaceAll('{email}', html2text(js[i].email));
tpl = tpl.replaceAll('{username}', html2text(js[i].username));
tpl = tpl.replaceAll('{ip_address}', html2text(js[i].sign_up_ip));
html += tpl;
}
return html;
if ((js.count === undefined || js.account === null)
|| js.count === 0)
return 'There is not any pending accounts';
var tpl = TPL;
tpl = tpl.replaceAll('{count}', js.count);
tpl = tpl.replaceAll('{id}', js.account.id);
tpl = tpl.replaceAll('{text}', html2text(js.account.text));
tpl = tpl.replaceAll('{email}', html2text(js.account.email));
tpl = tpl.replaceAll('{username}', html2text(js.account.username));
tpl = tpl.replaceAll('{ip_address}', html2text(js.account.sign_up_ip));
return tpl;
});
console.log(js);
});