From 19a55f57c0eb065acd96b6fdb24e188322764012 Mon Sep 17 00:00:00 2001 From: Rushan Sitdikov Date: Sun, 2 Jun 2024 20:15:01 +0300 Subject: [PATCH] school-stage stubs --- server/routers/school-stage/index.js | 49 ++++++++++++++--- .../school-stage/json/account/account.json | 52 ++++++++++--------- 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/server/routers/school-stage/index.js b/server/routers/school-stage/index.js index 68fa2c3..ae5b309 100644 --- a/server/routers/school-stage/index.js +++ b/server/routers/school-stage/index.js @@ -1,14 +1,49 @@ -const router = require('express').Router(); +/*const router = require('express').Router(); + +module.exports = router; router.get('/teachers', (request, response) => { - response.send(require('./json/teachers/success.json')) + response.send(require('../json/teachers/success.json')) }) router.get('/account', (request, response) => { - response.send(require('./json/account/account.json')) -}) -router.post('/login', (request, response) => { - response.send(require('./json/login/success.json')) + response.send(require('../json/account/account.json')) }) -module.exports = router; \ No newline at end of file +router.post('/login', (request, response) => { + response.send(require('../json/login/success.json')) +})*/ +const router = require('express').Router(); + +router.get('/teachers', (request, response) => { + response.send(require('../json/teachers/success.json')) + }) + +router.get('/account', (request, response) => { + response.send(require('../json/account/account.json')) +}) + +router.post('/login', (request, response) => { + const login = request.body.login; + const password = request.body.password; + + try { + const users = require('../json/account/account.json'); + const user = users.data.find(user => user.login === login && user.password === password); + + if (!user) { + return response.status(401).send('Неверные данные'); + } + + const responseObject = { + login: user.login, + } + return response.json(responseObject); + } catch (error) { + console.error('Error reading file:', error); + response.status(400).send('Internal server error'); + } +}) + + +module.exports = router; diff --git a/server/routers/school-stage/json/account/account.json b/server/routers/school-stage/json/account/account.json index e6de321..1159dd3 100644 --- a/server/routers/school-stage/json/account/account.json +++ b/server/routers/school-stage/json/account/account.json @@ -1,26 +1,28 @@ { - "data": [ - { - "login": "user1", - "photo": "boy", - "surname": "Иванов", - "name": "Иван", - "class": "2", - "group": "1", - "number": "+7 927 030 13 00", - "teacher": "Иванова Валерия Константиновна", - "lessons": ["02.05", "07.05", "14.05", "17.05", "21.05", "24.05", "28.05"] - }, - { - "login": "user2", - "photo": "boy", - "surname": "Александров", - "name": "Александр", - "class": "3", - "group": "2", - "number": "+7 927 030 13 00", - "teacher": "Иванова Валерия Константиновна", - "lessons": ["02.05", "07.05", "14.05", "17.05", "21.05", "24.05", "28.05"] - } - ] - } \ No newline at end of file + "data": [ + { + "login": "user1", + "password":"1234", + "photo": "boy", + "surname": "Иванов", + "name": "Иван", + "class": "2", + "group": "1", + "number": "+7 927 030 13 00", + "teacher": "Иванова Валерия Константиновна", + "lessons": ["02.05", "07.05", "14.05", "17.05", "21.05", "24.05", "28.05"] + }, + { + "login": "user2", + "password":"123", + "photo": "boy", + "surname": "Иванов", + "name": "Иван", + "class": "2", + "group": "1", + "number": "+7 927 030 13 00", + "teacher": "Иванова Валерия Константиновна", + "lessons": ["02.05", "07.05", "14.05", "17.05", "21.05", "24.05", "28.05"] + } + ] +} \ No newline at end of file