comments and captcha stuff

This commit is contained in:
biglyderv 2024-11-25 14:12:44 -05:00
parent e2ef83ec0c
commit 42aaebbd69
8 changed files with 25 additions and 28 deletions

View file

@ -9,7 +9,7 @@ let main = new Route([auth], async function (req, res, input) {
let {id} = req.query; let {id} = req.query;
let { username } = input; let { username } = input;
let comments = await db.all('SELECT * FROM comment WHERE targetType = ? AND targetId = ?', [ let comments = await db.all('SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC', [
route, route,
id id
]); ]);

View file

@ -2,16 +2,11 @@ import Route from "../route.js";
import initDb from "../db.js"; import initDb from "../db.js";
import { randomUUID } from 'node:crypto'; import { randomUUID } from 'node:crypto';
import auth from "../form/auth.js"; import auth from "../form/auth.js";
import captcha from "./captcha.js";
let db = await initDb(); let db = await initDb();
// TODO: rewrite // TODO: rewrite
let main = new Route([auth,captcha], async function (req, res, input) { let main = new Route([auth], async function (req, res, input) {
let { captchaMatch} = input;
if (!captchaMatch) return { 'success': false, 'message': 'Captcha is incorrect' };
let { username } = input; let { username } = input;
let id = randomUUID(); let id = randomUUID();
@ -28,7 +23,7 @@ let main = new Route([auth,captcha], async function (req, res, input) {
id id
]); ]);
res.send({ redir: `?` }); res.send({ 'message': 'Comment sent', redirect: `/client/${targetType}?id=${targetId}` });
}); });
export default main; export default main;

View file

@ -1,6 +1,5 @@
import Route from "../route.js"; import Route from "../route.js";
import initDb from "../db.js"; import initDb from "../db.js";
import { randomUUID } from 'node:crypto';
import auth from "../form/auth.js"; import auth from "../form/auth.js";
let db = await initDb(); let db = await initDb();

View file

@ -170,7 +170,8 @@ body {
.progressbar, .progressbar,
.progressbar-div, .progressbar-div,
.avatar-img { .avatar-img,
.captcha {
border-radius: var(--border-radius) border-radius: var(--border-radius)
} }

View file

@ -1,6 +1,7 @@
<%- include('form_bare.ejs', { data: [ { label: "" , type: "text" , name: "targetId" , hidden: id }, { label: "" , <%- include('form_bare.ejs', { data: [ { label: "" , type: "text" , name: "targetId" , hidden: id }, { label: "" ,
type: "text" , name: "targetType" , hidden: route }, { label: "Your thoughts..." , type: "textarea" , type: "text" , name: "targetType" , hidden: route }, { label: "Your thoughts..." , type: "textarea" ,
name: "content" , hidden: route }, ], 'route' : '/api/form/comment' , 'title' : 'Comments' , }) -%> name: "content" , hidden: route }, ], 'route' : '/api/form/comment' , 'title' : 'Comments' , noCaptcha: true })
-%>
<div class="content"> <div class="content">
<% for (let comment of comments) { %> <% for (let comment of comments) { %>

View file

@ -1,3 +1,3 @@
<%- include('header.ejs') -%> <%- include('header.ejs') -%>
<%- include('form_bare.ejs') -%> <%- include('form_bare.ejs', {noCaptcha: false}) -%>
<%- include('footer.ejs') -%> <%- include('footer.ejs') -%>

View file

@ -3,20 +3,22 @@
<%= title %> <%= title %>
</h1> </h1>
<div class='form-message'></div> <div class='form-message'></div>
<span class='form-key'> <% if (!noCaptcha) { %>
<img src='/client/captcha'>
</span>
<input class='form-input' type='text' name='challenger' value='Type the captcha'>
<% for (let elem of data) { %>
<span class='form-key'> <span class='form-key'>
<%= elem.label %> <img class='captcha' src='/client/captcha'>
</span> </span>
<% if (elem.type=='textarea' ) { %> <input class='form-input' type='text' name='challenger' value='Type the captcha'>
<textarea class='form-input' name='<%= elem.name %>'></textarea> <% } %>
<% } else { %> <% for (let elem of data) { %>
<input class='form-input' type='<%= elem.type %>' name='<%= elem.name %>' value='<%= elem.hidden %>' <span class='form-key'>
<%=elem.hidden ? 'hidden ' : '' %>> <%= elem.label %>
<% } %> </span>
<% } %> <% if (elem.type=='textarea' ) { %>
<input class='form-button' type='Submit' name='Submit'> <textarea class='form-input' name='<%= elem.name %>'></textarea>
<% } else { %>
<input class='form-input' type='<%= elem.type %>' name='<%= elem.name %>'
value='<%= elem.hidden %>' <%=elem.hidden ? 'hidden ' : '' %>>
<% } %>
<% } %>
<input class='form-button' type='Submit' name='Submit'>
</form> </form>

View file

@ -2,8 +2,7 @@
<div class='banner'><img class='banner-background' src='/static/img/bg.svg'> <div class='banner'><img class='banner-background' src='/static/img/bg.svg'>
<div class='banner-content'> <div class='banner-content'>
<h1>BiglyChat</h1> <h1>BiglyChat</h1>
<p>BiglyChat is a niche community for broadcasting videos to your fanbase, with integrated games and active <p>BiglyChat is a niche community for broadcasting videos to your fanbase.</p>
developers.</p>
<h2>Community</h2> <h2>Community</h2>
<%if (username=='!nobody' ) { %> <%if (username=='!nobody' ) { %>
<a class='form-button' href="/client/register">Join the Community</a> <a class='form-button' href="/client/register">Join the Community</a>