remotes/1693045480750635534/spooky-22
Aevann1 2021-09-16 19:02:58 +02:00
parent a205f626a2
commit 88ca2d6206
14 changed files with 160 additions and 6 deletions

View File

@ -159,8 +159,6 @@ def before_request():
@app.teardown_appcontext
def teardown_request(error):
if hasattr(g, 'db') and g.db:
try: g.db.commit()
except: g.db.rollback()
g.db.close()
@app.after_request

View File

@ -489,6 +489,8 @@ class User(Base, Stndrd, Age_times):
self.unban_utc = 0
g.db.add(self)
g.db.commit()
@property
def is_suspended(self):

View File

@ -42,6 +42,7 @@ def revert_actions(v, username):
for user in users:
user.unban()
g.db.commit()
return {"message": "Admin actions reverted!"}
@app.post("/@<username>/club_allow")
@ -63,6 +64,7 @@ def club_allow(v, username):
x.club_banned = False
g.db.add(x)
g.db.commit()
return {"message": f"@{username} has been allowed into the country club!"}
@app.post("/@<username>/club_ban")
@ -83,6 +85,7 @@ def club_ban(v, username):
u.club_allowed = False
g.db.add(x)
g.db.commit()
return {"message": f"@{username} has been kicked from the country club. Deserved."}
@ -94,6 +97,7 @@ def make_admin(v, username):
if not user: abort(404)
user.admin_level = 6
g.db.add(user)
g.db.commit()
return {"message": "User has been made admin!"}
@ -105,6 +109,7 @@ def remove_admin(v, username):
if not user: abort(404)
user.admin_level = 0
g.db.add(user)
g.db.commit()
return {"message": "Admin removed!"}
@ -116,6 +121,7 @@ def make_fake_admin(v, username):
if not user: abort(404)
user.admin_level = 1
g.db.add(user)
g.db.commit()
return {"message": "User has been made fake admin!"}
@ -127,6 +133,7 @@ def remove_fake_admin(v, username):
if not user: abort(404)
user.admin_level = 0
g.db.add(user)
g.db.commit()
return {"message": "Fake admin removed!"}
@ -180,6 +187,7 @@ def monthly(v):
g.db.bulk_save_objects(_awards)
g.db.commit()
return {"message": "Monthly awards granted"}
@ -428,6 +436,7 @@ def badge_grant_post(v):
g.db.add(user)
g.db.commit()
return redirect("/admin/badge_grant")
@ -578,6 +587,7 @@ def admin_link_accounts(v):
g.db.add(new_alt)
g.db.commit()
return redirect(f"/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).get(u2).username}")
@ -670,6 +680,7 @@ def admin_image_ban(v):
g.db.add(new_bp)
g.db.commit()
return render_template("admin/image_ban.html", v=v, success=True)
@ -722,6 +733,7 @@ def agendaposter(user_id, v):
if user.agendaposter: send_notification(NOTIFICATIONS_ACCOUNT, user, f"You have been marked by an admin as an agendaposter ({note}).")
else: send_notification(NOTIFICATIONS_ACCOUNT, user, f"You have been unmarked by an admin as an agendaposter.")
g.db.commit()
if user.agendaposter: return (redirect(user.url), user)
return {"message": "Agendaposter theme disabled!"}
@ -746,6 +758,7 @@ def shadowban(user_id, v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "User shadowbanned!"}
@ -770,6 +783,7 @@ def unshadowban(user_id, v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "User unshadowbanned!"}
@app.post("/admin/verify/<user_id>")
@ -779,6 +793,7 @@ def verify(user_id, v):
user = g.db.query(User).filter_by(id=user_id).first()
user.verified = "Verified"
g.db.add(user)
g.db.commit()
return {"message": "User verfied!"}
@app.post("/admin/unverify/<user_id>")
@ -788,6 +803,7 @@ def unverify(user_id, v):
user = g.db.query(User).filter_by(id=user_id).first()
user.verified = None
g.db.add(user)
g.db.commit()
return {"message": "User unverified!"}
@ -821,6 +837,7 @@ def admin_title_change(user_id, v):
)
g.db.add(ma)
g.db.commit()
return (redirect(user.url), user)
@app.post("/ban_user/<user_id>")
@ -874,6 +891,8 @@ def ban_user(user_id, v):
)
g.db.add(ma)
g.db.commit()
if 'reason' in request.args:
if reason.startswith("/post/"):
post = reason.split("/post/")[1].split("/")[0]
@ -916,6 +935,8 @@ def unban_user(user_id, v):
)
g.db.add(ma)
g.db.commit()
if "@" in request.referrer:
return redirect(user.url)
else:
@ -957,6 +978,8 @@ def ban_post(post_id, v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "Post removed!"}
@ -985,6 +1008,8 @@ def unban_post(post_id, v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "Post approved!"}
@ -1008,6 +1033,8 @@ def api_distinguish_post(post_id, v):
g.db.add(post)
g.db.commit()
return {"message": "Post distinguished!"}
@ -1029,7 +1056,7 @@ def api_sticky_post(post_id, v):
cache.delete_memoized(frontlist)
g.db.flush()
g.db.commit()
if post.stickied: return {"message": "Post pinned!"}
else: return {"message": "Post unpinned!"}
@ -1041,7 +1068,7 @@ def api_pin_post(post_id, v):
if post:
post.is_pinned = not (post.is_pinned)
g.db.add(post)
g.db.flush()
g.db.commit()
if post.is_pinned: return {"message": "Post pinned!"}
else: return {"message": "Post unpinned!"}
@ -1065,6 +1092,7 @@ def api_ban_comment(c_id, v):
target_comment_id=comment.id,
)
g.db.add(ma)
g.db.commit()
return {"message": "Comment removed!"}
@ -1088,6 +1116,7 @@ def api_unban_comment(c_id, v):
comment.is_banned = False
comment.is_approved = v.id
g.db.commit()
return {"message": "Comment approved!"}
@ -1115,6 +1144,8 @@ def admin_distinguish_comment(c_id, v):
html=str(BeautifulSoup(html, features="html.parser").find(id=f"comment-{comment.id}-only"))
g.db.commit()
return html
@app.get("/admin/dump_cache")
@ -1146,6 +1177,9 @@ def admin_toggle_ban_domain(v):
else:
d = BannedDomain(domain=domain, reason=reason)
g.db.add(d)
g.db.commit()
return redirect("/admin/banned_domains/")
@ -1177,6 +1211,8 @@ def admin_nuke_user(v):
)
g.db.add(ma)
g.db.commit()
return redirect(user.url)
@app.post("/admin/unnuke_user")
@ -1207,6 +1243,8 @@ def admin_nunuke_user(v):
)
g.db.add(ma)
g.db.commit()
return redirect(user.url)
@app.get("/chart")

