admins can edit and remove links

master
Marek Baczynski 6 years ago
parent a2e2b8992b
commit 6fca90977f

@ -92,15 +92,27 @@ def serveCode(code):
@app.route("/edit", methods=['GET', 'POST'])
def edit():
code = request.form.get("code")
print ("code: {}".format(code))
code = request.form.get("code") if request.form.get("code") is not None else request.args.get("code")
url = request.form.get("url")
if codeLink(code) is False:
return render_template('invalid.html', code=code)
if codeLink(code) is not None:
return render_template('cantedit.html', url=codeLink(code))
url = request.form.get("url")
if current_user.is_authenticated:
if url==None:
return render_template('editlink.html', code=code, url=codeLink(code), admin=current_user.is_authenticated)
else:
if url=='remove':
url = ''
links[code]['url']=url
saveFile()
return render_template('message.html', message="Done Mr. Admin person")
else:
if codeLink(code) is not None:
return render_template('cantedit.html', url=codeLink(code))
if url is None:
return render_template('editlink.html', code=code)
return render_template('editlink.html', code=code, url='', admin=current_user.is_authenticated)
#Saving the link:
if url.lower().startswith('https://') is False and url.lower().startswith('http://') is False:
return render_template('message.html', message="Only http:// and https:// links alowed. Plz fix your link!")

@ -1,12 +1,21 @@
{% extends 'base.html' %}
{% block content %}
<form action=/edit method="post">
<form action=/edit id="editform" method="post">
<input type="hidden" name="code" value="{{code}}" />
QR-code:<br />
<input type="text" value="{{code}}" disabled /><br />
URL:<br />
<input type="url" name="url" value=""/><br />
<button type="submit" class="graybar" >Save </button>
<input type="url" id="url" name="url" value="{{url}}"/><br />
<button type="submit" class="graybar" >Save</button>
</form>
{% if admin == True %}
<button class="graybar" onclick="removeLink()">Remove link</button>
{% endif %}
<script>
function removeLink() {
document.getElementById("url").value = "";
document.getElementById("editform").submit();
}
</script>
{% endblock %}

@ -5,7 +5,8 @@
{% for label in linklist %}
<p>
<span class="code">{{label['code']}}</span>:
<a href="/code/{{label['code']}}.png" class="linkonalist">Show QR</a> | <a href="/edit" class="linkonalist">Edit</a>
&nbsp;&nbsp;&nbsp;
<a href="/code/{{label['code']}}.png" class="linkonalist">Show QR</a> | <a href="/edit?code={{label['code']}}" class="linkonalist">Edit</a>
<br />
<a href="{{label['url']}}" class="linkonalist">{{label['url']}}</a>
<hr>

Loading…
Cancel
Save