Skip to content

Commit

Permalink
Your commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Richjerk committed May 22, 2024
1 parent c56f132 commit 762e917
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
34 changes: 34 additions & 0 deletions auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# auth.py
import hashlib
from db import get_users_collection

def hash_password(password):
return hashlib.sha256(password.encode()).hexdigest()

def register_user(username, email, password):
users_collection = get_users_collection()
if users_collection.find_one({"email": email}):
return "User already exists"

hashed_password = hash_password(password)
user = {
"username": username,
"email": email,
"password": hashed_password
}
users_collection.insert_one(user)
return "User registered successfully"

def login_user(email, password):
users_collection = get_users_collection()
user = users_collection.find_one({"email": email})

if not user:
return "Invalid credentials"

hashed_password = hash_password(password)
if user['password'] != hashed_password:
return "Invalid credentials"

return "Login successful"

15 changes: 15 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# db.py
import pymongo
from pymongo import MongoClient

# Replace the following with your MongoDB Atlas connection string
MONGODB_URI = "mongodb://atlas-sql-64cf1e5950ebbc37fa7eee8e-icpps.a.query.mongodb.net/ShopLocal-Assistant?ssl=true&authSource=admin"

def get_database():
client = MongoClient(MONGODB_URI)
return client['mongodb://atlas-sql-64cf1e5950ebbc37fa7eee8e-icpps.a.query.mongodb.net/ShopLocal-Assistant?ssl=true&authSource=admin']

def get_users_collection():
db = get_database()
return db['users']

1 change: 1 addition & 0 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import ollama
from PIL import Image
from auth import register_user, login_user
from ollama_api import query_ollama # Import the function

# Your existing Streamlit code...
Expand Down

0 comments on commit 762e917

Please sign in to comment.