View File

@ -151,6 +151,8 @@ def buy(v, award):
award = AwardRelationship(id=thing, user_id=v.id, kind=award)
g.db.add(award)
g.db.commit()
return {"message": "Award bought!"}
@ -373,4 +375,6 @@ def admin_userawards_post(v):
send_notification(NOTIFICATIONS_ACCOUNT, u, text)
g.db.commit()
return render_template("admin/user_award.html", awards=list(AWARDS.values()), v=v)

View File

@ -584,6 +584,8 @@ def api_comment(v):
parent_post.comment_count = g.db.query(Comment).filter_by(parent_submission=parent_post.id).count()
g.db.add(parent_post)
g.db.commit()
if request.headers.get("Authorization"): return c.json
else: return jsonify({"html": render_template("comments.html",
v=v,
@ -807,6 +809,8 @@ def edit_comment(cid, v):
n = Notification(comment_id=c.id, user_id=x)
g.db.add(n)
g.db.commit()
return jsonify({"html": c.body_html})
@ -829,6 +833,8 @@ def delete_comment(cid, v):
cache.delete_memoized(comment_idlist)
g.db.commit()
return {"message": "Comment deleted!"}
@app.post("/undelete/comment/<cid>")
@ -850,6 +856,8 @@ def undelete_comment(cid, v):
cache.delete_memoized(comment_idlist)
g.db.commit()
return {"message": "Comment undeleted!"}
@ -876,6 +884,8 @@ def toggle_comment_pin(cid, v):
)
g.db.add(ma)
g.db.commit()
if comment.is_pinned: return {"message": "Comment pinned!"}
else: return {"message": "Comment unpinned!"}
@ -894,6 +904,8 @@ def save_comment(cid, v):
try: g.db.flush()
except: g.db.rollback()
g.db.commit()
return {"message": "Comment saved!"}
@app.post("/unsave_comment/<cid>")
@ -907,4 +919,6 @@ def unsave_comment(cid, v):
if save: g.db.delete(save)
g.db.commit()
return {"message": "Comment unsaved!"}

View File

@ -29,7 +29,7 @@ def notifications(v):
next_exists = (len(comments) > 25)
comments = comments[:25]
elif posts:
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).all()
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all()
comments = []
for index, x in enumerate(notifications):

View File

@ -388,6 +388,8 @@ def sign_up_post(v):
session["user_id"] = new_user.id
session["session_id"] = token_hex(16)
g.db.commit()
return redirect("/")

View File

@ -32,6 +32,8 @@ def authorize(v):
g.db.add(new_auth)
g.db.commit()
return redirect(f"{application.redirect_uri}?token={access_token}")
@ -50,6 +52,8 @@ def request_api_keys(v):
send_admin(NOTIFICATIONS_ACCOUNT, f"{v.username} has requested API keys for `{request.form.get('name')}`. You can approve or deny the request [here](/admin/apps).")
g.db.commit()
return redirect('/settings/apps')
@ -66,6 +70,8 @@ def delete_oauth_app(v, aid):
g.db.delete(app)
g.db.commit()
return redirect('/apps')
@ -83,6 +89,8 @@ def edit_oauth_app(v, aid):
g.db.add(app)
g.db.commit()
return redirect('/settings/apps')
@ -106,6 +114,8 @@ def admin_app_approve(v, aid):
g.db.add(new_auth)
g.db.commit()
send_notification(NOTIFICATIONS_ACCOUNT, user, f"Your application `{app.app_name}` has been approved. Here's your access token: `{access_token}`\nPlease check the guide [here](/api) if you don't know what to do next.")
return {"message": f"{app.app_name} approved"}
@ -125,6 +135,8 @@ def admin_app_revoke(v, aid):
g.db.delete(app)
g.db.commit()
return {"message": f"App revoked"}
@ -142,6 +154,8 @@ def admin_app_reject(v, aid):
g.db.delete(app)
g.db.commit()
return {"message": f"App rejected"}
@ -222,4 +236,6 @@ def reroll_oauth_tokens(aid, v):
a.client_id = secrets.token_urlsafe(64)[:64]
g.db.add(a)
g.db.commit()
return {"message": "Client ID Rerolled", "id": a.client_id}

View File

@ -46,6 +46,8 @@ def toggle_club(pid, v):
)
g.db.add(ma)
g.db.commit()
if post.club: return {"message": "Post has been marked as +150-coins only!"}
else: return {"message": "Post has been unmarked as +150-coins only!"}
@ -61,6 +63,8 @@ def publish(pid, v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "Post published!"}
@app.get("/submit")
@ -385,6 +389,8 @@ def edit_post(pid, v):
if int(time.time()) - p.created_utc > 60 * 3: p.edited_utc = int(time.time())
g.db.add(p)
g.db.commit()
return redirect(p.permalink)
@app.get("/submit/title")
@ -1096,6 +1102,8 @@ def submit_post(v):
send_message(f"https://{site}{new_post.permalink}")
cache.delete_memoized(changeloglist)
g.db.commit()
if request.headers.get("Authorization"): return new_post.json
else: return redirect(new_post.permalink)
@ -1117,6 +1125,8 @@ def delete_post_pid(pid, v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "Post deleted!"}
@app.post("/undelete_post/<pid>")
@ -1130,6 +1140,8 @@ def undelete_post_pid(pid, v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "Post undeleted!"}
@ -1143,6 +1155,9 @@ def toggle_comment_nsfw(cid, v):
comment.over_18 = not comment.over_18
g.db.add(comment)
g.db.flush()
g.db.commit()
if comment.over_18: return {"message": "Comment has been marked as +18!"}
else: return {"message": "Comment has been unmarked as +18!"}
@ -1168,6 +1183,9 @@ def toggle_post_nsfw(pid, v):
g.db.add(ma)
g.db.flush()
g.db.commit()
if post.over_18: return {"message": "Post has been marked as +18!"}
else: return {"message": "Post has been unmarked as +18!"}
@ -1185,6 +1203,8 @@ def save_post(pid, v):
try: g.db.flush()
except: g.db.rollback()
g.db.commit()
return {"message": "Post saved!"}
@app.post("/unsave_post/<pid>")
@ -1198,4 +1218,6 @@ def unsave_post(pid, v):
if save: g.db.delete(save)
g.db.commit()
return {"message": "Post unsaved!"}

