npm run sendemail
This commit is contained in:
@@ -10,4 +10,8 @@ HOSTDB = localhost
|
||||
|
||||
TOKEN_SEED = seedAcatlan
|
||||
|
||||
TOKEN_EXP = 1d
|
||||
TOKEN_EXP = 1d
|
||||
|
||||
EMAIL = 'alfredo.jl323@gmail.com'
|
||||
|
||||
EMAILPASS = 'Everybody56.'
|
||||
@@ -0,0 +1,48 @@
|
||||
const symbols = require('log-symbols');
|
||||
const generator = require('generate-password');
|
||||
const admin = require('../server/models/tablas/Admin');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
const send = require('gmail-send')({
|
||||
user: process.env.EMAIL,
|
||||
pass: process.env.EMAILPASS,
|
||||
subject: 'Credenciales para ingreso a sistema de censo.'
|
||||
});
|
||||
|
||||
const emails = [
|
||||
'alfredo.lima@acatlan.unam.mx',
|
||||
'312047278@pcpuma.acatlan.unam.mx'
|
||||
];
|
||||
|
||||
emails.forEach(async(email, index) => {
|
||||
|
||||
// Para pruebas
|
||||
await admin.sync({ force: true });
|
||||
|
||||
let tempPass = generator.generate({
|
||||
length: 8,
|
||||
numbers: true,
|
||||
symbols: true,
|
||||
exclude: `"`,
|
||||
strict: true
|
||||
});
|
||||
console.log(symbols.info, `Creating user ${email}...`);
|
||||
let tempUser = await admin.create({
|
||||
name: email,
|
||||
password: bcrypt.hashSync(tempPass, 10),
|
||||
isAdmin: false
|
||||
});
|
||||
if (!tempUser)
|
||||
return console.log(symbols.error, 'Error creating user. Exiting.');
|
||||
console.log(`Sending email to ${email}`);
|
||||
await send({
|
||||
to: email,
|
||||
text: `Usuario: ${email}\nContraseña: ${tempPass}\nSaludos.`
|
||||
},
|
||||
async(err, res, resFull) => {
|
||||
if (err)
|
||||
return console.log(symbols.error, err);
|
||||
console.log(symbols.success, 'User created. Email sent.');
|
||||
});
|
||||
|
||||
})
|
||||
Generated
+22
@@ -761,6 +761,12 @@
|
||||
"is-property": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"generate-password": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/generate-password/-/generate-password-1.5.1.tgz",
|
||||
"integrity": "sha512-XdsyfiF4mKoOEuzA44w9jSNav50zOurdWOV3V8DbA7SJIxR3Xm9ob14HKYTnMQOPX3ylqiJMnQF0wEa8gXZIMw==",
|
||||
"dev": true
|
||||
},
|
||||
"get-stream": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz",
|
||||
@@ -801,6 +807,16 @@
|
||||
"ini": "^1.3.5"
|
||||
}
|
||||
},
|
||||
"gmail-send": {
|
||||
"version": "1.8.10",
|
||||
"resolved": "https://registry.npmjs.org/gmail-send/-/gmail-send-1.8.10.tgz",
|
||||
"integrity": "sha512-QMpWwzeA64U69HzOEzI37UNc73xXkhTg8LuqsfKX9W7LjiQY3yRvViVn7ZhuJWLTV4136vsLJf2sXiZKmdykbw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"lodash": "^4.17.15",
|
||||
"nodemailer": "^6.3.0"
|
||||
}
|
||||
},
|
||||
"got": {
|
||||
"version": "9.6.0",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
|
||||
@@ -1425,6 +1441,12 @@
|
||||
"tar": "^4.4.2"
|
||||
}
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "6.4.11",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.11.tgz",
|
||||
"integrity": "sha512-BVZBDi+aJV4O38rxsUh164Dk1NCqgh6Cm0rQSb9SK/DHGll/DrCMnycVDD7msJgZCnmVa8ASo8EZzR7jsgTukQ==",
|
||||
"dev": true
|
||||
},
|
||||
"nodemon": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.4.tgz",
|
||||
|
||||
+31
-28
@@ -1,30 +1,33 @@
|
||||
{
|
||||
"name": "censo2020back",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test:db": "node server/config/test",
|
||||
"install:db": "node server/models/install"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.0.0",
|
||||
"colors": "^1.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"log-symbols": "^4.0.0",
|
||||
"mariadb": "^2.4.2",
|
||||
"moment": "^2.27.0",
|
||||
"mysql2": "^2.1.0",
|
||||
"node-localstorage": "^2.1.6",
|
||||
"sequelize": "^6.3.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.4"
|
||||
}
|
||||
"name": "censo2020back",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test:db": "node server/config/test",
|
||||
"install:db": "node server/models/install",
|
||||
"sendemail": "node helpers/sendEmail"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.0.0",
|
||||
"colors": "^1.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"log-symbols": "^4.0.0",
|
||||
"mariadb": "^2.4.2",
|
||||
"moment": "^2.27.0",
|
||||
"mysql2": "^2.1.0",
|
||||
"node-localstorage": "^2.1.6",
|
||||
"sequelize": "^6.3.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"generate-password": "^1.5.1",
|
||||
"gmail-send": "^1.8.10",
|
||||
"nodemon": "^2.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkQWRtaW4iOjIsIm5hbWUiOiJhbGZyZWRvamwiLCJwYXNzd29yZCI6IiQyYiQxMCRtTUlnR0NUUGlhU01ObnhmcnQ1bG5lV29xTlhQZVV5aGVFVEw4RFBOMU1nRENIT3lLeEsvRyIsImlzQWRtaW4iOmZhbHNlLCJjcmVhdGVkQXQiOiIyMDIwLTA4LTE3VDE5OjE3OjQ5LjAwMFoiLCJ1cGRhdGVkQXQiOiIyMDIwLTA4LTE3VDE5OjE3OjQ5LjAwMFoifSwiaWF0IjoxNTk3ODgyNjExLCJleHAiOjE1OTc5NjkwMTF9.J_VzUBKHZ4PWHjd2NVEOqjOgSWhEr2k4QWJyZzQORp4
|
||||
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkQWRtaW4iOjEsIm5hbWUiOiJhbGZyZWRvLmxpbWFAYWNhdGxhbi51bmFtLm14IiwicGFzc3dvcmQiOiIkMmIkMTAkVVJYZzUvYXVCeG1McEY4L21CRzRmLklhZTFjd1dKeTZPSUNwYllhY2dNWHN6NVgvRmRQR3kiLCJpc0FkbWluIjpmYWxzZSwiY3JlYXRlZEF0IjoiMjAyMC0wOC0yMVQwMjo0OToyNS4wMDBaIiwidXBkYXRlZEF0IjoiMjAyMC0wOC0yMVQwMjo0OToyNS4wMDBaIn0sImlhdCI6MTU5Nzk3ODM4MSwiZXhwIjoxNTk4MDY0NzgxfQ.U7kSEbe6KwJ-olk-GUMBt4y10VT80D1ICOzyGB8OINs
|
||||
@@ -15,19 +15,19 @@ const post = async(req, res) => {
|
||||
});
|
||||
|
||||
if (user == null) {
|
||||
console.log("not found!");
|
||||
console.log("Invalid user or password");
|
||||
return res.status(500).json({
|
||||
err: {
|
||||
message: `No se pudo encontrar «${body.name}»`
|
||||
message: "Invalid user or password"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (!bcrypt.compareSync(body.password, user.password)) {
|
||||
console.log('Wrong password');
|
||||
console.log('Invalid user or password');
|
||||
return res.json({
|
||||
err: {
|
||||
message: 'Wrong password'
|
||||
message: 'Invalid user or password'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user