1.7.0 New Login With Dynamic Login Token

This commit is contained in:
SowinskiBraeden committed 2021-09-26 23:20:42 -07:00
1 parent dda0741d3e
commit a23ca21c42
5 files changed
+72 -3646

No files matched your search

+24 -17
View File
@@ -1,6 +1,6 @@
const MongoClient = require('mongodb').MongoClient; const MongoClient = require('mongodb').MongoClient;
const randomstring = require('randomstring');
const io = require('socket.io-client'); const io = require('socket.io-client');
const bcrypt = require('bcrypt');
const Discord = require('discord.js'); const Discord = require('discord.js');
const client = new Discord.Client(); const client = new Discord.Client();
@@ -30,32 +30,39 @@ class Bot {
// Remote Login // Remote Login
async remoteLogin(message, args) { async remoteLogin(message, args) {
if (args.length==0) return message.author.send(`You must provide a **email** and **password** ${message.author}!`); let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
if (!args[0]==null||!args[0]==undefined&&args[1]==null||args[1]==undefined) return message.author.send(`You must provide a **password** ${message.author}!`); if (user) return message.author.send(`You are already logged in ${message.author}! Use \`?logout\` to logout or \`?account\` to see your logged in account.`);
let user = await this.dbo.collection("users").findOne({"user.email":args[0]}).then(user => user); if (args.length==0) return message.author.send(`You must provide a **email** and **login token** ${message.author}!`);
if (!args[0]==null||!args[0]==undefined&&args[1]==null||args[1]==undefined) return message.author.send(`You must provide a **login token** ${message.author}!`);
user = await this.dbo.collection("users").findOne({"user.email":args[0]}).then(user => user);
if (user==null||user==undefined) return message.author.send(`Cannot find the email **${args[0]}** ${message.author}!`); if (user==null||user==undefined) return message.author.send(`Cannot find the email **${args[0]}** ${message.author}!`);
if (user.user.discord) {
if (user.user.discord.id==message.author.id) return message.author.send(`You are already logged in ${message.author}!`);
}
// Match Password // Check discord Login Token
bcrypt.compare(args[1], user.user.password, (err, isMatch) => { if (args[1]==user.user.discordLoginToken) {
if (err) throw err;
if (isMatch) {
// Modify user to include user.user.discord // Modify user to include user.user.discord
let discord = { let discord = {
id: message.author.id, id: message.author.id,
username: message.author.username, username: message.author.username,
discriminator: message.author.discriminator discriminator: message.author.discriminator
} }
this.dbo.collection("users").updateOne({"user.email":args[0]},{$set:{"user.discord": discord}},function(err,res) { let newToken = randomstring.generate(12);
this.dbo.collection("users").updateOne(
{
"user.email": args[0]
},
{
$set: {
"user.discord": discord,
"user.discordLoginToken": newToken
}
}, function(err,res) {
if (err) throw err; if (err) throw err;
return message.author.send(`Logged in as **${user.user.username}** ${message.author}!`); return message.author.send(`Logged in as **${user.user.username}** ${message.author}!`);
});
} else {
return message.author.send(`Incorrect password for **${args[0]}** ${message.author}!`);
} }
}); );
} else {
return message.author.send(`Incorrect login token ${message.author}! Try again or Regenerate your Discord Login Token.`);
}
} }
async remoteLogout(message) { async remoteLogout(message) {
@@ -421,7 +428,7 @@ class Bot {
{ name: `**${prefix}help**`, value: 'Displays this help page', inline: true }, { name: `**${prefix}help**`, value: 'Displays this help page', inline: true },
{ name: `**${prefix}ping**`, value: 'Responds with Pong to check Bot responce', inline: true }, { name: `**${prefix}ping**`, value: 'Responds with Pong to check Bot responce', inline: true },
{ name: `**${prefix}setPrefix** <new prefix>`, value: 'Sets new prefix (Admin only command)', inline: true }, { name: `**${prefix}setPrefix** <new prefix>`, value: 'Sets new prefix (Admin only command)', inline: true },
{ name: `**${prefix}login** <email> <password>`, value: 'Login to LPS account (DM only command)', inline: true }, { name: `**${prefix}login** <email> <login token>`, value: 'Login to LPS account (DM only command)', inline: true },
{ name: `**${prefix}logout**`, value: 'Logs out of your current logged in account', inline: true }, { name: `**${prefix}logout**`, value: 'Logs out of your current logged in account', inline: true },
{ name: `**${prefix}validStatus**`, value: 'Shows list of valid statuses to updade to', inline: true }, { name: `**${prefix}validStatus**`, value: 'Shows list of valid statuses to updade to', inline: true },
{ name: `**${prefix}checkStatus** <user>`, value: 'Leave user blank to check own status', inline: true }, { name: `**${prefix}checkStatus** <user>`, value: 'Leave user blank to check own status', inline: true },
+1 -1
View File
@@ -2,7 +2,7 @@
"defaultPrefix": "?", "defaultPrefix": "?",
"botID": "860298681047056434", "botID": "860298681047056434",
"mongoURI": "mongodb+srv://lps_bot:ktSkHml2BU9EIQ0a@heroku-police-cad-dev.j7aom.mongodb.net/heroku_8pc4g86l?retryWrites=true&w=majority", "mongoURI": "mongodb+srv://lps_bot:ktSkHml2BU9EIQ0a@heroku-police-cad-dev.j7aom.mongodb.net/heroku_8pc4g86l?retryWrites=true&w=majority",
"version": "Beta 1.6.5", "version": "Beta 1.7.0",
"socket": "https://police-cad-dev.herokuapp.com/", "socket": "https://police-cad-dev.herokuapp.com/",
"dbo": "heroku_8pc4g86l" "dbo": "heroku_8pc4g86l"
} }
+1 -1
View File
@@ -2,7 +2,7 @@
"defaultPrefix": "?", "defaultPrefix": "?",
"botID": "860298681047056434", "botID": "860298681047056434",
"mongoURI": "mongodb+srv://lps_bot:ktSkHml2BU9EIQ0a@heroku-police-cad-dev.j7aom.mongodb.net/heroku_8pc4g86l?retryWrites=true&w=majority", "mongoURI": "mongodb+srv://lps_bot:ktSkHml2BU9EIQ0a@heroku-police-cad-dev.j7aom.mongodb.net/heroku_8pc4g86l?retryWrites=true&w=majority",
"version": "Beta 1.6.5", "version": "Beta 1.7.0",
"socket": "http://localhost:8080", "socket": "http://localhost:8080",
"dbo": "heroku_8pc4g86l" "dbo": "heroku_8pc4g86l"
} }
+45 -3626
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -10,11 +10,11 @@
"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",
"express": "^4.17.1", "express": "^4.17.1",
"mongodb": "^3.6.8", "mongodb": "^3.6.8",
"nodemon": "^2.0.9", "nodemon": "^2.0.9",
"randomstring": "^1.2.1",
"socket.io-client": "^4.1.2" "socket.io-client": "^4.1.2"
} }
} }