mirror of
https://github.com/slynn1324/tinypin.git
synced 2026-01-23 02:25:08 +00:00
fix settings
This commit is contained in:
parent
deaa8ded34
commit
dcc063a4de
5 changed files with 69 additions and 22 deletions
|
|
@ -67,10 +67,10 @@ app.addComponent('navbar', (store) => { return new Reef("#navbar", {
|
|||
}
|
||||
|
||||
let settingsItem = "";
|
||||
if (data.user.admin == "y"){
|
||||
if (data.user.admin == 1){
|
||||
settingsItem = `
|
||||
<a class="navbar-item has-text-right" href="./settings">
|
||||
<span>settings</span>
|
||||
<span>tinypin settings</span>
|
||||
<img style="20px; height:20px;" src="data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzMwMHB4JyB3aWR0aD0nMzAwcHgnICBmaWxsPSIjMDAwMDAwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGRhdGEtbmFtZT0iTGF5ZXIgMSIgdmlld0JveD0iMCAwIDY0IDY0IiB4PSIwcHgiIHk9IjBweCI+PHRpdGxlPnNldHRpbmc8L3RpdGxlPjxwYXRoIGQ9Ik01OS42MSwyMS44M2wtNS04LjY2YTEsMSwwLDAsMC0xLjIzLS40M0w0Ni41MSwxNS41QTIyLjExLDIyLjExLDAsMCwwLDM5LDExLjE1TDM4LDMuODZBMSwxLDAsMCwwLDM3LDNIMjdhMSwxLDAsMCwwLTEsLjg2bC0xLDcuMjlhMjIuMTEsMjIuMTEsMCwwLDAtNy40OCw0LjM1bC02Ljg3LTIuNzZhMSwxLDAsMCwwLTEuMjMuNDNsLTUsOC42NmExLDEsMCwwLDAsLjI0LDEuMjlsNS44MSw0LjU2YTIxLjQzLDIxLjQzLDAsMCwwLDAsOC42NEw0LjYzLDQwLjg4YTEsMSwwLDAsMC0uMjQsMS4yOWw1LDguNjZhMSwxLDAsMCwwLDEuMjMuNDNsNi44Ny0yLjc2QTIyLjExLDIyLjExLDAsMCwwLDI1LDUyLjg1bDEsNy4yOUExLDEsMCwwLDAsMjcsNjFIMzdhMSwxLDAsMCwwLDE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WiI+PC9wYXRoPjwvc3ZnPg==" />
|
||||
</a>`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ module.exports = async (req, res, next) => {
|
|||
} else if ( req.method == "GET" && req.originalUrl == "/register" ){
|
||||
|
||||
let registerEnabled = dao.getProperty("registerEnabled");
|
||||
if ( registerEnabled != "y" ){
|
||||
if ( registerEnabled != 'y' ){
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ module.exports = async (req, res, next) => {
|
|||
} else if ( req.method == "POST" && req.originalUrl == "/register" ){
|
||||
|
||||
let registerEnabled = dao.getProperty("registerEnabled");
|
||||
if ( registerEnabled != "y" ){
|
||||
if ( registerEnabled != 'y' ){
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -365,17 +365,63 @@ async function init(path){
|
|||
|
||||
db.transaction( () => {
|
||||
|
||||
db.prepare('ALTER TABLE users ADD COLUMN admin').run();
|
||||
db.prepare('ALTER TABLE users ADD COLUMN uuid').run(); // need a uuid column to track real uniqueness, because we didn't use AUTOINCREMENT.
|
||||
db.prepare(`
|
||||
CREATE TABLE users_new (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
key TEXT NOT NULL,
|
||||
salt TEXT NOT NULL,
|
||||
createDate TEXT
|
||||
)
|
||||
`).run();
|
||||
|
||||
db.prepare(`
|
||||
CREATE TABLE boards_new (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
userId INTEGER NOT NULL,
|
||||
createDate TEXT,
|
||||
hidden INTEGER,
|
||||
|
||||
FOREIGN KEY (userId) REFERENCES users_new(id)
|
||||
)
|
||||
`).run();
|
||||
|
||||
db.prepare(`
|
||||
CREATE TABLE pins_new (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
boardId INTEGER NOT NULL,
|
||||
imageUrl TEXT,
|
||||
siteUrl TEXT,
|
||||
description TEXT,
|
||||
sortOrder INTEGER,
|
||||
originalHeight INTEGER,
|
||||
originalWidth INTEGER,
|
||||
thumbnailHeight INTEGER,
|
||||
thumbnailWidth INTEGER,
|
||||
userId INTEGER NOT NULL,
|
||||
createDate TEXT,
|
||||
|
||||
FOREIGN KEY (boardId) REFERENCES boards_new(id),
|
||||
FOREIGN KEY (userId) REFERENCES users_new(id)
|
||||
)
|
||||
`).run();
|
||||
|
||||
db.prepare("INSERT INTO users_new SELECT * FROM users").run();
|
||||
db.prepare("INSERT INTO boards_new SELECT * FROM boards").run();
|
||||
db.prepare("INSERT INTO pins_new SELECT * FROM pins").run();
|
||||
|
||||
db.prepare("UPDATE users SET admin = 1").run();
|
||||
db.prepare("ALTER TABLE users_new ADD COLUMN admin INTEGER").run();
|
||||
|
||||
let users = db.prepare("SELECT id FROM users").all();
|
||||
db.prepare("UPDATE users_new SET admin = 1").run();
|
||||
|
||||
for ( let i = 0; i < users.length; ++i ){
|
||||
let uuid = crypto.randomBytes(16).toString("hex"); // not a real uuid, but serves the same purpose
|
||||
db.prepare("UPDATE users SET uuid = @uuid WHERE id = @id").run({id: users[i].id, uuid: uuid});
|
||||
}
|
||||
db.prepare("DROP TABLE pins").run();
|
||||
db.prepare("DROP TABLE boards").run();
|
||||
db.prepare("DROP TABLE users").run();
|
||||
|
||||
db.prepare("ALTER TABLE pins_new RENAME TO pins").run();
|
||||
db.prepare("ALTER TABLE boards_new RENAME TO boards").run();
|
||||
db.prepare("ALTER TABLE users_new RENAME TO users").run();
|
||||
|
||||
db.prepare(`
|
||||
INSERT INTO properties (key,value) VALUES (@key, @value)
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ module.exports = async () => {
|
|||
app.get("/settings", (req, res) => {
|
||||
|
||||
let user = dao.getUser(req.user.id);
|
||||
if ( user.admin != "y" ){
|
||||
if ( user.admin != 1 ){
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
}
|
||||
|
|
@ -403,7 +403,7 @@ module.exports = async () => {
|
|||
app.post("/settings", async (req, res) => {
|
||||
|
||||
let user = dao.getUser(req.user.id);
|
||||
if ( user.admin != "y" ){
|
||||
if ( user.admin != 1 ){
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
}
|
||||
|
|
@ -426,10 +426,11 @@ module.exports = async () => {
|
|||
return;
|
||||
|
||||
} else if ( req.body.action == "updateSettings" ){
|
||||
let registerEnabled = 'y';
|
||||
let registerEnabled = "y";
|
||||
if ( req.body.registerEnabled == "n" ){
|
||||
registerEnabled = 'n';
|
||||
registerEnabled = "n";
|
||||
}
|
||||
console.log("set register enabled=" + registerEnabled);
|
||||
dao.setProperty('registerEnabled', registerEnabled);
|
||||
|
||||
res.redirect("./settings#settings-updated");
|
||||
|
|
@ -451,7 +452,7 @@ module.exports = async () => {
|
|||
let key = await tokenUtils.deriveKey(salt, password);
|
||||
|
||||
try{
|
||||
dao.createUser(username, 'n', key, salt);
|
||||
dao.createUser(username, 0, key, salt);
|
||||
} catch (err){
|
||||
console.log("error creating user " + username, err);
|
||||
res.redirect("./settings#create-user-error");
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
</a>
|
||||
|
||||
<span class="navbar-item">
|
||||
<span>Settings</span>
|
||||
<span>tinypin settings</span>
|
||||
</span>
|
||||
|
||||
<a role="button" class="navbar-burger is-active" aria-label="menu" aria-expanded="false" href="./">
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
<h1 style="border-bottom: 1px solid #eee;"><strong>Settings</strong></h1>
|
||||
<br />
|
||||
<form method="POST" action="./settings">
|
||||
<input type="hidden" name="action" value="updatePreferences">
|
||||
<input type="hidden" name="action" value="updateSettings">
|
||||
<div class="field is-horizontal">
|
||||
<div class="field-label is-normal">
|
||||
<label class="label has-text-weight-normal">Registration: </label>
|
||||
|
|
@ -81,7 +81,7 @@
|
|||
<select name="registerEnabled">
|
||||
<option value="y" <% if ( it.registerEnabled == "y" ){ %> selected <% } %> >Enabled</option>
|
||||
<option value="n" <% if ( it.registerEnabled != "y" ) { %> selected <% }%> >Disabled</option>
|
||||
</select>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -124,8 +124,8 @@
|
|||
<% if (it.userId != user.id) { %>
|
||||
<div class="select is-small">
|
||||
<select name="admin-<%= user.id %>">
|
||||
<option value="y" <% if (user.admin == "y" ){ %> selected <% } %> >y</option>
|
||||
<option value="n" <% if (user.admin != "y" ){ %> selected <% } %> >n</option>
|
||||
<option value="1" <% if (user.admin == 1 ){ %> selected <% } %> >yes</option>
|
||||
<option value="0" <% if (user.admin != 1 ){ %> selected <% } %> >no</option>
|
||||
</select>
|
||||
</div>
|
||||
<% } else { %>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue