forked from rDrama/rDrama
Turn login-gate of 1568ec0162
into admin toggle.
parent
846a7f4537
commit
2845e0961b
|
@ -80,7 +80,9 @@ mail = Mail(app)
|
|||
|
||||
if not path.isfile(f'/site_settings.json'):
|
||||
with open('/site_settings.json', 'w', encoding='utf_8') as f:
|
||||
f.write('{"Bots": true, "Fart mode": false, "Read-only mode": false, "Signups": true}')
|
||||
f.write(
|
||||
'{"Bots": true, "Fart mode": false, "Read-only mode": false, ' + \
|
||||
'"Signups": true, "login_required": false}')
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
|
|
|
@ -193,6 +193,11 @@ ACTIONTYPES = {
|
|||
"icon": 'fa-users',
|
||||
"color": 'bg-danger'
|
||||
},
|
||||
'disable_login_required': {
|
||||
"str": 'disabled Login Required',
|
||||
"icon": 'fa-users',
|
||||
"color": 'bg-danger'
|
||||
},
|
||||
'disable_under_attack': {
|
||||
"str": 'disabled under attack mode',
|
||||
"icon": 'fa-shield',
|
||||
|
@ -243,6 +248,11 @@ ACTIONTYPES = {
|
|||
"icon": 'fa-users',
|
||||
"color": 'bg-success'
|
||||
},
|
||||
'enable_login_required': {
|
||||
"str": 'enabled Login Required',
|
||||
"icon": 'fa-users',
|
||||
"color": 'bg-success'
|
||||
},
|
||||
'enable_under_attack': {
|
||||
"str": 'enabled under attack mode',
|
||||
"icon": 'fa-shield',
|
||||
|
|
|
@ -91,7 +91,6 @@ def check_ban_evade(v):
|
|||
|
||||
def auth_desired(f):
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
v = get_logged_in_user()
|
||||
|
||||
check_ban_evade(v)
|
||||
|
@ -101,9 +100,19 @@ def auth_desired(f):
|
|||
wrapper.__name__ = f.__name__
|
||||
return wrapper
|
||||
|
||||
def auth_desired_with_logingate(f):
|
||||
def wrapper(*args, **kwargs):
|
||||
v = get_logged_in_user()
|
||||
if app.config['SETTINGS']['login_required'] and not v: abort(401)
|
||||
|
||||
check_ban_evade(v)
|
||||
|
||||
return make_response(f(*args, v=v, **kwargs))
|
||||
|
||||
wrapper.__name__ = f.__name__
|
||||
return wrapper
|
||||
|
||||
def auth_required(f):
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
v = get_logged_in_user()
|
||||
if not v: abort(401)
|
||||
|
|
|
@ -34,7 +34,7 @@ WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"}
|
|||
@app.get("/logged_out/post/<pid>/<anything>/<cid>")
|
||||
@app.get("/logged_out/h/<sub>/comment/<cid>")
|
||||
@app.get("/logged_out/h/<sub>/post/<pid>/<anything>/<cid>")
|
||||
@auth_required
|
||||
@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")
|
||||
|
|
|
@ -16,7 +16,7 @@ from files.helpers.awards import award_timers
|
|||
@app.get("/logged_out/h/<sub>")
|
||||
@app.get("/logged_out/s/<sub>")
|
||||
@limiter.limit("3/second;30/minute;5000/hour;10000/day")
|
||||
@auth_required
|
||||
@auth_desired_with_logingate
|
||||
def front_all(v, sub=None, subdomain=None):
|
||||
|
||||
if not v and not request.path.startswith('/logged_out'):
|
||||
|
|
|
@ -103,7 +103,7 @@ def submit_get(v, sub=None):
|
|||
@app.get("/logged_out/post/<pid>/<anything>")
|
||||
@app.get("/logged_out/h/<sub>/post/<pid>")
|
||||
@app.get("/logged_out/h/<sub>/post/<pid>/<anything>")
|
||||
@auth_required
|
||||
@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}")
|
||||
|
@ -233,7 +233,7 @@ def post_id(pid, anything=None, v=None, sub=None):
|
|||
|
||||
@app.get("/viewmore/<pid>/<sort>/<offset>")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
@auth_desired_with_logingate
|
||||
def viewmore(v, pid, sort, offset):
|
||||
try: pid = int(pid)
|
||||
except: abort(400)
|
||||
|
@ -324,7 +324,7 @@ def viewmore(v, pid, sort, offset):
|
|||
|
||||
@app.get("/morecomments/<cid>")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
@auth_desired_with_logingate
|
||||
def morecomments(v, cid):
|
||||
try: cid = int(cid)
|
||||
except: abort(400)
|
||||
|
|
|
@ -433,7 +433,7 @@ def sub_sidebar(v, sub):
|
|||
return redirect(f'/h/{sub.name}/settings')
|
||||
|
||||
@app.get("/holes")
|
||||
@auth_required
|
||||
@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()
|
||||
return render_template('sub/subs.html', v=v, subs=subs)
|
||||
|
|
|
@ -894,7 +894,7 @@ def visitors(v):
|
|||
@app.get("/@<username>")
|
||||
@app.get("/@<username>.json")
|
||||
@app.get("/logged_out/@<username>")
|
||||
@auth_required
|
||||
@auth_desired_with_logingate
|
||||
def u_username(username, v=None):
|
||||
|
||||
if not v and not request.path.startswith('/logged_out'):
|
||||
|
@ -1006,7 +1006,7 @@ def u_username(username, v=None):
|
|||
@app.get("/@<username>/comments")
|
||||
@app.get("/@<username>/comments.json")
|
||||
@app.get("/logged_out/@<username>/comments")
|
||||
@auth_required
|
||||
@auth_desired_with_logingate
|
||||
def u_username_comments(username, v=None):
|
||||
|
||||
if not v and not request.path.startswith('/logged_out'):
|
||||
|
|
|
@ -84,6 +84,11 @@
|
|||
<label class="custom-control-label" for="signups">Signups</label>
|
||||
</div>
|
||||
|
||||
<div class="custom-control custom-switch">
|
||||
<input autocomplete="off" type="checkbox" class="custom-control-input" id="login_required" {% if site_settings['login_required'] %}checked{% endif %} onchange="post_toast(this,'/admin/site_settings/login_required');">
|
||||
<label class="custom-control-label" for="login_required">Login Required</label>
|
||||
</div>
|
||||
|
||||
<div class="custom-control custom-switch">
|
||||
<input autocomplete="off" type="checkbox" class="custom-control-input" id="bots" {% if site_settings['Bots'] %}checked{% endif %} onchange="post_toast(this,'/admin/site_settings/Bots');">
|
||||
<label class="custom-control-label" for="bots">Bots</label>
|
||||
|
|
Loading…
Reference in New Issue