View File

@ -31,6 +31,8 @@ def api_flag_post(pid, v):
g.db.add(flag)
g.db.commit()
return {"message": "Post reported!"}
@ -59,6 +61,8 @@ def api_flag_comment(cid, v):
g.db.add(flag)
g.db.commit()
return {"message": "Comment reported!"}
@ -79,4 +83,6 @@ def remove_report(report_fn, v):
g.db.delete(report)
g.db.commit()
return {"message": "Removed report"}

View File

@ -38,6 +38,7 @@ tiers={
def removebackground(v):
v.background = None
g.db.add(v)
g.db.commit()
return {"message": "Background removed!"}
@app.post("/settings/profile")
@ -243,6 +244,7 @@ def settings_profile_post(v):
if updated:
g.db.add(v)
g.db.commit()
return {"message": "Your settings have been updated."}
@ -258,7 +260,7 @@ def changelogsub(v):
cache.delete_memoized(frontlist)
g.db.flush()
g.db.commit()
if v.changelogsub: return {"message": "You have subscribed to the changelog!"}
else: return {"message": "You have unsubscribed from the changelog!"}
@ -271,6 +273,7 @@ def namecolor(v):
if len(color) != 6: return render_template("settings_security.html", v=v, error="Invalid color code")
v.namecolor = color
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/themecolor")
@ -282,6 +285,7 @@ def themecolor(v):
if len(themecolor) != 6: return render_template("settings_security.html", v=v, error="Invalid color code")
v.themecolor = themecolor
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/gumroad")
@ -358,6 +362,8 @@ def gumroad(v):
g.db.add(new_badge)
g.db.add(v)
g.db.commit()
return {"message": f"{patron} rewards claimed!"}
@app.post("/settings/titlecolor")
@ -369,6 +375,8 @@ def titlecolor(v):
if len(titlecolor) != 6: return render_template("settings_security.html", v=v, error="Invalid color code")
v.titlecolor = titlecolor
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/security")
@ -466,6 +474,8 @@ def settings_security_post(v):
v.mfa_secret = None
g.db.add(v)
g.db.commit()
return redirect("/settings/security?msg=" +
escape("Two-factor authentication disabled."))
@ -488,6 +498,8 @@ def settings_log_out_others(v):
g.db.add(v)
g.db.commit()
return render_template("settings_security.html", v=v,
msg="All other devices have been logged out")
@ -516,6 +528,8 @@ def settings_images_profile(v):
v.profileurl = imageurl
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v, msg="Profile picture successfully updated.")
@ -535,6 +549,7 @@ def settings_images_banner(v):
if imageurl:
v.bannerurl = imageurl
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v, msg="Banner successfully updated.")
@ -556,6 +571,7 @@ def settings_delete_banner(v):
v.bannerurl = None
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v,
msg="Banner successfully removed.")
@ -588,6 +604,8 @@ def settings_css(v):
else:
v.css = 'body *::before, body *::after { content: "Trans rights are human rights!"; }'
g.db.add(v)
g.db.commit()
return render_template("settings_css.html", v=v)
@app.get("/settings/profilecss")
@ -604,6 +622,8 @@ def settings_profilecss(v):
profilecss = request.form.get("profilecss").replace('\\', '')[:50000]
v.profilecss = profilecss
g.db.add(v)
g.db.commit()
return render_template("settings_profilecss.html", v=v)
@app.post("/settings/block")
@ -639,6 +659,8 @@ def settings_block_user(v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": f"@{user.username} blocked."}
@ -664,6 +686,8 @@ def settings_unblock_user(v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": f"@{user.username} unblocked."}
@ -688,6 +712,8 @@ def settings_remove_discord(v):
v.discord_id=None
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.get("/settings/content")
@ -742,6 +768,8 @@ def settings_name_change(v):
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/song_change")
@ -822,6 +850,8 @@ def settings_song_change(v):
v.song=id
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/title_change")
@ -844,4 +874,6 @@ def settings_title_change(v):
v.customtitle = filter_title(new_name)
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")

View File

@ -156,6 +156,7 @@ def contact(v):
def submit_contact(v):
message = f'This message has been sent automatically to all admins via https://{site}/contact, user email is "{v.email}"\n\nMessage:\n\n' + request.form.get("message", "")
send_admin(v.id, message)
g.db.commit()
return render_template("contact.html", v=v, msg="Your message has been sent.")
@app.route('/archives')

View File

@ -33,6 +33,7 @@ def pay_rent(v):
u.coins += 500
g.db.add(u)
send_notification(NOTIFICATIONS_ACCOUNT, u, f"@{v.username} has paid rent!")
g.db.commit()
return {"message": "Rent paid!"}
@ -68,6 +69,7 @@ def steal(v):
g.db.add(v)
u.coins += 500
g.db.add(u)
g.db.commit()
return {"message": "Attempt failed!"}
@ -97,6 +99,7 @@ def suicide(v, username):
send_notification(NOTIFICATIONS_ACCOUNT, user, suicide)
v.suicide_utc = t
g.db.add(v)
g.db.commit()
return {"message": "Help message sent!"}
@ -132,6 +135,8 @@ def transfer_coins(v, username):
send_notification(v.id, receiver, transfer_message)
return {"message": f"{amount} {app.config['COINS_NAME']} transferred!"}, 200
g.db.commit()
return {"message": f"{app.config['COINS_NAME']} transferred!"}
@ -186,6 +191,7 @@ def song(song):
def subscribe(v, post_id):
new_sub = Subscription(user_id=v.id, submission_id=post_id)
g.db.add(new_sub)
g.db.commit()
return {"message": "Post subscribed!"}
@app.post("/unsubscribe/<post_id>")
@ -193,6 +199,7 @@ def subscribe(v, post_id):
def unsubscribe(v, post_id):
sub=g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).first()
g.db.delete(sub)
g.db.commit()
return {"message": "Post unsubscribed!"}
@app.post("/@<username>/message")
@ -232,6 +239,8 @@ def message2(v, username):
except Exception as e:
print(e)
g.db.commit()
return redirect(f"/@{username}")
@ -269,6 +278,8 @@ def messagereply(v):
notif = Notification(comment_id=new_comment.id, user_id=user.id)
g.db.add(notif)
g.db.commit()
return jsonify({"html": render_template("comments.html",
v=v,
comments=[new_comment],
@ -594,6 +605,9 @@ def follow_user(username, v):
existing = g.db.query(Notification).filter_by(followsender=v.id, user_id=target.id).first()
if not existing: send_follow_notif(v.id, target.id, f"@{v.username} has followed you!")
g.db.commit()
return {"message": "User followed!"}
@app.post("/unfollow/<username>")
@ -613,6 +627,9 @@ def unfollow_user(username, v):
existing = g.db.query(Notification).filter_by(unfollowsender=v.id, user_id=target.id).first()
if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has unfollowed you!")
g.db.commit()
return {"message": "User unfollowed!"}

View File

@ -101,6 +101,7 @@ def api_vote_post(post_id, new, v):
post.upvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=1).count()
post.downvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=-1).count()
g.db.add(post)
g.db.commit()
return "", 204
@app.post("/vote/comment/<comment_id>/<new>")
@ -155,4 +156,5 @@ def api_vote_comment(comment_id, new, v):
comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count()
comment.downvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=-1).count()
g.db.add(comment)
g.db.commit()
return "", 204