generated from acmucsd-projects/mern-template-updated
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from acmucsd-projects/user-authentication
User authentication
- Loading branch information
Showing
29 changed files
with
2,014 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.