Skip to content
This repository was archived by the owner on Dec 21, 2019. It is now read-only.

Commit 26f23d9

Browse files
committed
Updating to let admins set the notification title
1 parent 907de6c commit 26f23d9

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

__init__.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ def notify_send():
2626
return render_template('notify.html')
2727
elif request.method == 'POST':
2828
msg = request.form.get('msg')
29+
title = request.form.get('title')
2930
client_secret = get_config('thunderpush_client_secret')
3031
server_secret = get_config('thunderpush_server_secret')
3132
thunderpush_url = get_config('thunderpush_url')
3233
thunderpush_port = get_config('thunderpush_port')
3334
t = Thunder(apikey=client_secret, apisecret=server_secret, host=thunderpush_url, port=thunderpush_port)
34-
print t.send_message_to_channel(channel='all_teams', message={'title': 'CTFd Notification', 'msg': msg})
35+
t.send_message_to_channel(channel='all_teams', message={'title': title, 'msg': msg})
3536
return '', 200
3637

3738
@notify.route('/notify/static/ctfd-notify.js', methods=['GET'])
@@ -43,4 +44,12 @@ def notify_static_generator():
4344
return Response(js, mimetype='application/javascript')
4445

4546
app.register_blueprint(notify)
46-
app.register_blueprint(notify_static, url_prefix='/notify')
47+
app.register_blueprint(notify_static, url_prefix='/notify')
48+
scripts = [
49+
"/notify/static/sockjs-0.3.4.min.js",
50+
"/notify/static/thunderpush.js",
51+
"/notify/static/push.min.js",
52+
"/notify/static/ctfd-notify.js"
53+
]
54+
for s in scripts:
55+
utils.register_plugin_script(s)

templates/ctfd-notify.js

-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,5 @@ if ( push_status === Push.Permission.DEFAULT ) {
4141
console.log(message);
4242
var message = html.format(message.title, message.msg);
4343
$('#notification_wrapper').append(message);
44-
4544
});
4645
}

templates/notify.html

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ <h1 class="text-center">Send Notification</h1>
99
</div>
1010
<div class="row">
1111
<form id="thunderpush_notify" method="POST" action="/admin/plugins/notify/send">
12+
<div class="form-group">
13+
<label>Notification Title</label>
14+
<input class="form-control" type="text" name="title" placeholder="Notification Title">
15+
</div>
1216
<div class="form-group">
1317
<label>Notification Message</label>
1418
<input class="form-control" type="text" name="msg" placeholder="Notification Message">
@@ -23,13 +27,16 @@ <h1 class="text-center">Send Notification</h1>
2327
{% endblock %}
2428

2529
{% block scripts %}
30+
<script src="{{ request.script_root }}/notify/static/sockjs-0.3.4.min.js"></script>
31+
<script src="{{ request.script_root }}/notify/static/thunderpush.js"></script>
32+
<script src="{{ request.script_root }}/notify/static/push.min.js"></script>
33+
<script src="{{ request.script_root }}/notify/static/ctfd-notify.js"></script>
34+
2635
<script type="text/javascript">
2736
$('#thunderpush_notify').submit(function(e){
2837
e.preventDefault();
2938
$.post(window.location.pathname, $(this).serialize(), function(data){
30-
if (data == 1){
31-
window.location.reload();
32-
}
39+
console.log(data);
3340
});
3441
});
3542
</script>

0 commit comments

Comments
 (0)