Skip to content

Commit

Permalink
Revert "refactor: diminui a quantidade de dados sensíveis indo para o…
Browse files Browse the repository at this point in the history
… client …"
  • Loading branch information
ana-pfeilsticker authored Aug 14, 2024
1 parent 03a8395 commit 65b647f
Show file tree
Hide file tree
Showing 6 changed files with 710 additions and 788 deletions.
248 changes: 86 additions & 162 deletions node-app/controllers/UserMET.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,24 @@
import Sequelize from "sequelize";
export const getDados = (app, sequelize) => {
app.get("/usuario", async (req, res) => {
try {
const [results] = await sequelize.query(
"SELECT email, matricula FROM usuario"
);
res.json(results);
} catch (error) {
console.error(error);
res.status(500).send("Houve um erro ao buscar os dados");
}
});
};

export const autenticaUsuario = (app, sequelize) => {
app.post("/autenticar", async (req, res) => {
const { email, senha } = req.body;

try {
const [results] = await sequelize.query(
"SELECT matricula, senha FROM usuario WHERE email = :email",
{
replacements: { email },
type: Sequelize.QueryTypes.SELECT,
}
);
console.log(results);

// Se não encontrar o usuário, retorna erro
if (results.length === 0) {
return res
.status(401)
.json({ success: false, message: "Usuário não encontrado" });
}

const usuario = results;

// Verifica se a senha está correta (comparando diretamente)
if (senha !== usuario.senha) {
return res
.status(401)
.json({ success: false, message: "Senha incorreta" });
}

// Se a autenticação for bem-sucedida, retornar um sucesso
return res
.status(200)
.json({ success: true, matricula: usuario.matricula });
} catch (error) {
console.error("Erro ao autenticar:", error);
res.status(500).json({ success: false, message: "Erro ao autenticar" });
}
});
app.get("/usuario", async (req, res) => {
try {
const [results] = await sequelize.query(
"SELECT email, senha, matricula, cpf FROM usuario"
);
res.json(results);
} catch (error) {
console.error(error);
res.status(500).send("Houve um erro ao buscar os dados");
}
});
};

