minor auth_desired refactor

remotes/1693045480750635534/spooky-22
Aevann1 2022-09-20 02:51:01 +02:00
parent 696423d174
commit 7d39cdb520
7 changed files with 14 additions and 47 deletions

View File

@ -112,6 +112,14 @@ def auth_desired_with_logingate(f):
v = get_logged_in_user()
if app.config['SETTINGS']['login_required'] and not v: abort(401)
if not v and not request.path.startswith('/logged_out'):
return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'):
redir = request.full_path.replace('/logged_out','')
if not redir: redir = '/'
return redirect(redir)
check_ban_evade(v)
return make_response(f(*args, v=v, **kwargs))

View File

@ -34,9 +34,6 @@ WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"}
@auth_desired_with_logingate
def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}#context")
if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','') + '#context')
try: cid = int(cid)
except: abort(404)

View File

@ -19,14 +19,6 @@ from files.helpers.awards import award_timers
@auth_desired_with_logingate
def front_all(v, sub=None, subdomain=None):
if not v and not request.path.startswith('/logged_out'):
return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'):
redir = request.full_path.replace('/logged_out','')
if not redir.startswith('/'): redir = f'/{redir}'
return redirect(redir)
if sub:
sub = sub.strip().lower()
if sub == 'chudrama' and not (v and v.can_see_chudrama): abort(403)

View File

@ -106,9 +106,6 @@ def submit_get(v, sub=None):
@auth_desired_with_logingate
def post_id(pid, anything=None, v=None, sub=None):
if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out',''))
try: pid = int(pid)
except Exception as e: pass

View File

@ -71,11 +71,8 @@ def marsey_list():
@app.get('/sidebar')
@app.get('/logged_out/rules')
@app.get('/logged_out/sidebar')
@auth_desired
@auth_desired_with_logingate
def sidebar(v):
if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out',''))
return render_template('sidebar.html', v=v)
@ -184,7 +181,8 @@ def log_item(id, v):
return render_template("log.html", v=v, actions=[action], next_exists=False, page=1, action=action, admins=admins, types=types)
@app.get("/directory")
@auth_desired
@app.get("/logged_out/directory")
@auth_desired_with_logingate
def static_megathread_index(v):
return render_template("megathread_index.html", v=v)
@ -425,26 +423,12 @@ def transfers(v):
else:
return render_template("transfers.html", v=v, page=page, comments=comments, standalone=True, next_exists=next_exists)
@app.get("/kb/<page>")
@auth_desired
def knowledgebase(v, page):
if not knowledgebase_page_regex.fullmatch(page):
abort(404)
template_path = f'kb/{SITE_NAME}/{page}.html'
if not os.path.exists('files/templates/' + template_path):
abort(404)
return render_template(template_path, v=v)
if not os.path.exists(f'files/templates/donate_{SITE_NAME}.html'):
copyfile(f'files/templates/donate_rDrama.html', f'files/templates/donate_{SITE_NAME}.html')
@app.get('/donate')
@auth_desired
@app.get("/logged_out/donate")
@auth_desired_with_logingate
def donate(v):
if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out',''))
return render_template(f'donate_{SITE_NAME}.html', v=v)

View File

@ -501,6 +501,7 @@ def sub_marsey(v, sub):
return redirect(f'/h/{sub}/settings')
@app.get("/holes")
@app.get("/logged_out/holes")
@auth_desired_with_logingate
def subs(v):
subs = g.db.query(Sub, func.count(Submission.sub)).outerjoin(Submission, Sub.name == Submission.sub).group_by(Sub.name).order_by(func.count(Submission.sub).desc()).all()

View File

@ -935,12 +935,6 @@ def visitors(v):
@auth_desired_with_logingate
def u_username(username, v=None):
if not v and not request.path.startswith('/logged_out'):
return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'):
return redirect(request.full_path.replace('/logged_out',''))
u = get_user(username, v=v, rendered=True)
if v and username == v.username:
@ -1042,12 +1036,6 @@ def u_username(username, v=None):
@auth_desired_with_logingate
def u_username_comments(username, v=None):
if not v and not request.path.startswith('/logged_out'):
return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'):
return redirect(request.full_path.replace('/logged_out',''))
user = get_user(username, v=v, rendered=True)
if v and username == v.username: