mirror of
https://github.com/fastogt/fastocloud_admin.git
synced 2025-03-09 23:38:52 +00:00
Message send
This commit is contained in:
parent
96c043ae02
commit
ce1ee32ae4
6 changed files with 86 additions and 13 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 99e119d1facbd614f7f8307f9512578e79eead8a
|
Subproject commit 201c631c2464927690c3fe3b1c0d26853faa9586
|
|
@ -212,3 +212,8 @@ class ServiceManager(IClientHandler):
|
||||||
connections.append(user)
|
connections.append(user)
|
||||||
|
|
||||||
return connections
|
return connections
|
||||||
|
|
||||||
|
def send_message(self, email: str, message: str, ttl: int):
|
||||||
|
for user in self._subscribers:
|
||||||
|
if user.info and user.info.email == email:
|
||||||
|
user.send_message(message, ttl * 1000)
|
||||||
|
|
|
@ -4,9 +4,9 @@ from flask_classy import FlaskView, route
|
||||||
from flask import render_template, redirect, url_for, request, jsonify, Response
|
from flask import render_template, redirect, url_for, request, jsonify, Response
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
|
|
||||||
from app import get_runtime_folder
|
from app import get_runtime_folder, servers_manager
|
||||||
from app.common.service.forms import ServiceSettingsForm, ActivateForm, UploadM3uForm, ServerProviderForm
|
from app.common.service.forms import ServiceSettingsForm, ActivateForm, UploadM3uForm, ServerProviderForm
|
||||||
from app.common.subscriber.forms import SignupForm
|
from app.common.subscriber.forms import SignupForm, MessageForm
|
||||||
from app.common.service.entry import ServiceSettings, ProviderPair
|
from app.common.service.entry import ServiceSettings, ProviderPair
|
||||||
from app.common.subscriber.entry import Subscriber
|
from app.common.subscriber.entry import Subscriber
|
||||||
from app.common.utils.m3u_parser import M3uParser
|
from app.common.utils.m3u_parser import M3uParser
|
||||||
|
@ -271,6 +271,17 @@ class ServiceView(FlaskView):
|
||||||
|
|
||||||
return jsonify(status='failed'), 404
|
return jsonify(status='failed'), 404
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@route('/subscriber/send_message/<sid>', methods=['GET', 'POST'])
|
||||||
|
def subscriber_send_message(self, sid):
|
||||||
|
subscriber = Subscriber.objects(id=sid).first()
|
||||||
|
form = MessageForm()
|
||||||
|
if request.method == 'POST' and form.validate_on_submit():
|
||||||
|
servers_manager.send_message(subscriber.email, form.message.data, form.ttl.data)
|
||||||
|
return jsonify(status='ok'), 200
|
||||||
|
|
||||||
|
return render_template('service/subscriber/send_message.html', form=form)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@route('/add', methods=['GET', 'POST'])
|
@route('/add', methods=['GET', 'POST'])
|
||||||
def add(self):
|
def add(self):
|
||||||
|
|
|
@ -1087,15 +1087,5 @@ Dashboard | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
34
app/templates/service/subscriber/send_message.html
Normal file
34
app/templates/service/subscriber/send_message.html
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{% from 'bootstrap/wtf.html' import form_field %}
|
||||||
|
{% macro render_bootstrap_field(field) %}
|
||||||
|
<div class="row">
|
||||||
|
<label class="col-md-4">{{ field.label }}</label>
|
||||||
|
<div class="col-md-8">
|
||||||
|
{{ field(class='form-control')|safe }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
<form id="send_message_form" name="send_message_form" class="form" method="post">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
<h4 class="modal-title">
|
||||||
|
{% block title %}
|
||||||
|
{% endblock %}
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
<br>
|
||||||
|
{{ render_bootstrap_field(form.message) }}
|
||||||
|
<br>
|
||||||
|
{{ render_bootstrap_field(form.ttl) }}
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
{% block footer %}
|
||||||
|
<button type="button" class="btn btn-danger" data-dismiss="modal">{% trans %}Cancel{% endtrans %}</button>
|
||||||
|
{{ form_field(form.apply, class="btn btn-success") }}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</form>
|
|
@ -59,6 +59,10 @@ Activate service | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
onclick="edit_subscriber('{{ subscriber.id }}')">
|
onclick="edit_subscriber('{{ subscriber.id }}')">
|
||||||
{% trans %}Edit{% endtrans %}
|
{% trans %}Edit{% endtrans %}
|
||||||
</button>
|
</button>
|
||||||
|
<button type="submit" class="btn btn-success btn-xs"
|
||||||
|
onclick="send_message_for_subscriber('{{ subscriber.id }}')">
|
||||||
|
{% trans %}Send message{% endtrans %}
|
||||||
|
</button>
|
||||||
<button type="submit" class="btn btn-danger btn-xs"
|
<button type="submit" class="btn btn-danger btn-xs"
|
||||||
onclick="remove_subscriber('{{ subscriber.id }}')">
|
onclick="remove_subscriber('{{ subscriber.id }}')">
|
||||||
{% trans %}Remove{% endtrans %}
|
{% trans %}Remove{% endtrans %}
|
||||||
|
@ -168,6 +172,35 @@ Activate service | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function send_message(url) {
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: "POST",
|
||||||
|
dataType: 'json',
|
||||||
|
data: $('#send_message_form').serialize(),
|
||||||
|
success: function (response) {
|
||||||
|
console.log(response);
|
||||||
|
$('#service_dialog').modal('hide');
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
error: function (error) {
|
||||||
|
console.error(error);
|
||||||
|
$('#service_dialog .modal-content').html(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function send_message_for_subscriber(sid) {
|
||||||
|
var url = "/service/subscriber/send_message/" + sid;
|
||||||
|
$.get(url, function(data) {
|
||||||
|
$('#service_dialog .modal-content').html(data);
|
||||||
|
$('#service_dialog').modal();
|
||||||
|
|
||||||
|
$('#apply').click(function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
send_message(url);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue