-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
101 lines (89 loc) · 3.55 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
from flask import Flask, render_template, request, session, redirect
from backend import member_data, post_data, comments_data
app=Flask(__name__)
@app.route('/')
@app.route('/home',methods=["GET","POST"])
def home():
#Track whether the user has logged in
if 'logged' not in session:
session['logged']=False
if 'post_til' not in session:
session['post_til']=10
if 'in_comments' not in session:
session['in_comments']=False
if 'comment_index' not in session:
session['comment_index']=0
if request.method=="POST":
post_data.addPost(request.form['story'],request.form['title'],session['username'])
post=post_data.showPosts();
post.reverse();
return render_template('home.html',s=session,posts=post)
@app.route('/make_comment',methods=["GET","POST"])
def make_the_goddamn_comment():
if request.method=="POST":
theUname = int(post_data.findhuman(session['username']))
thepostnum = int(session['post_id'])
thecomment = request.form['thecomment']
comments_data.addcomment(theUname,thepostnum,thecomment)
session['comments']=comments_data.findPost(session['post_id'])
return redirect("/")
@app.route('/rm_post',methods=["GET","POST"])
def rm_this_post():
if request.method=="POST":
the_post_id = request.form['post_id']
post_data.removePost(int(the_post_id))
return redirect("/home")
@app.route('/add_more_posts/')
def add_up():
session['post_til']+=10
return redirect("/home")
@app.route('/remove_more_posts')
def go_back():
session['post_til']-=10
return redirect("/home")
@app.route('/set_comment_off')
def set_comment_off():
session['in_comments']=False
return redirect("/home")
@app.route('/login',methods=["GET","POST"])
def login():
if 'logged' not in session:
session['logged']=False
#If the user is trying to log in, verify password
if request.method=="POST":
if (request.form['button']=="New Account"):
if (member_data.filterUname(request.form['username'])):
member_data.addMember(request.form['username'], request.form['password'])
session['logged']=True
session['username']=request.form['username']
return redirect('/')
else:
return render_template('login.html',s=session,error="Username already taken")
if (request.form['button']=="login"):
if member_data.checkPass(request.form['username'], request.form['password']):
session['logged']=True
session['username']=request.form['username']
return redirect('/')
else:
return render_template('login.html',s=session,error="Incorrect Username/Password")
return render_template('login.html',s=session)
#When a user clicks a button to logout, direct them here, log them out and redirect them
@app.route('/logout')
def logout():
session['logged'] = False
return redirect('/login')
@app.route("/comments",methods=["GET","POST"])
def comment():
if (session['logged']!=True):
return redirect('/login')
session['in_comments']=True
session['comments']=comments_data.findPost(int(request.form['post_id']))
print session['comments']
session['post_id']=int(request.form['post_id'])
session['comment_name']=request.form['comment_name']
session['comment_text']=request.form['comment_text']
return redirect('/')
if __name__=="__main__":
app.debug = True
app.secret_key="Don't tell anyone!"
app.run('0.0.0.0', port=8000)