adding admin
parent
e3a3e7aa19
commit
d2092ab496
@ -1,25 +1,18 @@
|
||||
from flask import session, redirect, url_for, flash
|
||||
from flask import redirect, flash, request, url_for
|
||||
from flask_login import current_user
|
||||
from functools import wraps
|
||||
from nerochan.models import User, CreatorProfile, BackerProfile, Subscription
|
||||
from nerochan.models import User
|
||||
|
||||
|
||||
# def login_required(f):
|
||||
# @wraps(f)
|
||||
# def decorated_function(*args, **kwargs):
|
||||
# if "auth" not in session or not session["auth"]:
|
||||
# return redirect(url_for("auth.login"))
|
||||
# return f(*args, **kwargs)
|
||||
# return decorated_function
|
||||
|
||||
def subscription_required(f):
|
||||
def admin_required(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
print(current_user)
|
||||
# m = Moderator.filter(username=session["auth"]["preferred_username"])
|
||||
# if m:
|
||||
# return f(*args, **kwargs)
|
||||
# else:
|
||||
# flash("You are not a moderator")
|
||||
# return redirect(url_for("index"))
|
||||
if current_user.is_admin:
|
||||
return f(*args, **kwargs)
|
||||
else:
|
||||
flash('Must be an admin to access that page.', 'warning')
|
||||
if request.referrer:
|
||||
u = request.referrer
|
||||
else:
|
||||
u = url_for('main.index')
|
||||
return redirect(u)
|
||||
return decorated_function
|
||||
|
@ -0,0 +1,33 @@
|
||||
{% extends 'includes/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<h1>admins</h1>
|
||||
<p>Add a homie</p>
|
||||
<form method="post" action="">
|
||||
{{ user_form.csrf_token }}
|
||||
<div class="row">
|
||||
<div class="two columns">
|
||||
{{ user_form.handle }}
|
||||
</div>
|
||||
<div class="two columns">
|
||||
<input class="button-primary" type="submit" value="Submit">
|
||||
</div>
|
||||
</div>
|
||||
<ul>
|
||||
{%- for field, errors in user_form.errors.items() %}
|
||||
<li>{{ ', '.join(errors) }}</li>
|
||||
{%- endfor %}
|
||||
</ul>
|
||||
</form>
|
||||
<ul>
|
||||
{% for admin in admins %}
|
||||
<li><h6>{{ admin.handle }} - <a href="?remove={{ admin.handle }}">remove</a></h6></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue