Login Logic
This commit is contained in:
1 parent
cef83877a7
commit
74c50b193c
4 files changed
+820
-242
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
const mongodb = require('mongodb');
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
|
const bcrypt = require('bcrypt');
|
||||||
const socket = require('socket.io');
|
const socket = require('socket.io');
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const client = new Discord.Client();
|
const client = new Discord.Client();
|
||||||
@@ -20,9 +21,31 @@ async function newPrefix(message, n) {
|
|||||||
|
|
||||||
// Remote Login
|
// Remote Login
|
||||||
async function remoteLogin(message, args) {
|
async function remoteLogin(message, args) {
|
||||||
if (!args) return message.channel.send(`You must provide a **username** and **password** ${message.author}!`);
|
if (args.length==0) return message.author.send(`You must provide a **email** and **password** ${message.author}!`);
|
||||||
if (!args[1]) return message.channel.sned(`You must provide a **password** ${message.author}!`);
|
if (!args[0]==null||!args[0]==undefined&&args[1]==null||args[1]==undefined) return message.author.send(`You must provide a **password** ${message.author}!`);
|
||||||
// Login logic???
|
|
||||||
|
MongoClient.connect(config.mongoURI,{useUnifiedTopology:true},function(err, db) {
|
||||||
|
if (err) throw err;
|
||||||
|
let dbo = db.db("knoldus");
|
||||||
|
dbo.collection("users").findOne({"user.email":args[0]}, function(err, result) {
|
||||||
|
if (err) throw err;
|
||||||
|
if (result==null||result==undefined) return message.author.send(`Cannot find the email **${args[0]}** ${message.author}!`);
|
||||||
|
|
||||||
|
// Match Password
|
||||||
|
bcrypt.compare(args[1], result.user.password, (err, isMatch) => {
|
||||||
|
if (err) throw err;
|
||||||
|
if (isMatch) {
|
||||||
|
// Log in data Discord is linked to this email for LPS
|
||||||
|
data.userAcc[message.author] = result.user.email;
|
||||||
|
console.log(data);
|
||||||
|
return message.author.send(`Logged in as **${result.user.username}** ${message.author}!`);
|
||||||
|
} else {
|
||||||
|
return message.author.send(`Incorrect password for **${args[0]}** ${message.author}!`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
db.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
@@ -72,10 +95,8 @@ client.on('message', (message) => {
|
|||||||
}
|
}
|
||||||
// Login
|
// Login
|
||||||
if (command == 'login') {
|
if (command == 'login') {
|
||||||
console.log(message.channel.type);
|
|
||||||
if (message.channel.type=="text") return message.channel.send(`You must direct message me to login ${message.author}!`);
|
if (message.channel.type=="text") return message.channel.send(`You must direct message me to login ${message.author}!`);
|
||||||
message.author.send("Login");
|
remoteLogin(message, args);
|
||||||
//remoteLogin(message, args);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"defaultPrefix": "?",
|
"defaultPrefix": "?",
|
||||||
"token": "ODYwMjk4NjgxMDQ3MDU2NDM0.YN5NlQ.EeoaT9X-Qk8mg26E3vircZkPlus",
|
"token": "ODYwMjk4NjgxMDQ3MDU2NDM0.YN5NlQ.EeoaT9X-Qk8mg26E3vircZkPlus",
|
||||||
"botID": "860298681047056434"
|
"botID": "860298681047056434",
|
||||||
|
"mongoURI": "mongodb://localhost/27017"
|
||||||
}
|
}
|
||||||
Generated
+789
-234
File diff suppressed because it is too large.
Load diff
@@ -10,6 +10,7 @@
|
|||||||
"author": "Braeden Sowinski",
|
"author": "Braeden Sowinski",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"bcrypt": "^5.0.1",
|
||||||
"discord.js": "^12.5.3",
|
"discord.js": "^12.5.3",
|
||||||
"mongodb": "^3.6.8",
|
"mongodb": "^3.6.8",
|
||||||
"nodemon": "^2.0.9",
|
"nodemon": "^2.0.9",
|
||||||
|
|||||||
Reference in new issue
Block a user