diff --git a/app/auth/views.py b/app/auth/views.py index 0b687e7..730c646 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -35,17 +35,17 @@ def login(): user = User.query.filter_by(student_id=student_id).first() if user is None: flash("Your StudentID/OrganizationID has not been registered") - return render_template('auth/login.html') + return redirect(url_for('auth.login')) elif user.verify_password(password) is False: flash("StudentID/OrganizationID or password error") - return render_template('auth/login.html') + return redirect(url_for('auth.login')) if user is not None and user.verify_password(password): login_user(user, True) next = request.args.get('next') if next is None or not next.startswith('/'): next = url_for('main.index') return redirect(next) - return render_template('auth/login.html') + return redirect(url_for('auth.login')) # # 登录 @@ -112,23 +112,23 @@ def register(): is_student = Students.query.filter_by(student_id=request.form["BJUT_id"]).first() # 学号 if is_student is None: flash("Sorry, you are not a BJUT student and cannot sign up for this account.") - return render_template('auth/register.html') + return redirect(url_for('auth.login')) if is_student.id_number != request.form["id_num"]: flash("Your student ID does not match your ID number, you cannot register for this account.") - return render_template('auth/register.html') + return redirect(url_for('auth.login')) if is_student is not None and is_student.id_number == request.form["id_num"]: if is_student.confirmed: flash("Your student number has been registered, you cannot register for a second SOFB account") - return render_template('auth/register.html') + return redirect(url_for('auth.login')) else: email_find = User.query.filter_by(email=request.form["email"]).first() if email_find is not None: flash("Your email has been registered, please change your email") - return render_template('auth/register.html') + return redirect(url_for('auth.login')) username_find = User.query.filter_by(username=request.form["user_name"]).first() if username_find is not None: flash("Your username has been registered, please change your username") - return render_template('auth/register.html') + return redirect(url_for('auth.login')) student = Students.query.filter_by(student_id=request.form["BJUT_id"]).first() user = User(email=request.form["email"], ID_number=request.form["id_num"], diff --git a/app/main/views.py b/app/main/views.py index fd0a298..3933b26 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -684,6 +684,23 @@ def follow(username): flash('You are now following %s.' % username) return redirect(url_for('.user', username=username)) +@main.route('/AJAXfollow/', methods=['POST'], strict_slashes=False) +@csrf.exempt +@permission_required(Permission.FOLLOW) +def AJAXfollow(username): + if current_user is None: + return redirect(url_for("/")) + user = User.query.filter_by(username=username).first() + if user is not None: + if current_user.is_following(user): + current_user.unfollow(user) + db.session.commit() + return jsonify({'code': 200, 'like': False}) + else: + current_user.follow(user) + db.session.commit() + return jsonify({'code': 200, 'like': True}) + @main.route('/unfollow/') @login_required diff --git a/app/templates/auth/login-and-register.html b/app/templates/auth/login-and-register.html index d9e113d..6613ca9 100644 --- a/app/templates/auth/login-and-register.html +++ b/app/templates/auth/login-and-register.html @@ -25,9 +25,20 @@ {% block body %}
+ {% with messages =get_flashed_messages() %} + {% if messages %} +
    + {% for message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% else %} +
+ {% endif %} + {% endwith %}
diff --git a/app/templates/post.html b/app/templates/post.html index 2af7903..847d528 100644 --- a/app/templates/post.html +++ b/app/templates/post.html @@ -202,15 +202,52 @@  {{ post.author.college }}
{% if current_user.can(Permission.FOLLOW) and post.author != current_user %} - {% if not current_user.is_following(post.author) %} - Follow - {% else %} - Unfollow - {% endif %} +{# {% if not current_user.is_following(post.author) %}#} +{# Follow#} +{# {% else %}#} +{# Unfollow#} +{# {% endif %}#} + {% if not current_user.is_following(post.author) %}Follow{% else %}Unfollow{% endif %} {% endif %}
{% endif %} @@ -265,25 +302,67 @@