From 00a3b645ff7b2d867188313e362be4804d01e545 Mon Sep 17 00:00:00 2001 From: bug_creator Date: Wed, 1 Dec 2021 17:32:21 +0800 Subject: [PATCH 1/2] fix bug|test register --- app/auth/views.py | 16 +- app/templates/auth/login-and-register.html | 180 ++++++++++++++++++++- data-dev.sqlite | Bin 6885376 -> 6885376 bytes 3 files changed, 183 insertions(+), 13 deletions(-) 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/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 %} + + {% else %} +
+ {% endif %} + {% endwith %}
diff --git a/data-dev.sqlite b/data-dev.sqlite index 87502db27ad9658499260c548e71206aa8b37da0..fb1763eebf65cbf73618a47b178c8eacdf9da9eb 100644 GIT binary patch delta 1106 zcmZ|NUuYCZ90%~7-Q;dJ?)|aG#A<9}o2JH^yP3J&+1=CHoPTTeQnhOQ@9o}Z)TF=(lLEPN&c3&V0JYOi4TRNnOE zRW*x>Uo>$(_%4(@KYZHfw#aiqF*<3bpPd=xyZfy2<^EHHXFDmCjvG3%?1v7weMo$x7i!Dp}*x?vrB4(p)@GLQud3^?S# z0=qstCw8jZd9}9|pBGP6wHLQML~5n`BAtHwJ6|8K+!@0xIN*W@dDs9O;S1OVUqUYw zU^8rit*{NY!w&cgcEZ=N3wA>h`rsSb1AAc~d<*;G033vVI0T2`2polDa2!s+NhpC2 S0hA$x0g!O2Ub=sJviK4`Zjo64 delta 673 zcmW;GJ4{mn6vpxUXu00@K5Eq#p$hn@_$mdpA}SP75w%#~Z!Od-G_fgzI+z$r9J-hk z(lkw+7%;}o<_0=6jZHTb2NR;Piwtfi?u`C%_$}w0@0^oeT#~bxZx@RTff2D-PQ0BJ z1^e%;ztdrg%7sOYmqTY z&Pa)pQje^0=apEBHX@$fOe2Eh=*I~R;3Q7rGzKw*D28zcBRGq5IFC_Wz!)y#5-uZ# vaa=(hS8)y3aRWDT3%79xcX1E*@c<9;2#=A#1SXNh6IghPsme@adOr3KEAT9z From 07ac510c7fa339da0c60650aa0aa7250242be2f4 Mon Sep 17 00:00:00 2001 From: bug_creator Date: Wed, 1 Dec 2021 18:39:16 +0800 Subject: [PATCH 2/2] ajax follow --- app/main/views.py | 17 ++++++ app/templates/post.html | 131 ++++++++++++++++++++++++++++++++-------- app/templates/user.html | 51 +++++++++++++--- data-dev.sqlite | Bin 6885376 -> 6885376 bytes 4 files changed, 166 insertions(+), 33 deletions(-) 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/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 @@
- {% if not current_user.is_liking(post) %} - - - - - -
{{ post.liker.count() }} likes
-
- {% else %} - +{# {% if not current_user.is_liking(post) %}#} +{# #} +{# #} +{# #} +{# #} +{# #} +{#
{{ post.liker.count() }} likes
#} +{#
#} +{# {% else %}#} +{# #} +{# #} +{# #} +{# #} +{# #} +{#
{{ post.liker.count() }} likes
#} +{#
#} +{# {% endif %}#} + - - + + -
{{ post.liker.count() }} likes
-
- {% endif %} +
{{ post.liker.count() }} likes
+ Follow - {% else %} - Followed - {% endif %} +{# {% if not current_user.is_following(user) %}#} +{# Follow#} +{# {% else %}#} +{# Followed#} +{# {% endif %}#} + {% if not current_user.is_following(user) %}Follow{% else %}Unfollow{% endif %} {% endif %}
  • diff --git a/data-dev.sqlite b/data-dev.sqlite index fb1763eebf65cbf73618a47b178c8eacdf9da9eb..fb6d3c5105b54cf7dfadc1ead853915c9fd5b47c 100644 GIT binary patch delta 2623 zcmai#TWl0n7{||p8{VLxB1wHQgv3a+ z+n0~%lh~N$h1drIZ={IrDz#Xtm&8Q-88!M?jSnV1(DUhZ+;S$5}2&m9uRUv<_5hf%A@Z%TVe9GyhBdl)6w%wQ)336PL1u zZ)J|$kX;%hzi67w&@A9Tn(*i$k z@-@X1i(G~!TLwXKYLV|wHJNkF{Kx#&{L@^RXfu8^dA#(8X}pmw>+}q+v;y08g&xhH z*>G}H8bkxpNHh`6M2v_N38IBa5-FmUNE0T}M%+fMAliuzqLa9txP!QpxQkdxtRlLI zyNP><)kLN=DzmS@-JfZmW#)NvuW6(w(}&aP)~VKGt(nw!sW(&WlfNg=B=;xVTfT33 zr=>r!n7Euco)GcB;^*Rr;$5*{V(-WH#Ny4f^ioeWCwfPACfNFo?W}m}yzVTHpEb;E z#QtgJIY#fujykR#Se_R+wkCIb9ajq4Cncp%ZhuYJ%emB7`LwO%_SJKJOA8sO@_Kvg zx!SUYCmoO6o;og#sn*&L%4^8ibA_d)?TPZUb=P!V8ZXQDT|X$h+iJQpr6iQZHC;a^Jj=7CyYzm&dakr=M+(QLzPg@EGf91yX5Fpn(oA|*AOd@7ew~}$RiXb- zCE^^dZD(M_E?$|=_N)knl~6(tjHqSTX(39vZZI$+tJj5>lhV?@69_RdB9^X~14=A~ zp0B0w?32f)v&0%=Epacgj<}ClPi!DI6894i5DyZY2#a`#5QHQYVV90gJ8!9QVwPj| zH87uCZ(PP6##$bG&&+su`;DbERGn|?8=8QRJ z7R*62Z)QxEo=?xD$I^xLU^;(&+u5h98*V;6RCTKveIn|iv8n!kIP~ssG!Q=fB%%S` zpfVq<6kV^(1e=VghvtAyT(1v@55Vx|vyX3WP&u&5Gr%rI*DJHYKDxCYo(XnwslIC2 z2^<~{HeSkK)$@r)#*9qyH-~qWPCGnq4By(fa&VV}pM4WquZBJQIFi>biI<&!)zu(2t_mdJfa?oV|FF7UX5Tj9Z|m#yM2m% z7A;h=mQ6+0tNF?<18P7I&<6|vbAX!xw*YPh+y>YUm;>!t><8QqxC3w};4Z-3 zfDZ#c0{AH49>BeTj{yzt0iObV8t@sw{eaH`J_qcb_2*%?}v70Fq%@ygcN4nQ%g`;*; zHX(jhrfRjaB}e)&Vbldt7Nd0lqOS{X2Zn(xhN zbHW@kyUnOsVk{e9jTz&aF>3S~O-6azKj%zhM~`q5^Uh+Sn~I1<53xfWC2k;&5yy%5 z5bq`4N8Cu