export const getDadosSessionStorage = (app, sequelize) => {
app.get("/usuario_session_storage/:matricula", async (req, res) => {
const { matricula } = req.params;
try {
const [results] = await sequelize.query(
`
app.get("/usuario_session_storage/:matricula", async (req, res) => {
const { matricula } = req.params;
try {
const [results] = await sequelize.query(
`
SELECT
u.matricula,
u.foto_url,
Expand Down Expand Up @@ -119,88 +78,53 @@ export const getDadosSessionStorage = (app, sequelize) => {
FROM usuario u
WHERE u.matricula = :matricula
`,
{ replacements: { matricula }, type: sequelize.QueryTypes.SELECT }
);
res.json(results);
} catch (error) {
console.error(error);
res.status(500).send("Houve um erro ao buscar os dados");
}
});
{ replacements: { matricula }, type: sequelize.QueryTypes.SELECT }
);
res.json(results);
} catch (error) {
console.error(error);
res.status(500).send("Houve um erro ao buscar os dados");
}
});
};

export const postDados = (app, sequelize) => {
app.post("/usuario", async (req, res) => {
const { matricula, cpf, nome, sobrenome, email, senha, curso } = req.body;

try {
// Verifica se o e-mail, matrícula ou CPF já estão cadastrados
const usuariosExistentes = await sequelize.query(
"SELECT email, matricula, cpf FROM usuario WHERE email = :email OR matricula = :matricula OR cpf = :cpf",
{
replacements: { email, matricula, cpf },
type: Sequelize.QueryTypes.SELECT,
}
);

if (usuariosExistentes) {
// Verificar qual campo já está cadastrado e retornar a mensagem correspondente
if (usuariosExistentes.some((user) => user.email === email)) {
return res
.status(400)
.json({ success: false, message: "O e-mail já está cadastrado." });
}

if (
usuariosExistentes.some(
(user) => user.matricula.toString() === matricula.toString()
)
) {
return res.status(400).json({
success: false,
message: "A matrícula já está cadastrada.",
});
}

if (usuariosExistentes.some((user) => user.cpf === cpf)) {
return res
.status(400)
.json({ success: false, message: "O CPF já está cadastrado." });
}
}

// Se passar nas verificações, inserir o novo usuário
await sequelize.query(
"INSERT INTO usuario (matricula, cpf, nome, sobrenome, email, senha, curso) VALUES (?, ?, ?, ?, ?, ?, ?)",
{
replacements: [matricula, cpf, nome, sobrenome, email, senha, curso],
type: Sequelize.QueryTypes.INSERT,
}
);

console.log("Cadastro feito com sucesso");
res.json({ success: true, message: "Cadastro feito com sucesso" });
} catch (error) {
console.error("Erro ao cadastrar:", error);
res.status(500).json({ success: false, message: "Erro ao cadastrar" });
}
});
app.post("/usuario", (req, res) => {
const { matricula, cpf, nome, sobrenome, email, senha, curso } = req.body;

sequelize
.query(
"INSERT INTO usuario (matricula, cpf, nome, sobrenome, email, senha, curso) VALUES (?, ?, ?, ?, ?, ?, ?)",
{
replacements: [matricula, cpf, nome, sobrenome, email, senha, curso],
type: Sequelize.QueryTypes.INSERT,
}
)
.then(() => {
console.log("Cadastro feito com sucesso"); // Loga quando o cadastro é bem-sucedido
res.json({ success: true, message: "Cadastro feito com sucesso" });
})
.catch((error) => {
console.error("Erro ao cadastrar:", error); // Loga o erro caso ocorra algum problema
res.status(500).json({ success: false, message: "Erro ao cadastrar" });
});
});
};

export const getChave = (app) => {
app.get("/chave", async (req, res) => {
const segredo =
"^VX0t#C7b3$Q4h!^v)z&FL6Mnq9#e2f5@!w4Jj%R)7*A0#Dk8Y2^&h$l3TnQ9@6r3g1cXJ*8(K7o#wF5$m)dU9P^2Zl%1@0s#Rf!Bv&3x6G$4t(N7J*Ky)Q!5D2e^@P0#r8w^hYqf%U3$n9(4J6L*7Z!vX5T@3r#2Q1h&8cF$0^m9N@)4$3b7gWl1*#K!2J(T9P3nQ^4w8D&zF5$v@6j0t#3*r)X7h9m^2L!8#4k@3$0F5U%*B^7j@9Q2t4D1&k)v3#cL!6M7f^R*4Q8$2@h3N!9W5)X&0r#4J0l3^K7*g9P$1@6$F2%8zN9*w4v(3J#0L&h^2cY7q1T5)k9mN!^$U4v5@3*2jQ8T7#r3D1&Xh@6J$0g4l9)w#^M3F2*t8P5!@7c9Q4D&1Kv$r)J2L^3nU0#8h7f1L!6P3$*Q9v^r2D#4J7w)@K8&0c5N$3h6m1F!XQ^*j9T&2$l4k7@#1p3^J)0N!D8U$w*F2v#r5&7h3^T9Q$6c4@N0*J1(L7w2D9)3gQ#F&4k5m@8$t*X7)U2r0N!9^Q@l4J6h5%3#7f$K1*T8)Xv2&0m9Jw!cL3^4Qn)@7$1h6P2D9^#rN5*F3v)4j0tW!8$U2Q%*K3@7L#9X&4h0c^6D8)N1Q9*m4P$3&v@J2#Lw7*r5h6^U0(3T8F!7$k)N4lQ2@9J5c#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0)3T5X8*2J@k6Q$1Q^7J9L0rN8h4)Tc3w$5@Q3r2)X1k7^L9N@Jh4*Q8$J6T!0Q@5w7)c1rL3T8X9^4Jh2*";
res.json(segredo);
});
};

export const getDadosPerfil = (app, sequelize) => {
app.get("/usuario_perfil/:matricula", async (req, res) => {
const { matricula } = req.params;
try {
const [results] = await sequelize.query(
`
app.get("/usuario_perfil/:matricula", async (req, res) => {
const { matricula } = req.params;
try {
const [results] = await sequelize.query(
`
SELECT
u.nome,
u.foto_url,
Expand All @@ -216,39 +140,39 @@ export const getDadosPerfil = (app, sequelize) => {
WHERE u.matricula = :matricula
GROUP BY u.nome, u.sobrenome, u.email, u.curso, u.matricula
`,
{
replacements: { matricula },
}
);
res.json({ success: true, data: results });
} catch (error) {
console.error(error);
res.status(500).send("Houve um erro ao buscar os dados");
}
});
{
replacements: { matricula },
}
);
res.json({ success: true, data: results });
} catch (error) {
console.error(error);
res.status(500).send("Houve um erro ao buscar os dados");
}
});
};

export const editarDadosPerfil = (app, sequelize) => {
app.put("/usuario_perfil", (req, res) => {
const { matricula, nome, sobrenome, email, foto_url, curso } = req.body;
sequelize
.query(
"UPDATE usuario SET nome = ?, sobrenome = ?, email = ?, foto_url = ?, curso = ? WHERE matricula = ?",
{
replacements: [nome, sobrenome, email, foto_url, curso, matricula],
type: Sequelize.QueryTypes.UPDATE,
}
)
.then(() => {
console.log("Informações atualizadas com sucesso");
res.json({
success: true,
message: "Informações atualizadas com sucesso",
});
})
.catch((error) => {
console.error("Erro ao atualizar:", error);
res.status(500).json({ success: false, message: "Erro ao atualizar" });
});
});
app.put("/usuario_perfil", (req, res) => {
const { matricula, nome, sobrenome, email, foto_url, curso } = req.body;
sequelize
.query(
"UPDATE usuario SET nome = ?, sobrenome = ?, email = ?, foto_url = ?, curso = ? WHERE matricula = ?",
{
replacements: [nome, sobrenome, email, foto_url, curso, matricula],
type: Sequelize.QueryTypes.UPDATE,
}
)
.then(() => {
console.log("Informações atualizadas com sucesso");
res.json({
success: true,
message: "Informações atualizadas com sucesso",
});
})
.catch((error) => {
console.error("Erro ao atualizar:", error);
res.status(500).json({ success: false, message: "Erro ao atualizar" });
});
});
};
35 changes: 17 additions & 18 deletions node-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import * as Comentario from "./controllers/ComentarioMET.js";
dotenv.config();

const corsOptions = {
origin: process.env.URL_FRONT_END,
methods: ["GET", "POST", "PUT", "DELETE"],
allowedHeaders: ["Content-Type", "Authorization"],
credentials: true,
origin: process.env.URL_FRONT_END,
methods: ["GET", "POST", "PUT", "DELETE"],
allowedHeaders: ["Content-Type", "Authorization"],
credentials: true,
};

const app = express();
Expand All @@ -23,23 +23,22 @@ app.use(cors(corsOptions));
app.use(express.json());

const sequelize = new Sequelize({
dialect: "mysql",
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
dialect: "mysql",
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
});

sequelize
.authenticate()
.then(function () {
console.log("Conectado ao Banco de Dados");
})
.catch(function (erro) {
console.log(erro);
});
.authenticate()
.then(function () {
console.log("Conectado ao Banco de Dados");
})
.catch(function (erro) {
console.log(erro);
});

User.autenticaUsuario(app, sequelize);
User.getDados(app, sequelize);
User.getDadosSessionStorage(app, sequelize);
User.postDados(app, sequelize);
Expand Down Expand Up @@ -73,5 +72,5 @@ Comentario.deletarRelacionamentoUsuarioComentarioMateria(app, sequelize);
Comentario.editarRelacionamentoUsuarioComentarioMateria(app, sequelize);

app.listen(3000, () => {
console.log("API is running on port 3000");
console.log("API is running on port 3000");
});
Loading

0 comments on commit 65b647f

Please sign in to comment.