Compare commits

..

No commits in common. "ecff52392630fd289cea47a6ea97747624807f41" and "8e5cb9dfcc4d6fc3054fc777dab5329cc2250494" have entirely different histories.

14 changed files with 38 additions and 221 deletions

View File

@ -38,11 +38,6 @@ Article.structure = {
gpgsign: { gpgsign: {
type: DataTypes.TEXT, type: DataTypes.TEXT,
allowNull: true allowNull: true
},
hidden: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
} }
}; };

View File

@ -66,21 +66,6 @@ class User extends Model {
session.secret = crypto.randomBytes(256).toString('base64'); session.secret = crypto.randomBytes(256).toString('base64');
return session; return session;
} }
/**
* Get a user object from express session
* @param {*} session
* @returns User
*/
static async bySession(session) {
if (session.user == undefined) return;
if (session.user.user_id == undefined) return;
const user = await User.findOne({where: {id: session.user.user_id}});
if (!user) {
return false;
}
return user;
}
} }
const structure = { const structure = {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 638 B

File diff suppressed because one or more lines are too long

View File

@ -1,20 +0,0 @@
(
function() {
'use strict';
$('span.flag_btn').css('visibility', 'visible');
const au_btn = $('#aussy_language span');
const body = $('body')
let isAustralian = false;
au_btn.on('click', () => {
au_btn.attr('title', isAustralian ? 'Australian' : 'English');
au_btn.css('background', isAustralian ? 'url(/content/au_flag.jpg)' : 'url(/content/uk_flag.jpg)')
isAustralian = !isAustralian;
body.css('transform', isAustralian ? 'rotate(180deg)' : 'none');
})
}
)()

View File

@ -39,11 +39,10 @@ a:visited {
.side_menu { .side_menu {
width: 200px; width: 200px;
border-right: 1px solid #c2c4c2; border-right: 1px solid #c2c4c2;
padding: 0; padding: 0
font-size: 9pt;
} }
.side_menu h1 { .side_menu h1 {
font-size: 1.75em; font-size: 1.5em;
padding-left: 3px; padding-left: 3px;
} }
.side_menu h1 a { .side_menu h1 a {
@ -55,13 +54,10 @@ a:visited {
.side_menu ul { .side_menu ul {
list-style: none; list-style: none;
padding: 0; padding: 0;
font-size: 10pt; font-size: 11pt;
padding-left: 4px; padding-left: 4px;
line-height: 125%; line-height: 125%;
} }
.side_menu p {
padding-left: 14px;
}
.main_contents { .main_contents {
padding: 16px 12px; padding: 16px 12px;
} }
@ -92,20 +88,3 @@ hr {
text-decoration:none; text-decoration:none;
text-shadow:0px 1px 0px #ffffff; text-shadow:0px 1px 0px #ffffff;
} }
span.flag_btn {
width: 30px;
height: 20px;
border: 1px solid #606060;
border-radius: 2px;
display: inline-block;
box-shadow:
inset 0 -2px 3px #a0a0a080,
inset 0 1px 1px #f1f4f280;
margin-left: 10px;
visibility: hidden;
}
span.au_flag {
background: url(/content/au_flag.jpg);
}

View File

@ -1,15 +1,8 @@
.control_panel {
border-collapse: separate;
border-spacing: 5px;
}
.cp_panel_panel { .cp_panel_panel {
border: 1px solid #c2c4c2; border: 1px solid #c2c4c2;
border-radius: 2px; padding: 4px;
padding: 4px 8px;
min-height: 300px; min-height: 300px;
font-size: 9pt; font-size: 9pt;
max-width: 386px;
box-shadow: 0 2px 1px #20202010;
} }
.cp_panel_panel h5 { .cp_panel_panel h5 {
font-size: 1.1em; font-size: 1.1em;
@ -21,24 +14,9 @@
color: blue; color: blue;
font-size: 100%; font-size: 100%;
} }
.cp_panel_panel p {
margin: 2px 0;
padding: 0;
}
.cp_gb_entry .cp_gb_entry_name {
text-align: left;
white-space: nowrap;
width: 1px;
}
.cp_gb_entry .cp_gb_entry_hide {
text-align: right;
white-space: nowrap;
width: 1px;
}
.cp_gb_entry_hidden { .cp_gb_entry_hidden {
filter: opacity(0.7) filter: opacity(0.7)
} }
input[type=submit] { input[type=submit] {
cursor: pointer; cursor: pointer;
} }

View File

@ -1,7 +1,6 @@
const handler = require('express-async-handler') const handler = require('express-async-handler')
const Helpers = require('../helpers'); const Helpers = require('../helpers');
const db = require('../models'); const db = require('../models');
const express = require('express');
async function login(req, res) { async function login(req, res) {
res.send(await Helpers.ViewLoader.load('admin/login.pug', { res.send(await Helpers.ViewLoader.load('admin/login.pug', {
@ -29,22 +28,13 @@ async function apiLogin(req, res) {
async function panel(req, res) { async function panel(req, res) {
const user = await db.User.bySession(req.session);
if (!user) {
res.status(401).send('Forbidden');
return;
}
const gb_records = await db.Guestbook.findAll({ const gb_records = await db.Guestbook.findAll({
order: [['id', 'DESC']] order: [['id', 'DESC']]
}); });
const articles = await db.Article.findAll({where: {hidden: true}});
res.send(await Helpers.ViewLoader.load('admin/panel.pug', { res.send(await Helpers.ViewLoader.load('admin/panel.pug', {
current_route: req.originalUrl, current_route: req.originalUrl,
gb_records, gb_records
access_level: user.accessLevel
})); }));
return; return;
} }
@ -52,11 +42,6 @@ async function panel(req, res) {
async function gb_api(req, res) { async function gb_api(req, res) {
let action = false; let action = false;
const id = req.body.id; const id = req.body.id;
const user = await db.User.bySession(req.session);
if (!user) {
res.status(401).send('Forbidden');
return;
}
if (req.body.hide) action = 'hide'; if (req.body.hide) action = 'hide';
@ -73,10 +58,6 @@ async function gb_api(req, res) {
} }
} }
async function article_new(req, res) {
res.send(await Helpers.ViewLoader.load('articles/new.pug'))
}
module.exports = (router) => { module.exports = (router) => {
// login // login
@ -84,12 +65,8 @@ module.exports = (router) => {
router.get('/admin/login', handler(login)); router.get('/admin/login', handler(login));
router.post('/admin/login', handler(apiLogin)); router.post('/admin/login', handler(apiLogin));
router.post('/gb_api', handler(gb_api));
// panel // panel
router.get('/admin/panel', handler(panel)); router.get('/admin/panel', handler(panel));
router.post('/admin/panel/gb_api', handler(gb_api));
// article
router.get('/admin/article/new', handler(article_new));
} }

View File

@ -19,13 +19,7 @@ async function handler(req, res) {
{ {
current_route: '/', current_route: '/',
gb_entries, gb_entries,
articles, articles
og: {
title: 'blek! Site',
type: 'website',
image: req.protocol + '://' + req.get('host') + '/content/transylveonia.jpg',
url: req.protocol + '://' + req.get('host') + req.originalUrl
}
} }
) )
); );

View File

@ -13,74 +13,34 @@ block content
| Warning: Your access level is unkown, so everything is displayed and some funtions may not work. | Warning: Your access level is unkown, so everything is displayed and some funtions may not work.
hr hr
- access_level = 4 - access_level = 4
table(class='control_panel') table
tr tr
td(class='cp_panel_panel') td(class='cp_panel_panel')
h5 Guestbook panel h5 Guestbook panel
hr hr
p p
if (access_level >= 3) a(href='/admin/panel/guestbook.editor') Edit data
a(href='/admin/panel/guestbook.editor') Edit data br
br a(href='/admin/panel/guestbook.csv') Download data (.CSV)
a(href='/admin/panel/guestbook.csv') Download data (.CSV) br
br a(href='/admin/panel/guestbook.csv') Download data (SQL)
a(href='/admin/panel/guestbook.csv') Download data (SQL)
if (access_level >= 4)
div(style='padding-left:4px')
form(action='/admin/panel/gb_api')
h5 Import from file
p
b WARNING:
| All the records will be removed and replaced with your values!
label(for='filetype') File type:
select(name='filetype')
option(value='csv') .CSV
option(value='sql') .TSV
br
input(type='file' name='file')
br
input(type='submit' name='import' value='Send')
hr hr
div(style='max-height:160px;overflow-y:scroll') table
table(width='100%') each record of gb_records
if (!gb_records || gb_records.length == 0) tr(class='' + (record.hidden ? 'cp_gb_entry_hidden' : ''))
p Nothing to show. form(action='/admin/panel/gb_api' method='POST')
each record of gb_records input(type='hidden' name='id' value=record.id)
tr(class='cp_gb_entry' + (record.hidden ? ' cp_gb_entry_hidden' : '')) td
form(action='/admin/panel/gb_api' method='POST') a(href='/guestbook#gb_entry_' + record.id)= record.id
input(type='hidden' name='id' value=record.id) | : #{record.name}
td(class='cp_gb_entry_name') td
a(href='/guestbook#gb_entry_' + record.id)= record.id if (record.text.length > 40)
| : | #{record.text.substr(0, 40)}...
b= record.name + ' says:' else
td | #{record.text}
if (record.text.length > 30) td
| #{record.text.substr(0, 340)}... if (!record.hidden)
else input(type='submit' name='hide' value='Hide')
| #{record.text} else
if (access_level >= 3) input(type='submit' name='hide' value='Unhide')
td(class='cp_gb_entry_hide')
if (!record.hidden)
input(type='submit' name='hide' value='Hide')
else
input(type='submit' name='hide' value='Unhide')
td(class='cp_panel_panel')
h5 Articles
hr
p
a(href='/admin/article/new') Create new article
if (access_level >= 4)
br
a(href='/admin/articles.csv') Download data (.CSV)
br
a(href='/admin/articles.sql') Download data (SQL)
div(style='padding-left:4px')
form(action='/admin/panel/article_api' method='POST')
h5 Import from file
p
b WARNING:
| All the records will be removed and replaced with your values!
hr
if (!articles)
p Nothing to show.

View File

@ -20,16 +20,16 @@ block content
tr tr
td Your name: td Your name:
td td
input(type='text' name='name' value='' + (name ? name : '') style='width:50%') input(type='text' name='name' value='' + name style='width:50%')
span(style='font-size:9pt;color:red;user-select:none' title='required') * span(style='font-size:9pt;color:red;user-select:none' title='required') *
tr tr
td Your email: td Your email:
td td
input(type='email' name='email' value='' + (email ? email : '')) input(type='email' name='email' value='' + email)
tr tr
td Hide your email? td Hide your email?
td td
input(type='checkbox' name='hidemail' checked=(hidemail ? true : 'off')) input(type='checkbox' name='hidemail' checked=hidemail)
// span(style='font-size:9pt;color:red;user-select:none' title='required') * // span(style='font-size:9pt;color:red;user-select:none' title='required') *
p(style='margin:6px 0') p(style='margin:6px 0')
| Your message (512 chars max): | Your message (512 chars max):

View File

@ -13,24 +13,12 @@ block root
} }
doctype html doctype html
html(style='overflow-y:auto' lang='en_US') html(style='overflow-y:auto')
head head
title blek! Site #{title ? "- " + title : ""} title blek! Site #{title ? "- " + title : ""}
link(rel='stylesheet' href='/static/main.css') link(rel='stylesheet' href='/static/main.css')
//- basic SEO tags
if (typeof description == 'string')
meta(name='description' content=description)
//- Open Graph tags
if (typeof og == 'object')
each content, tag in og
meta(property='og:' + tag content=content)
//- UX
meta(name='viewport' content='width=device-width, initial-scale=1')
block head block head
body(style='overflow-y:auto') body(style='overflow-y:auto')
table(width='100%' height='100%' class='body_table') table(width='100%' height='100%' class='body_table')
@ -49,25 +37,8 @@ html(style='overflow-y:auto' lang='en_US')
| > #{name} | > #{name}
else else
a(href=route) #{name} a(href=route) #{name}
hr
p This site is also available in:
p
a(href='#' id='aussy_language')
span(class='flag_btn au_flag' title='Australian')
td(class='main_contents') td(class='main_contents')
block content block content
block foot block foot
//- js dependencies
script(src='/static/js/jquery.js')
//- global js
script(src='/static/js/main.js')
script(type='text/javascript').
setTimeout(function() {
alert('Congratulations! You have spent 10 years on this page. Go fuck yourself.\n\nUwU');
}, 1000 * 60 * 60 * 24 * 365 * 10);
//- page js
block scripts block scripts