forked from hornet/wirechan
add more comments
This commit is contained in:
parent
14080bf8b2
commit
0a644cf9de
1 changed files with 11 additions and 11 deletions
22
app.py
22
app.py
|
|
@ -5,10 +5,10 @@ from bson.objectid import ObjectId
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = 'secret_key'
|
app.secret_key = 'secret_key' #change this to a random string
|
||||||
|
|
||||||
#initialize the database
|
#initialize the databases
|
||||||
client = MongoClient('localhost', 27017)
|
client = MongoClient('localhost', 27017) #change this if you are using a different host/port
|
||||||
db = client.flask_db
|
db = client.flask_db
|
||||||
posts_collection = db.posts_collection
|
posts_collection = db.posts_collection
|
||||||
users_collection = db.users_collection
|
users_collection = db.users_collection
|
||||||
|
|
@ -41,7 +41,7 @@ def board(board_name):
|
||||||
else:
|
else:
|
||||||
admin=False
|
admin=False
|
||||||
return render_template('board.html', title=board_name, header=display_name, links=links, posts=posts, admin=admin)
|
return render_template('board.html', title=board_name, header=display_name, links=links, posts=posts, admin=admin)
|
||||||
|
#posting API
|
||||||
@app.route('/post', methods=['POST'])
|
@app.route('/post', methods=['POST'])
|
||||||
def post():
|
def post():
|
||||||
board_name = request.form['board_name']
|
board_name = request.form['board_name']
|
||||||
|
|
@ -70,7 +70,7 @@ def post():
|
||||||
posts_collection.insert_one(post_data)
|
posts_collection.insert_one(post_data)
|
||||||
|
|
||||||
return redirect(url_for('board', board_name=board_name))
|
return redirect(url_for('board', board_name=board_name))
|
||||||
|
#image API
|
||||||
@app.route('/image/<post_id>')
|
@app.route('/image/<post_id>')
|
||||||
def image(post_id):
|
def image(post_id):
|
||||||
post = posts_collection.find_one({'_id': ObjectId(post_id)})
|
post = posts_collection.find_one({'_id': ObjectId(post_id)})
|
||||||
|
|
@ -82,7 +82,7 @@ def image(post_id):
|
||||||
@app.route('/login', methods=['GET'])
|
@app.route('/login', methods=['GET'])
|
||||||
def login():
|
def login():
|
||||||
return render_template('login.html')
|
return render_template('login.html')
|
||||||
|
#login API
|
||||||
@app.route('/login', methods=['POST'])
|
@app.route('/login', methods=['POST'])
|
||||||
def login_post():
|
def login_post():
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
|
|
@ -104,7 +104,7 @@ def login_post():
|
||||||
def register():
|
def register():
|
||||||
regalert = request.args.get('regalert', '')
|
regalert = request.args.get('regalert', '')
|
||||||
return render_template('register.html', regalert=regalert)
|
return render_template('register.html', regalert=regalert)
|
||||||
|
#registration API
|
||||||
@app.route('/register', methods=['POST'])
|
@app.route('/register', methods=['POST'])
|
||||||
def register_post():
|
def register_post():
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
|
|
@ -123,7 +123,7 @@ def register_post():
|
||||||
})
|
})
|
||||||
|
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
#admin dashboard
|
||||||
@app.route('/admin', methods=['GET'])
|
@app.route('/admin', methods=['GET'])
|
||||||
def admin():
|
def admin():
|
||||||
admin_user = users_collection.find_one({'username': 'admin'})
|
admin_user = users_collection.find_one({'username': 'admin'})
|
||||||
|
|
@ -138,7 +138,7 @@ def admin():
|
||||||
return render_template('admin.html', success1=success1, success2=success2, success3=success3, total_users=total_users, total_posts=total_posts, nuke_count=nuke_count, users=users)
|
return render_template('admin.html', success1=success1, success2=success2, success3=success3, total_users=total_users, total_posts=total_posts, nuke_count=nuke_count, users=users)
|
||||||
else:
|
else:
|
||||||
return url_for('index')
|
return url_for('index')
|
||||||
|
#admin functions
|
||||||
@app.route('/deletepost', methods=['POST'])
|
@app.route('/deletepost', methods=['POST'])
|
||||||
def deletepost():
|
def deletepost():
|
||||||
admin_user = users_collection.find_one({'username': 'admin'})
|
admin_user = users_collection.find_one({'username': 'admin'})
|
||||||
|
|
@ -173,13 +173,13 @@ def nukeboard():
|
||||||
nuke_counter.insert_one({'board_name': board_name}, {'date': datetime.now()})
|
nuke_counter.insert_one({'board_name': board_name}, {'date': datetime.now()})
|
||||||
return redirect(url_for('admin', success3=success))
|
return redirect(url_for('admin', success3=success))
|
||||||
|
|
||||||
|
#logout API
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
def logout():
|
def logout():
|
||||||
session.pop('user_id', None)
|
session.pop('user_id', None)
|
||||||
session.pop('username', None)
|
session.pop('username', None)
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
#start the server
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, host='100.64.0.18', port=5000)
|
app.run(debug=True, host='100.64.0.18', port=5000)
|
||||||
Loading…
Add table
Reference in a new issue