Skip to content

Commit

Permalink
Merge pull request #20 from Happy-Park/add-ifFuncionario-login
Browse files Browse the repository at this point in the history
Add if para verificar se o login é de usuario ou funcionario
  • Loading branch information
francisco-cavasan authored Sep 2, 2021
2 parents 8c135b3 + eb90f99 commit cb6688b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@ const crypto = require("crypto");
const db = require("../src/postgres");

const notyf = new Notyf({
position: {
x: "right",
y: "top",
}});
position: {
x: "right",
y: "top",
},
});
db.connect();
const button = document.getElementById("login-btn");
const user = document.getElementById("username");

button.addEventListener("click", function () {
let password = document.getElementById("password").value;
//FAZER CAMPO ISWORKER NA TABELA USUARIO PARA FACILITAR O LOGIN
const query = `select usuario.email, usuario.senha from usuario where usuario.email='${user.value}'`;
const query = `select usuario.email, usuario.senha, usuario.funcionario from usuario where usuario.email='${user.value}'`;
db.query(query, (err, res) => {
if (err) {
console.error(err);
}
password = crypto.createHash("sha256").update(password).digest("hex");

if (res.rowCount === 0) {
notyf.error('Usuário não encontrado');
notyf.error("Usuário não encontrado");
} else {
if (res.rows[0].email === user.value) {
if (res.rows[0].senha === password) {
window.location.href = "../pages/home.html";
if (res.rows[0].funcionario === true) {
window.location.href = "../pages/home.html";
} else {
window.location.href = "../pages/home_user.html";
}
} else {
notyf.error('Senha incorreta!');
notyf.error("Senha incorreta!");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ button.addEventListener("click", function () {
console.log(err);
}
cityNumber = res.rows[0].id;
const query = `insert into usuario values(default,${cpf.value.replaceAll(".", "").replaceAll("-", "")},'${name.value}','${phone.value}','${email.value}','${password}','${birthdate.value}',${cityNumber})`;
const query = `insert into usuario values(default,${cpf.value.replaceAll(".", "").replaceAll("-", "")},'${name.value}','${phone}','${email.value}','${password}','${birthdate.value}',${cityNumber})`;
console.log(query);
db.query(query, (err, res) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/register_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ button.addEventListener("click", function () {
console.log(err);
}
cityNumber = res.rows[0].id;
//fazer campo data de admissao
const query = `insert into usuario values(default,${cpf.value.replaceAll(".", "").replaceAll("-", "")},'${name.value}','${phone.value}','${email.value}','${password}','${birthdate.value}',${cityNumber},${admin},'true')`;
console.log(query);
db.query(query, (err, res) => {
Expand All @@ -56,6 +55,7 @@ button.addEventListener("click", function () {
console.log(err);
} else {
notyf.success("Cadastro realizado com sucesso!");
window.location.href = "../pages/home.html";
}
console.log(res);
});
Expand Down

0 comments on commit cb6688b

Please sign in to comment.