def add_mod():
# adds a user to the list of moderators
username = request.form["username"]
user = User.query.filter(func.lower(User.username)
== func.lower(username)).first()
if not user:
return bad_request("user not found")
user.form_mod = True
run = True
while run:
# issue key
key = "".join(
random.choices(
string.ascii_letters +
string.digits,
k=32))
user.api_key = key
try:
db.session.add(user)
db.session.commit()
run = False
except IntegrityError: # check for uniqueness
continue
db.session.add(user)
db.session.commit()
url = url_for('settings', _external=True)
subj = f"invitation to moderate {g.settings.site_title}"
body = f"**gadzooks!** u/{g.user.username} has added you as a moderator of {g.settings.site_title}"
body += f"\n\nclick [here]({url}) to view the site. mod tools will be visible at the top of the page."
send_message(username, subj, body)
return jsonify(status="OK"), 200
评论列表
文章目录