-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
40 lines (25 loc) · 990 Bytes
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import g
from flask_pymongo import MongoClient
# 8Wnd2SHngkxjdUkR kaustubhmayekar02
def get_db():
if 'db' not in g:
# Replace 'your_connection_string' with your MongoDB Atlas connection string
client = MongoClient('mongodb+srv://kaustubhmayekar02:[email protected]/?retryWrites=true&w=majority&appName=Cluster0')
g.db = client['users']
print("db connected")
return g.db
def close_db(e=None):
db = g.pop('db', None)
if db is not None:
db.client.close()
def insert_user(username, mobile, email, password):
db = get_db()
user_data = {'username': username, 'mobile': mobile, 'email': email, 'password': password}
db.users.insert_one(user_data)
def get_user(email):
db = get_db()
return db.users.find_one({'email': email})
def verify_password(user, password):
return user and user['password'] == password
def init_app(app):
app.teardown_appcontext(close_db)