Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolução de conflitos #3

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14, 16]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Run tests
env:
Admin_email: ${{ secrets.Admin_email }}
Admin_celular: ${{ secrets.Admin_celular }}
Admin_senha: ${{ secrets.Admin_senha }}
User_email: ${{ secrets.User_email }}
User_celular: ${{ secrets.User_celular }}
User_senha: ${{ secrets.User_senha }}
run: npm test
39 changes: 19 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Dependências instaladas
/node_modules

# Arquivos de log
npm-debug.log
yarn-debug.log
yarn-error.log
package-lock.json

# Arquivos de ambiente
.env

# Arquivos de build
/build
/coverage

# Arquivos de configuração de IDEs
.idea
.vscode
.env
# Dependências instaladas
/node_modules

# Arquivos de log
npm-debug.log
yarn-debug.log
yarn-error.log
package-lock.json

# Arquivos de ambiente
.env

# Arquivos de build
/build
/coverage

# Arquivos de configuração de IDEs
.idea
.vscode
.vs/
10 changes: 2 additions & 8 deletions src/Controllers/membershipController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const { sendEmail } = require("../Utils/email");
const Membership = require("../Models/membershipSchema");
const generator = require("generate-password");
const bcrypt = require("bcryptjs");
const Token = require("../Models/tokenSchema");
const { generateRecoveryPasswordToken } = require("../Utils/token");
const salt = bcrypt.genSaltSync();
const saltRounds = 13;
const Role = require("../Models/roleSchema");

const createMembershipForm = async (req, res) => {
Expand Down Expand Up @@ -35,7 +34,7 @@

const sindRole = await Role.findOne({ name: "sindicalizado" });
if (!sindRole) {
console.error(

Check warning on line 37 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
'Role "sindicalizado" não encontrada. Crie a role antes de adicionar o usuário administrador.'
);
return;
Expand All @@ -45,12 +44,7 @@

const membership = new Membership(formData);

const temp_pass = generator.generate({
length: 8,
numbers: true,
});

membership.password = bcrypt.hashSync(temp_pass, salt);
membership.password = await bcrypt.hash(formData.senha, saltRounds);

await membership.save();
return res.status(201).send(membership);
Expand All @@ -63,7 +57,7 @@
try {
const sindRole = await Role.findOne({ name: "sindicalizado" });
if (!sindRole) {
console.error('Role "sindicalizado" não encontrada.');

Check warning on line 60 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
// prettier-ignore
return res
.status(404).send({ error: 'Role "sindicalizado" não encontrada.' });
Expand All @@ -78,7 +72,7 @@
const membership = await Membership.find(query);
return res.status(200).send(membership);
} catch (error) {
console.error("Erro no getMembershipForm:", error);

Check warning on line 75 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
return res.status(400).send({ error: error.message });
}
};
Expand Down
6 changes: 5 additions & 1 deletion src/Controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ const login = async (req, res) => {

try {
if (typeof email == "string") {
const user = await User.findOne({ email: email, status: true });
const user = await User.findOne({
email: email,
//"Gamebiarra" Não deve ficar aqui no final
status: true,
});

if (!user) {
return res
Expand Down
44 changes: 30 additions & 14 deletions src/Utils/initDatabase.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
/*Para inicializar o Database você precisa criar um arquivo .env na raiz do projeto com os seguintes dados:
######################################################################################
Admin_email=
Admin_celular=
Admin_senha=
User_email=
User_celular=
User_senha=
######################################################################################
Altere os dados de forma que melhor desejar para iniciar o banco de dados com um usuário comum e um usuario Administrador.
*/

// ./utils/initRoles.js
const mongoose = require("mongoose");
const Role = require("../Models/roleSchema"); // Ajuste o caminho conforme necessário
const User = require("../Models/userSchema");
const bcrypt = require("bcryptjs");
const saltRounds = 13;

const salt = bcrypt.genSaltSync();
const senhaAdmin = process.env.Admin_senha;
const emailAdmin = process.env.Admin_email;
const celularAdmin = process.env.Admin_celular;
const senhaUser = process.env.User_senha;
const emailUser = process.env.User_email;
const celularUser = process.env.User_celular;

const initializeRoles = async () => {
const roles = [
Expand Down Expand Up @@ -53,7 +71,6 @@ const initializeRoles = async () => {
];

try {
// Verificar se a conexão está aberta antes de executar
if (mongoose.connection.readyState === 1) {
for (const roleData of roles) {
const existingRole = await Role.findOne({
Expand All @@ -75,7 +92,6 @@ const initializeRoles = async () => {
}

try {
// Verificar se a conexão está aberta antes de executar
if (mongoose.connection.readyState === 1) {
// Busca o user 'administrador'
const adminRole = await Role.findOne({ name: "administrador" });
Expand All @@ -93,18 +109,19 @@ const initializeRoles = async () => {
return;
}

// Verifica se o usuário administrador já existe
const existingAdmin = await User.findOne({
email: "admin@admin.com",
email: emailAdmin,
});
if (!existingAdmin) {
const hashedPassword = await bcrypt.hash("senha", salt); // Altere a senha padrão conforme necessário
const hashedPassword = await bcrypt.hash(
senhaAdmin,
saltRounds
);

// Cria o usuário administrador
const adminUser = new User({
name: "Admin",
email: "admin@admin.com",
phone: "1234567890",
email: emailAdmin,
phone: celularAdmin,
status: true,
password: hashedPassword,
role: adminRole._id,
Expand All @@ -118,16 +135,15 @@ const initializeRoles = async () => {
}

const ExistingSindicalizado = await User.findOne({
email: "user@user.com",
email: emailUser,
});
if (!ExistingSindicalizado) {
const hashedPassword = await bcrypt.hash("senha", salt); // Altere a senha padrão conforme necessário
const hashedPassword = await bcrypt.hash(senhaUser, saltRounds);

// Cria o usuário administrador
const sindUser = new User({
name: "User",
email: "user@user.com",
phone: "61981818181",
email: emailUser,
phone: celularUser,
status: true,
password: hashedPassword,
role: userRole,
Expand Down
Loading