Skip to content

Commit

Permalink
Merge pull request #15 from acmucsd-projects/user-authentication
Browse files Browse the repository at this point in the history
User authentication
  • Loading branch information
VinodV23 authored Sep 1, 2024
2 parents c4720e5 + f46841d commit 98f6a76
Show file tree
Hide file tree
Showing 29 changed files with 2,014 additions and 136 deletions.
11 changes: 11 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require('dotenv').config({path:'../.env'});


const config = {
DB_URL: process.env.DB_URL,

}



module.exports = config;
12 changes: 12 additions & 0 deletions config/connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var config = require('./config');

const mongoose = require('mongoose');


mongoose.connect(config.DB_URL, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
dbName: 'mainDB' }).then(() => {
console.log('Connected to MongoDB database');
});

24 changes: 24 additions & 0 deletions config/genImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
from azure.cognitiveservices.search.imagesearch import ImageSearchClient
from msrest.authentication import CognitiveServicesCredentials
import os
from pprint import pprint
import requests
import random
from dotenv import load_dotenv

load_dotenv()

subscription_key = os.environ.get('BING_API_KEY')
subscription_endpoint = "https://api.bing.microsoft.com/v7.0/images/search"
bing = ImageSearchClient(endpoint=subscription_endpoint, credentials=CognitiveServicesCredentials(subscription_key))
mkt = 'en-US'

def bingSearch(search_term):
params = { 'q': search_term, 'mkt': mkt , 'safeSearch': "Strict"}
headers = { 'Ocp-Apim-Subscription-Key': subscription_key }
response = requests.get(subscription_endpoint, headers=headers, params=params)
response.raise_for_status()
search_results = response.json()
content_url = search_results["value"][random.randint(0,len(search_results['value']))]["contentUrl"]
return content_url
21 changes: 21 additions & 0 deletions config/productSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongoose = require('mongoose');

const productSchema = new mongoose.Schema({
id: {
type: mongoose.ObjectId,
},
name: {
type: String,
required: true, // Throws error if name is missing
unique: true // Error is thrown for duplicate names
},

createdAt: {
type: Date,
default: Date.now // Sets default value as current date
}
});

const Product = mongoose.model('Product', productSchema);

// console.log('Product Schema loaded');
26 changes: 26 additions & 0 deletions config/userSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
id: {
type: mongoose.ObjectId,
},
email: {
type: String,
required: true // Throws error if email is missing
},
password: {
type: String,
//required: true // Throws error if password is missing
},
name: {
type: String,
required: true, // Throws error if name is missing
unique: true // Error is thrown for duplicate names
},
createdAt: {
type: Date,
default: Date.now // Sets default value as current date
}
});

const User = mongoose.model('User', userSchema);
28 changes: 26 additions & 2 deletions dbShellCommands.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mongosh "mongodb+srv://gogogrocery.yameky9.mongodb.net/" --apiVersion 1 --username goGoGrocery
mongosh "mongodb+srv://gogogrocery.yameky9.mongodb.net" --apiVersion 1 --username goGoGrocery
show dbs
use [dbName]
show tables
Expand All @@ -7,4 +7,28 @@ use [collectionName]
AFTER CONNECTING TO THE DATABASE:
db.login.insertOne({email:"[email protected]",password:"sup3rs3cure",name:"ex exe"})

command cheat sheet: https://gist.github.com/michaeltreat/d3bdc989b54cff969df86484e091fd0c
command cheat sheet: https://gist.github.com/michaeltreat/d3bdc989b54cff969df86484e091fd0c



//to download the data from mirabelle.openfoodfacts.org [CSV without limit]

-- Products from USA that have been scanned at least one time
select * from [all]
where countries_en like "%United States%" and unique_scans_n is not null
order by unique_scans_n desc
-- the limit here displays 20 results; the link "CSV without limit" below allows to download all the data without limit
limit 20

references:

https://mirabelle.openfoodfacts.org/products?sql=--+Products+from+Germany+that+have+been+scanned+at+least+one+time%0D%0Aselect+*+from+%5Ball%5D%0D%0Awhere+countries_en+like+%22%25United+States%25%22+and+unique_scans_n+is+not+null%0D%0Aorder+by+unique_scans_n+desc%0D%0A--+the+limit+here+displays+20+results%3B+the+link+%22CSV+without+limit%22+below+allows+to+download+all+the+data+without+limit%0D%0Alimit+20

https://wiki.openfoodfacts.org/Reusing_Open_Food_Facts_Data

https://www.mongodb.com/pricing



// from the same directory as the csv file, use this command to import the csv file into the database
mongoimport --uri "mongodb+srv://goGoGrocery:<PASSWORD>@gogogrocery.yameky9.mongodb.net/?retryWrites=true&w=majority&appName=goGoGrocery" --db mainDB --collection nutrition --type csv --file ./productsUSA.csv --headerline --drop
242 changes: 242 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
},
"keywords": [],
"author": "",
"license": "ISC"
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.5",
"mongoose": "^8.5.3"
}
}
Loading

0 comments on commit 98f6a76

Please sign in to comment.