-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (45 loc) · 1.96 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const { MongoClient } = require('mongodb');
// or as an es module:
// import { MongoClient } from 'mongodb'
require("dotenv").config();
const URI = process.env.URL_API_MONGO;
// Connection URL
const url = URI;
const client = new MongoClient(url);
// Database Name
const dbName = process.env.DBNAME;
exports = ({ token, tokenId, username, password, currentPasswordValid }) => {
// check if the username corresponds to a real user
const isUser = myCustomValidator.validate(username);
// check if the user is attempting to reset their password to their current password
if (currentPasswordValid) {
myCustomNotifier.sendMessage(username, "Cannot reset password to current password.");
return { status: 'fail' };
}
// check if the user has requested a password reset too often recently
const isNotCoolingDown = myCustomCooldownService.canReset(username, 'myCustomService')
// send a message to the user in some way so that the user can confirm themselves
const msgSendSuccessful = isUser && isNotCoolingDown && myCustomMsgr.send(username, token, tokenId)
if ( msgSendSuccessful ) {
return { status: 'pending' };
} else {
return { status: 'fail' };
}
}
async function main() {
// Use connect method to connect to the server
await client.connect();
console.log('Connected successfully to server');
const db = client.db(dbName);
const collection = db.collection('usuarios');
const insertResult = await collection.insertMany([{ id: 1, nombres:"Jose" ,apellidos:"Mejia Bolaños", Rol:"Contador" }, { id: 2, nombres:"Fabian" ,apellidos:"Jimenez", Rol:"Administrador" }, { id: 3, nombres:"Fabian" ,apellidos:"Jimenez", Rol:"Caja"}]);
console.log('Inserted documents =>', insertResult);
// the following code examples can be pasted here...
const findResult = await collection.find({}).toArray();
console.log('Found documents =>', findResult);
return 'done.';
}
main()
.then(console.log)
.catch(console.error)
.finally(() => client.close());