Skip to content

Commit

Permalink
Create app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ManaS066 authored Aug 29, 2024
1 parent 2a9454e commit efa8917
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions Government of NCT of Delhi/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from flask import Flask, render_template, request, redirect
import os
from pymongo import MongoClient

app = Flask(__name__)


from flask_bcrypt import Bcrypt
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi

uri = "mongodb+srv://manasranjanpradhan2004:[email protected]/?retryWrites=true&w=majority&appName=HMS"

# Create a new client and connect to the server
client = MongoClient(uri, server_api=ServerApi('1'))

# Send a ping to confirm a successful connection
try:
client.admin.command('ping')
print("Pinged your deployment. You successfully connected to MongoDB!")
except Exception as e:
print(e)
db = client['HMS']
patients_collection = db['patients']
doctors_collection = db['doctors']
users_collection = db['users']
admin_collection = db['admin']
appointment_collection = db['appointment']
contact_collection = db['contact']

bcrypt = Bcrypt(app)




@app.route('/',methods=['GET', 'POST'])
def landing():
if request.method=='POST':
name= request.form['name']
email = request.form['email']
number = request.form['number']
comment = request.form['comment']
contact_data = {
'name': name,
'email': email,
'number': number,
'comment': comment
}
contact_collection.insert_one(contact_data)
return render_template('index.html')


@app.route('/user_register',methods=['GET','POST'])
def user_register():
if request.method=='POST':
name=request.form['name']
number=request.form['phone']
email= request.form['email']
user_name = request.form['username']
existing_user = users_collection.find_one({'$or': [{'username': user_name}, {'email': email}]})
if existing_user:
return 'Username or email already exists'
pa = request.form['password']
password=bcrypt.generate_password_hash(pa).decode('utf-8')
user_data={
'name':name,
'username':user_name,
'number':number,
'password':password
}
users_collection.insert_one(user_data)
return render_template('user login.html')
return render_template('user register.html')






















if __name__ == '__main__':
app.run( port=8000,debug=True)

0 comments on commit efa8917

Please sign in to comment.