Реализовал добавление новых стихов
This commit is contained in:
parent
55cd21180a
commit
39877bed54
3 changed files with 33 additions and 6 deletions
20
src/db.js
20
src/db.js
|
@ -21,12 +21,20 @@ function getVerseCount() {
|
|||
return Object.keys(Verse).length
|
||||
}
|
||||
|
||||
function peopleByLogin(login) {
|
||||
function peopleNumberByLogin(login) {
|
||||
for (let p in People)
|
||||
if (People[p].LOGIN == login)
|
||||
return People[p]
|
||||
return p
|
||||
return false
|
||||
}
|
||||
function peopleByLogin(login) {
|
||||
const number = peopleNumberByLogin(login)
|
||||
return number ? People[number] : false
|
||||
}
|
||||
|
||||
function checkPassword(login, password) {
|
||||
return peopleByLogin(login).HASH == createHash('sha256').update(password).digest('hex')
|
||||
}
|
||||
|
||||
function Init() {
|
||||
const people = fs.readdirSync(DB + '/people')
|
||||
|
@ -60,13 +68,13 @@ function addPeople(name, subname, login, password) {
|
|||
})
|
||||
}
|
||||
|
||||
function addVerse(title, author, genre, text) {
|
||||
function addVerse(title, login, genre, text) {
|
||||
const v = {
|
||||
TITLE: title,
|
||||
AUTHOR: author,
|
||||
AUTHOR: peopleNumberByLogin(login),
|
||||
GENRE: genre
|
||||
}
|
||||
const index = Number(Object.keys(Verse)[getVerseCount() - 1]) + 1
|
||||
const index = getVerseCount() == 0 ? 1 : Number(Object.keys(Verse)[getVerseCount() - 1]) + 1
|
||||
|
||||
Verse[index] = v
|
||||
|
||||
|
@ -84,7 +92,9 @@ export default {
|
|||
getVerse,
|
||||
getPeopleCount,
|
||||
getVerseCount,
|
||||
peopleNumberByLogin,
|
||||
peopleByLogin,
|
||||
checkPassword,
|
||||
Init,
|
||||
addPeople,
|
||||
addVerse
|
||||
|
|
|
@ -99,6 +99,17 @@ const server = createServer(async (req, res) => {
|
|||
res.writeHead(301, {location: '/login'})
|
||||
res.end()
|
||||
break
|
||||
case 'addverse':
|
||||
if (db.checkPassword(body.login, body.password)) {
|
||||
db.addVerse(body.title, body.login, body.genre, body.text)
|
||||
res.writeHead(301, {location: '/'})
|
||||
res.end()
|
||||
}
|
||||
else {
|
||||
res.statusCode = 403
|
||||
res.sendText('Нет прав! Перезайдите')
|
||||
}
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -115,6 +126,12 @@ const server = createServer(async (req, res) => {
|
|||
else
|
||||
notFound()
|
||||
break
|
||||
case 'add':
|
||||
if (tokens.length == 1)
|
||||
sendFile(path.join(Config.WWW, 'add.html'))
|
||||
else
|
||||
notFound()
|
||||
break
|
||||
default:
|
||||
if (db.peopleByLogin(command)) {
|
||||
sendText('Есть такой пользователь!')
|
||||
|
|
2
www
2
www
|
@ -1 +1 @@
|
|||
Subproject commit c8910f218e876847badc832783e3af78f68aa234
|
||||
Subproject commit 12275291636c4659b3a0f3108024f4523931635f
|
Loading…
Add table
Add a link
Reference in a new issue