Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
necitboss committed Nov 11, 2024
1 parent 4c6dec9 commit 3b9a5f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion main/_front/src/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ document.addEventListener("DOMContentLoaded", function() {
})
.then(res => res.json())
.then(data => {
if (data.message === true) {
if (data.message === "Вы авторизованы") {
title.textContent = "Вы уже вошли в панель администратора"
login.parentElement.classList.add('hide');
password.parentElement.classList.add('hide');
Expand Down
14 changes: 11 additions & 3 deletions main/controllers/AdminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const register = async (req, res) => {
passwordHash: hash
})
const admin = await doc.save();
console.log("here1")
const token = jwt.sign({
_id: admin._id,
},
Expand All @@ -23,10 +22,8 @@ export const register = async (req, res) => {
expiresIn: '30d',
}
);
console.log("here2")
const {passwordHash, ...AdminData} = admin._doc;

console.log("here3")
res.json({
...AdminData,
token
Expand All @@ -41,6 +38,17 @@ export const register = async (req, res) => {
export const login = async (req, res) => {
try {
const msg = "Неверный логин или пароль";
if (!AdminModel.find()[0]) {
const password = "12345";
const salt = await bcrypt.genSalt(10);
const hash = await bcrypt.hash(password, salt);

const doc = new AdminModel({
login: "admin",
passwordHash: hash
})
await doc.save();
}
const admin = await AdminModel.findOne({login: req.body.login});
if (!admin) {
return res.status(404).json({
Expand Down
2 changes: 1 addition & 1 deletion main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ app.get('/components', getAll)
app.get('/components/:id', getOne);
app.get('/auth/authorized', checkAuth, (req, res) => {
res.json({
message: true
message: "Вы авторизованы"
})
});

Expand Down

0 comments on commit 3b9a5f1

Please sign in to comment.