|
|
@@ -1,11 +1,11 @@
|
|
|
# Site Back-End Logic
|
|
|
from hmac import new
|
|
|
-import string, secrets
|
|
|
from flask import Blueprint, render_template, request, flash, redirect, url_for
|
|
|
from flask_login import login_user, login_required, logout_user, current_user
|
|
|
from werkzeug.security import generate_password_hash, check_password_hash
|
|
|
from .models import User, Message
|
|
|
from . import db
|
|
|
+import string, secrets
|
|
|
|
|
|
logic = Blueprint('logic', __name__)
|
|
|
|
|
|
@@ -49,13 +49,38 @@ def profile():
|
|
|
|
|
|
return render_template("profile.html", user=current_user)
|
|
|
|
|
|
+recipient_id = None
|
|
|
|
|
|
@logic.route('/matchbook', methods=['GET', 'POST'])
|
|
|
@login_required
|
|
|
def matchbook():
|
|
|
all_users = User.query.all()
|
|
|
+
|
|
|
+ if request.method == 'POST':
|
|
|
+ global recipient_id
|
|
|
+ recipient_id = request.form.get('message_recipient')
|
|
|
+ return redirect(url_for('logic.messaging'))
|
|
|
+
|
|
|
return render_template("matchbook.html", user=current_user, userlist=all_users)
|
|
|
|
|
|
+@logic.route('/messaging', methods=['GET', 'POST'])
|
|
|
+@login_required
|
|
|
+def messaging():
|
|
|
+ recipient = User.query.filter_by(id=recipient_id).first()
|
|
|
+
|
|
|
+ sent_history = Message.query.filter_by(sender=current_user.id, recipient=recipient.id).all()
|
|
|
+ recv_history = Message.query.filter_by(sender=recipient.id, recipient=current_user.id).all()
|
|
|
+ joint_history = sent_history + recv_history
|
|
|
+ joint_history.sort(key=lambda x: x.id) # add reverse=True for descending
|
|
|
+ ## add filter to remove duplicate messages to self?
|
|
|
+ if request.method == 'POST':
|
|
|
+ message = request.form.get('message_box')
|
|
|
+ new_msg_dbcall = Message(sender=current_user.id, recipient=recipient.id, message=message)
|
|
|
+ db.session.add(new_msg_dbcall)
|
|
|
+ db.session.commit()
|
|
|
+
|
|
|
+ return render_template("messaging.html", user=current_user, recipient=recipient, msg_hist=joint_history)
|
|
|
+
|
|
|
|
|
|
@logic.route('/login', methods=['GET', 'POST'])
|
|
|
def login():
|