forked from Micky-12/Question_Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini.py
68 lines (57 loc) · 2.32 KB
/
mini.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from flask import Flask, render_template, request, redirect
import csv
app = Flask(__name__)
# Function to save username, email, and password to a CSV file
def save_to_csv(username, email, password):
try:
with open(r"C:\Users\harsha anand\Desktop\Miniproject\flask\static\uploads\user.csv", 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([username, email, password])
except Exception as e:
print(f"Error saving to CSV: {e}")
return False
# Function to check if username exists in the CSV file
def username_exists(username):
with open(r"C:\Users\harsha anand\Desktop\Miniproject\flask\static\uploads\user.csv", 'r') as file:
reader = csv.reader(file)
for row in reader:
if row[0] == username:
return True
return False
# Route to handle the login page
@app.route('/')
def login():
return render_template("login.html")
# Route to handle the form submission
@app.route("/login", methods=['POST'])
def login_submit():
username = request.form['username']
password = request.form['password']
# Check if the username exists and credentials match
if username_exists(username):
# Implement password checking logic here
return redirect("/preview") # Redirect to preview page on successful login
else:
return redirect("/register") # Redirect to registration page if username doesn't exist or credentials don't match
# Route to handle the registration page
@app.route("/register")
def register():
return render_template("register.html")
# Route to handle the registration form submission
@app.route("/register", methods=['POST'])
def register_submit():
username = request.form['username']
email = request.form['email']
password = request.form['password']
# Check if the username already exists
if username_exists(username):
print("Username Exist")
else:
save_to_csv(username, email, password) # Save username, email, and password to CSV
return redirect('/login') # Redirect to login page after registration
# Route to handle the preview page
@app.route("/preview")
def preview():
return render_template("preview.html")
if __name__ == '__main__':
app.run(debug=True)