Skip to content

Commit cdfdbb8

Browse files
committed
Login data to mongoDB + extra (read comment)
Co-authored-by: Jon Cruz [email protected] Co-authored-by: Elena Atencio [email protected] Co-authored-by: John Donato [email protected]
1 parent 7d185fd commit cdfdbb8

File tree

13 files changed

+12457
-22
lines changed

13 files changed

+12457
-22
lines changed

app/components/Login.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const Login = React.memo(() => {
2323
// eslint-disable-next-line no-return-assign
2424
// inputFields.forEach(input => (input.value = ''));
2525
const response: boolean | string = ipcRenderer.sendSync('login', { username, password });
26-
if (typeof(response) === 'string') {
26+
if (typeof (response) === 'string') {
27+
console.log('response', response)
2728
setUser(username);
2829
setMode(response);
2930
navigate('/');

electron/databases/mongo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import mongoose from 'mongoose';
22
// import { MongoError } from 'mongodb';
33

44
// Mongoose connection wrapped in function that takes the index of the selected database as the parameter. This index is used to target the correct database for querying.
5-
const connectMongoose = async (URI: string) => {
5+
const connectMongoose = async (i:number, URI: string) => {
66
try {
77
await mongoose.connection.close();
88
const db = await mongoose.connect(URI);

electron/routes/dashboard.ts

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const User = require('../models/UserModel')
88
const mongoose = require('mongoose');
99
// const db = require('../databases/mongo')
1010

11-
const MONGO_URI = ''
11+
const MONGO_URI = 'mongodb+srv://wiris316:[email protected]/?retryWrites=true&w=majority'
1212

1313
mongoose.connect(MONGO_URI, {
1414
useNewUrlParser: true,
@@ -141,7 +141,8 @@ ipcMain.on('addAwsApp', (message: IpcMainEvent, application: any) => {
141141
ipcMain.on('getApps', (message: IpcMainEvent) => {
142142
// Retrieves file contents from settings.json for current Apps
143143
const settings = JSON.parse(fs.readFileSync(settingsLocation).toString('utf8'));
144-
const services: string[][] = settings[currentUser].services;
144+
// const services: string[][] = settings[currentUser].services;
145+
const services: string[][] = settings['guest'].services; // temporarily set to guests at every login attempt
145146

146147
// Return an array of arrays that is a subset of the full services array
147148
const dashboardList: string[][] = services.map((arr: string[]) => [
@@ -255,15 +256,44 @@ ipcMain.on('login', (message: IpcMainEvent, user: { username: string; password:
255256
const { username, password } = user;
256257

257258
// Load in the stored users
258-
const settings = JSON.parse(fs.readFileSync(settingsLocation).toString('utf8'));
259-
if (username in settings && bcrypt.compareSync(password, settings[username].password)) {
260-
currentUser = username;
261-
message.returnValue = settings[username].mode;
262-
return;
263-
} else {
264-
message.returnValue = false;
265-
return;
266-
}
259+
// const settings = JSON.parse(fs.readFileSync(settingsLocation).toString('utf8'));
260+
// if (username in settings && bcrypt.compareSync(password, settings[username].password)) {
261+
// currentUser = username;
262+
// message.returnValue = settings[username].mode;
263+
// return;
264+
// } else {
265+
// message.returnValue = false;
266+
// return;
267+
// }
268+
console.log('in login')
269+
270+
return User.findOne({ username : username })
271+
.then((data) => {
272+
console.log('data', data)
273+
if (data !== null && bcrypt.compareSync(password, data.password)) {
274+
console.log('User found');
275+
// console.log('found data', data.mode)
276+
currentUser = username
277+
message.returnValue = data.mode
278+
return message.returnValue;
279+
} else {
280+
message.returnValue = false;
281+
return message.returnValue;
282+
}
283+
})
284+
.catch((error) => {
285+
console.log(`checkUser failed : ${error}`)
286+
// return false;
287+
})
288+
289+
290+
291+
292+
293+
294+
295+
296+
267297
});
268298

269299
ipcMain.on('signOut', (message: IpcMainEvent) => {

electron/routes/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ipcMain.on('connect', async (message: Electron.IpcMainEvent, username: string, i
4747
const [databaseType, URI] = [userDatabase[1], userDatabase[2]];
4848

4949
// Connect to the proper database
50-
if (databaseType === 'MongoDB') await connectMongo(URI);
50+
if (databaseType === 'MongoDB') await connectMongo(index,URI);
5151
if (databaseType === 'SQL') pool = await connectPostgres(index, URI);
5252

5353
// Currently set to a global variable

0 commit comments

Comments
 (0)