-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
104 lines (79 loc) · 2.94 KB
/
main.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
103
104
from flask import Flask, render_template, request, session, redirect, url_for
from pymongo import MongoClient
from bson.json_util import dumps
from random import randint
client = MongoClient("mongodb+srv://KileCodora:06907328D@cluster0.jzqkx.mongodb.net/myproject?retryWrites=true&w=majority")
app = Flask(__name__)
app.secret_key = "hkIbg#45f1"
db = client.users
users_db = db.users
db = client.data
data_db = db.data
@app.route('/home', methods=["GET","POST"])
def home():
if "auth" in session:
return render_template("Home_page.html")
else:
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
a = users_db.find_one({"email":email})
b = users_db.find_one({"email":email},{"password":password})
if a != None or b != None:
a = a['email']
b = b['password']
if a != email or b != password:
return redirect(url_for("home"))
session["auth"] = email
return redirect(url_for("home"))
else:
return render_template("Home_page.html")
@app.route('/lidostas', methods=["GET","POST"])
def lidostas():
return render_template('Lidostas.html')
@app.route('/lidmasinas', methods=["GET","POST"])
def lidmasinas():
return render_template('Lidmasinas.html')
@app.route('/reisi', methods=["GET","POST"])
def reisi():
return render_template('Reisi.html')
@app.route('/admin', methods=["GET","POST"])
def admin():
return render_template('admin.html')
@app.route('/logout', methods=["GET","POST"])
def logout():
session.pop("auth", None)
return redirect(url_for("home"))
@app.route('/registration', methods=["GET","POST"])
def registration():
if "auth" in session:
return redirect(url_for("home"))
else:
if request.method == 'POST':
id_ = randint(100,9999999)
email = request.form['email']
password = request.form['password']
a = users_db.find_one({"email":email})
if a != None:
a = a['email']
if a == email:
return redirect(url_for("home"))
session["auth"] = email
users_db.insert_one({"id":id_,"email":email,"password":password})
return redirect(url_for("home"))
else:
return render_template("registration.html")
@app.route("/login", methods=["GET","POST"])
def login():
if "name" in session and "password" in session:
if session["name"] == "admin" and session["password"] == "admin":
return redirect(url_for("panel"))
if request.method == "POST":
name = request.form["name"]
password = request.form["password"]
session["name"] = name
session["password"] = password
return redirect(url_for("panel"))
else:
return render_template("login.html")
app.run(host='0.0.0.0', port=80, debug=True)