-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
105 lines (75 loc) · 2.9 KB
/
app.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from flask import Flask, render_template, request, make_response,redirect, url_for, flash , session
from pymongo import MongoClient
import secrets
import time
app = Flask(__name__)
app.secret_key = secrets.token_hex(16)
# Function to check if the session has expired
def session_expired():
if 'login_time' in session:
# Check if the session is expired (5 minutes)
return time.time() - session['login_time'] > 300
return True
@app.route('/database', methods=['POST'])
def button_click():
username = request.form.get('username')
email = request.form.get('email')
password = request.form.get('password')
client = MongoClient('you atlas cluster link')#I ve removeed my one
db = client['mydatabase']
users_collection = db['users']
user_data = {'username': username, 'email': email, 'password': password}
users_collection.insert_one(user_data)
print(f"Username: {username}, Email: {email}, Password: {password}")
return render_template('login.html')
@app.route('/databaselogin', methods=['POST'])
def submit_login():
username = request.form.get('username')
password = request.form.get('password')
client = MongoClient('mongodb+srv://sohamshahh:soham2003@cluster0.x5owqbs.mongodb.net/')
db = client['mydatabase']
users_collection = db['users']
# Retrieve user by username
query = {'username': username, 'password': password}
user = users_collection.find_one(query)
if user:
flash('Login successful!', 'success') # Flash a success message
session['username'] = username # Set the username in the session
session['login_time'] = time.time() # Set the login time
response = make_response(redirect(url_for('index')))
# Set cookies
response.set_cookie('isAuthenticated', 'true')
response.set_cookie('username', username)
return response
# return redirect(url_for('index')) # Redirect to the index page after successful login
else:
flash('Login failed. Invalid username or password.', 'error') # Flash an error message
return redirect(url_for('login')) # Redirect to the login page on login failure
@app.route('/logout')
def logout():
session.clear() # Clear the session data
return redirect(url_for('login'))
@app.route('/')
def index():
return render_template('index.html')
@app.route('/DA')
def data_analyst():
return render_template('DA.html')
@app.route('/selfpractice')
def selfpractice():
return render_template('selfpractice.html')
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/signup')
def signup():
return render_template('signup.html')
@app.route('/DE')
def data_engineer():
return render_template('DE.html')
@app.route('/DS')
def data_science():
return render_template('DS.html')
@app.route('/about')
def about():
return render_template('about.html')