Добавил регистрацию и вход

This commit is contained in:
Денис Буторин 2025-06-29 20:38:46 +03:00
parent a4715325cc
commit 55cd21180a
Signed by: dekabu
GPG key ID: 867F0C8041D69B4C
2 changed files with 20 additions and 23 deletions

View file

@ -70,36 +70,33 @@ const server = createServer(async (req, res) => {
sendText('API сайта kompoet.ru')
break
}
else if (req.method == 'GET')
switch (tokens[1]) {
case 'checklogin':
if (db.peopleByLogin(tokens[2]))
sendText('Логин занят')
else {
res.statusCode = 404
sendText('Логин свободен')
}
break
}
else {
let body = ''
req.on('data', chunck => {
body += chunck.toString()
req.on('data', chunk => {
body += chunk.toString()
})
req.on('end', () => {
body = querystring.parse(body)
switch (tokens[1]) {
case 'checklogin':
if (db.peopleByLogin(tokens[2]))
sendText('Логин занят')
else {
res.statusCode = 404
sendText('Логин свободен')
}
break
case 'checkpassword':
if (db.peopleByLogin(body.login).HASH == createHash('sha256').update(body.password).digest('hex'))
sendText('Пароль верный')
else {
res.statusCode = 403
sendText('Пароль неверный')
}
break
case 'signup':
db.addPeople(body.name, body.subname, body.login, body.password)
res.writeHead(301, {'location': '/'})
res.end()
break
case 'login':
const p = db.peopleByLogin(body.login)
if (!p)
res.writeHead(301, {'location': '/login?unknown'})
else if (createHash('sha256').update(body.password).digest('hex') != p.HASH)
res.writeHead(301, {'location': '/login?password'})
res.writeHead(301, {location: '/login'})
res.end()
break
}

2
www

@ -1 +1 @@
Subproject commit dde28033ce15c13f85a1613ff3fbaa045a0840df
Subproject commit c8910f218e876847badc832783e3af78f68aa234