-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
106 lines (87 loc) · 3.05 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
105
106
from flask import Flask, render_template, request, redirect, flash, abort
import flask_login
import pymysql
from dynaconf import Dynaconf
app = Flask(__name__)
conf = Dynaconf(
settings_file = ["settings.toml"]
)
app.secret_key = conf.secret_key
login_manager = flask_login.LoginManager()
login_manager.init_app(app)
class User:
is_authenticated = True
is_anonymous = False
is_active = True
def __init__(self, user_id, username, email, first_name, last_name):
self.id = user_id
self.username = username
self.email = email
self.first_name = first_name
self.last_name = last_name
def get_id(self):
return str(self.id)
@login_manager.user_loader
def load_user(user_id):
conn = connectdb()
cursor = conn.cursor()
cursor.execute(f"SELECT * FROM `Customer` WHERE `id` = {user_id};")
result = cursor.fetchone()
cursor.close()
conn.close()
if result is not None:
return User(result["id"], result["username"], result["email"], result["first_name"], result["last_name"])
def connectdb():
conn = pymysql.connect(
host = "https://db.steamcenter.tech/index.php?route=/&db=plot_point&table=User",
database = "",
user = conf.username,
password = conf.password,
autocommit = True,
cursorclass = pymysql.cursors.DictCursor
)
return conn
@app.route("/")
def index ():
return render_template("homepage.html.jinja")
@app.route("/signin")
def sin ():
return render_template("signin.html.jinja")
@app.route("/signup")
def sup ():
if flask_login.current_user.is_authenticated:
return redirect ("/")
else:
if request.method == "POST":
first_name = request.form["fname"]
last_name = request.form["lname"]
username = request.form["username"]
password = request.form["pass"]
confirmpassword = request.form["confirmpass"]
email = request.form["email"]
address = request.form["address"]
conn = connectdb()
cursor = conn.cursor()
if len(password) < 8:
flash("Password contains less than 8 characters")
if confirmpassword != password:
flash("The passwords don't match")
else:
try:
cursor.execute(f"""
INSERT INTO `Customer`
(`first_name`, `last_name`, `username`, `password`, `email`, `address`)
VALUE
('{first_name}', '{last_name}', '{username}', '{password}', '{email}', '{address}');
""")
except pymysql.err.IntegrityError:
flash("Username/Email is already in use")
else:
return redirect("/signin")
finally:
cursor.close()
conn.close()
return render_template("signup.html.jinja")
@app.route("/main")
def main ():
return render_template("mainpage.html.jinja")