Skip to content

Commit 7353007

Browse files
committed
Тест доделан (почти)
1 parent 397c7fb commit 7353007

File tree

8 files changed

+42
-22
lines changed

8 files changed

+42
-22
lines changed

backend/server.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const pool = require('./dbconfig');
66
const Cookies = require("js-cookie");
77
//создание сервера
88
const app = express();
9-
const port = 5007;
9+
const port = 5009;
1010

1111
//подключение к приложени.
1212
app.use(cookieParser());
@@ -31,24 +31,28 @@ app.post('/api/login', async (req, res) => {
3131
console.log('Login successful:', user);
3232

3333
const myUserResult = await pool.query(
34-
'SELECT user_id, login, fio FROM USERS.USERS WHERE login = $1 AND password = $2',
34+
'SELECT * FROM USERS.USERS U JOIN USERS.ROLES R ON U.role_id = R.role_id WHERE login = $1 AND password = $2',
3535
[login, password]
3636
);
3737
const myUser = myUserResult.rows[0];
3838
// Очистка всех куков
3939
res.clearCookie('user_id', { path: '/' });
4040
res.clearCookie('login', { path: '/' });
4141
res.clearCookie('fio', { path: '/' });
42+
res.clearCookie('role_id', { path: '/' });
4243

4344
// Установить новые куки, доступные на стороне клиента
4445
res.cookie('user_id', myUser.user_id, { path: '/' });
4546
res.cookie('login', myUser.login, { path: '/' });
4647
res.cookie('fio', myUser.fio, { path: '/' });
48+
res.cookie('role_id', myUser.role_id, { path: '/' });
49+
4750
// Вывод установленных cookies в консоль
4851
console.log('Cookies set:');
4952
console.log('user_id:', myUser.user_id);
5053
console.log('login:', myUser.login);
5154
console.log('fio:', myUser.fio);
55+
console.log('role_id:', myUser.role_id);
5256

5357
res.status(200).json({ success: true, user });
5458
//res.status(200).json({ message: 'Login successful', user });

craco.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
devServer: {
33
proxy: {
44
'/api': {
5-
target: 'http://localhost:5007',
5+
target: 'http://localhost:5009',
66
changeOrigin: true,
77
},
88
},
59.2 MB
Binary file not shown.
103 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"eject": "craco eject",
2626
"deploy" : "npm run build&&gh-pages -d build"
2727
},
28-
"proxy": "http://localhost:5007",
28+
"proxy": "http://localhost:5009",
2929
"engines": {
3030
"node": "18.x"
3131
},

src/components/layout/themeOutput/tasksPage/testLayout/testContainer/test-container.jsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,19 @@ const TestComponent = ({ questions_ar, onTestResult, onEndTest, rootClassName })
8383
{questions_ar.map((question, index) => (
8484
<div key={index} className="test-container-question">
8585
<div className="test-container-text">{`Вопрос ${index + 1}`}</div>
86+
{resultData && (
87+
<div className={`answer-explanation ${resultData.correctAnswers[question.task_id][0] === userAnswers[index].answer
88+
? 'green-text'
89+
: 'red-text'}`}>
90+
{resultData.correctAnswers[question.task_id][0] === userAnswers[index].answer
91+
? 'Ответ правильный'
92+
: 'Ответ неверный'}
93+
</div>
94+
)}
8695
<span className="test-container-text3">{question.task_text}</span>
8796
<div className="test-container-answers">
8897
{question.answers.map((answer, idx) => (
89-
<div key={idx} className={`test-container-answer ${getAnswerClass(index, idx,question.task_id, answer)}`}>
98+
<div key={idx} className={`test-container-answer`}>
9099
<input
91100
className="custom-radio"
92101
type="radio"
@@ -95,17 +104,12 @@ const TestComponent = ({ questions_ar, onTestResult, onEndTest, rootClassName })
95104
value={idx}
96105
disabled={!!resultData} // Блокируем изменение ответов после проверки
97106
/>
98-
<label htmlFor={`q${index}a${idx}`}>{answer}</label>
107+
<label className={`${getAnswerClass(index, idx,question.task_id, answer)}`} htmlFor={`q${index}a${idx}`}>{answer}</label>
99108
</div>
100109
))}
110+
101111
</div>
102-
{resultData && (
103-
<div className="answer-explanation">
104-
{resultData.correctAnswers[question.task_id][0] === userAnswers[index].answer
105-
? 'Ответ правильный'
106-
: 'Ответ неверный'}
107-
</div>
108-
)}
112+
109113
</div>
110114
))}
111115

src/views/profile/profile.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const Profile = (props) => {
3232
} else {
3333
console.error('Failed to fetch progress:', data.error);
3434
}
35+
36+
3537
} catch (error) {
3638
console.error('Error fetching progress:', error);
3739
}
@@ -65,8 +67,13 @@ const Profile = (props) => {
6567
onClick={handleLogout}
6668
/>
6769

68-
{parseInt(Cookies.get('user_id'), 10)===1 ? <AdminPanel/> : <Contact/>}
69-
70+
{parseInt(Cookies.get('role_id'), 10) === 3 ? (
71+
<AdminPanel />
72+
) : parseInt(Cookies.get('role_id'), 10) === 1 ? (
73+
<AdminPanel />
74+
) : (
75+
<Contact />
76+
)}
7077
<Footer rootClassName="footer-root-class-name1"></Footer>
7178
</div>
7279
)

src/views/tasks/tasks.css

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
.correct-answer {
2-
background-color: #d4edda;
3-
color: #155724;
2+
/*background-color: #d4edda;*/
3+
color: #13b335;
44
}
55

66
.incorrect-answer {
7-
background-color: #f8d7da;
8-
color: #721c24;
7+
/*background-color: #f8d7da;*/
8+
color: #cc0d1e;
99
}
10-
10+
/*.green-text{*/
11+
/* color: #13b335;*/
12+
/*}*/
13+
/*.red-text{*/
14+
/* color: #cc0d1e;*/
15+
/*}*/
1116
.answer-explanation {
12-
margin-top: 10px;
17+
margin: 15px 0px ;
1318
font-style: italic;
14-
color: #333;
19+
color: var(--dl-color-secondary-400);
1520
}
1621

1722
.Correct-format{

0 commit comments

Comments
 (0)