-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
100 lines (79 loc) · 3.3 KB
/
__init__.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
from flask import Flask, render_template, request, url_for, flash, redirect, session
from content_management import Content
from dbcon import connection
from wtforms import Form, BooleanField, TextField, PasswordField, validators
from passlib.hash import sha256_crypt
from MySQLdb import escape_string as thwart
import gc
TOPIC_DICT = Content()
app = Flask(__name__)
@app.route('/')
def homepage():
return render_template("main.html")
@app.route('/dashboard/')
def dashboard():
return render_template("dashboard.html", TOPIC_DICT = TOPIC_DICT)
@app.route('/login/', methods=["GET","POST"])
def login_page():
error = ''
try:
if request.method == "POST":
attempted_username = request.form['username']
attempted_password = request.form['password']
#flash(attempted_username)
#flash(attempted_password)
if attempted_username == "admin" and attempted_password == "password":
return redirect(url_for('dashboard'))
else:
error = "Invalid credentials. Try Again."
return render_template("login.html", error = error)
except Exception as e:
#flash(e)
return render_template("login.html", error = error)
class RegistrationForm(Form):
username = TextField('Username', [validators.Length(min=4, max=20)])
email = TextField('Email Address', [validators.Length(min=6, max=50)])
password = PasswordField('New Password', [
validators.Required(),
validators.EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
accept_tos = BooleanField('I accept the Terms of Service and Privacy Notice (updated Jan 22, 2016)', [validators.Required()])
@app.route('/register/', methods=["GET","POST"])
def register_page():
try:
form = RegistrationForm(request.form)
if request.method == "POST" and form.validate():
username = form.username.data
email = form.email.data
password = sha256_crypt.encrypt((str(form.password.data)))
c, conn = connection()
x = c.execute("SELECT * FROM users WHERE username = (%s)", (thwart(username)))
if int(x) > 0:
# flash("existed....")
return render_template('register.html', form=form)
else:
c.execute("INSERT INTO users (username, password, email, tracking) VALUES (%s, %s, %s, %s)",
(thwart(username), thwart(password), thwart(email), thwart("/introduction-to-python-programming/")))
conn.commit()
# flash("Thx")
c.close()
conn.close()
gc.collect()
session['logged_in'] = True
session['username'] = username
return redirect(url_for('dashboard'))
return render_template("register.html", form=form)
except Exception as e:
return (str(e))
@app.errorhandler(404)
def page_not_found(e):
return render_template("404.html")
# @app.route('/slashboard/')
# def slashboard():
# try:
# return render_template("dashboard.html", TOPIC_DICT=shadowfiend)
# except Exception as e:
# return render_template("500.html", error=e)
if __name__ == "__main__":
app.run(debug=True)