mirror of
https://github.com/fastogt/fastocloud_admin.git
synced 2025-03-09 23:38:52 +00:00
Add user
This commit is contained in:
parent
3805db5aff
commit
6c378f86aa
9 changed files with 143 additions and 50 deletions
|
@ -1,5 +1,5 @@
|
||||||
PUBLIC_CONFIG = {'site': {'title': 'FastoCloud', 'keywords': 'video,cloud,iptv,service,server'},
|
PUBLIC_CONFIG = {'site': {'title': 'FastoCloud', 'keywords': 'video,cloud,iptv,service,restreamer'},
|
||||||
'company': {'title': 'FastoGT', 'domain': 'https://fastogt.com'},
|
'company': {'title': 'FastoGT', 'domain': 'https://fastogt.com'},
|
||||||
'support': {'contact_email': 'support@fastogt.com',
|
'support': {'contact_email': 'support@fastogt.com',
|
||||||
'contact_address': 'Republic of Belarus, Minsk, Stadionnay str. 5'},
|
'contact_address': 'Republic of Belarus, Minsk, Stadionnay str. 5'},
|
||||||
'project': {'version': '1.0.0', 'version_type': 'release'}}
|
'project': {'version': '1.1.0', 'version_type': 'rc'}}
|
||||||
|
|
|
@ -184,3 +184,14 @@ class Roles(IntEnum):
|
||||||
WRITE = 1
|
WRITE = 1
|
||||||
ADMIN = 2
|
ADMIN = 2
|
||||||
SUPPORT = 3
|
SUPPORT = 3
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def choices(cls):
|
||||||
|
return [(choice, choice.name) for choice in cls]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def coerce(cls, item):
|
||||||
|
return cls(int(item)) if not isinstance(item, cls) else item
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.value)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_babel import lazy_gettext
|
from flask_babel import lazy_gettext
|
||||||
from wtforms.fields import StringField, SubmitField, FileField, SelectField, FormField
|
from wtforms.fields import StringField, SubmitField, FileField, SelectField, FormField
|
||||||
from wtforms.validators import InputRequired, Length
|
from wtforms.validators import InputRequired, Length, Email
|
||||||
|
|
||||||
from app.common_forms import HostAndPortForm
|
from app.common_forms import HostAndPortForm
|
||||||
from app.service.service_entry import ServiceSettings
|
from app.service.service_entry import ServiceSettings
|
||||||
from app.constants import StreamType
|
import app.constants as constants
|
||||||
|
|
||||||
|
|
||||||
class ServiceSettingsForm(FlaskForm):
|
class ServiceSettingsForm(FlaskForm):
|
||||||
|
@ -51,11 +51,24 @@ class ActivateForm(FlaskForm):
|
||||||
|
|
||||||
|
|
||||||
class UploadM3uForm(FlaskForm):
|
class UploadM3uForm(FlaskForm):
|
||||||
AVAILABLE_STREAM_TYPES_FOR_UPLOAD = [(StreamType.RELAY, 'Relay'), (StreamType.ENCODE, 'Encode'),
|
AVAILABLE_STREAM_TYPES_FOR_UPLOAD = [(constants.StreamType.RELAY, 'Relay'), (constants.StreamType.ENCODE, 'Encode'),
|
||||||
(StreamType.CATCHUP, 'Catchup'), (StreamType.TEST_LIFE, 'Test life'),
|
(constants.StreamType.CATCHUP, 'Catchup'),
|
||||||
(StreamType.VOD_RELAY, 'Vod relay'), (StreamType.VOD_ENCODE, 'Vod encode')]
|
(constants.StreamType.TEST_LIFE, 'Test life'),
|
||||||
|
(constants.StreamType.VOD_RELAY, 'Vod relay'),
|
||||||
|
(constants.StreamType.VOD_ENCODE, 'Vod encode')]
|
||||||
|
|
||||||
file = FileField()
|
file = FileField()
|
||||||
type = SelectField(lazy_gettext(u'Type:'), coerce=StreamType.coerce, validators=[InputRequired()],
|
type = SelectField(lazy_gettext(u'Type:'), coerce=constants.StreamType.coerce, validators=[InputRequired()],
|
||||||
choices=AVAILABLE_STREAM_TYPES_FOR_UPLOAD)
|
choices=AVAILABLE_STREAM_TYPES_FOR_UPLOAD)
|
||||||
submit = SubmitField(lazy_gettext(u'Upload'))
|
submit = SubmitField(lazy_gettext(u'Upload'))
|
||||||
|
|
||||||
|
|
||||||
|
class UserAddForm(FlaskForm):
|
||||||
|
AVAILABLE_ROLES = [(constants.Roles.READ, 'Read'), (constants.Roles.WRITE, 'Write'),
|
||||||
|
(constants.Roles.ADMIN, 'Admin'), (constants.Roles.SUPPORT, 'Support')]
|
||||||
|
|
||||||
|
email = StringField(lazy_gettext(u'Email:'),
|
||||||
|
validators=[InputRequired(), Email(message=lazy_gettext(u'Invalid email')), Length(max=30)])
|
||||||
|
role = SelectField(lazy_gettext(u'Role:'), coerce=constants.Roles.coerce, validators=[InputRequired()],
|
||||||
|
choices=AVAILABLE_ROLES)
|
||||||
|
apply = SubmitField(lazy_gettext(u'Apply'))
|
||||||
|
|
|
@ -38,3 +38,7 @@ class ServiceSettings(Document, ServerSettings):
|
||||||
out.uri)
|
out.uri)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def add_user(self, user: UserPair):
|
||||||
|
self.users.append(user)
|
||||||
|
self.save()
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bson.objectid import ObjectId
|
|
||||||
|
|
||||||
from flask_classy import FlaskView, route
|
from flask_classy import FlaskView, route
|
||||||
from flask import render_template, redirect, url_for, request, jsonify
|
from flask import render_template, redirect, url_for, request, jsonify
|
||||||
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
|
||||||
from app.service.forms import ServiceSettingsForm, ActivateForm, UploadM3uForm
|
from app.service.forms import ServiceSettingsForm, ActivateForm, UploadM3uForm, UserAddForm
|
||||||
from app.service.service_entry import ServiceSettings, UserPair
|
from app.service.service_entry import ServiceSettings, UserPair
|
||||||
from app.utils.m3u_parser import M3uParser
|
from app.utils.m3u_parser import M3uParser
|
||||||
|
from app.home.user_loging_manager import User
|
||||||
import app.constants as constants
|
import app.constants as constants
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,6 +140,20 @@ class ServiceView(FlaskView):
|
||||||
|
|
||||||
# broadcast routes
|
# broadcast routes
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@route('/user/add/<sid>', methods=['GET', 'POST'])
|
||||||
|
def user_add(self, sid):
|
||||||
|
form = UserAddForm()
|
||||||
|
if request.method == 'POST' and form.validate_on_submit():
|
||||||
|
user = User.objects(email=form.email.data).first()
|
||||||
|
server = ServiceSettings.objects(id=sid).first()
|
||||||
|
if server and user:
|
||||||
|
admin = UserPair(user.id, form.role.data)
|
||||||
|
server.add_user(admin)
|
||||||
|
return jsonify(status='ok'), 200
|
||||||
|
|
||||||
|
return render_template('service/user/add.html', form=form)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@route('/add', methods=['GET', 'POST'])
|
@route('/add', methods=['GET', 'POST'])
|
||||||
def add(self):
|
def add(self):
|
||||||
|
@ -148,12 +161,12 @@ class ServiceView(FlaskView):
|
||||||
form = ServiceSettingsForm(obj=model)
|
form = ServiceSettingsForm(obj=model)
|
||||||
if request.method == 'POST' and form.validate_on_submit():
|
if request.method == 'POST' and form.validate_on_submit():
|
||||||
new_entry = form.make_entry()
|
new_entry = form.make_entry()
|
||||||
new_entry.users.append(UserPair(current_user.id, constants.Roles.ADMIN))
|
admin = UserPair(current_user.id, constants.Roles.ADMIN)
|
||||||
new_entry.save()
|
new_entry.add_user(admin)
|
||||||
current_user.add_server(new_entry)
|
current_user.add_server(new_entry)
|
||||||
return jsonify(status='ok'), 200
|
return jsonify(status='ok'), 200
|
||||||
|
|
||||||
return render_template('service/add.html', form=form)
|
return render_template('service/user/add.html', form=form)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@route('/remove', methods=['POST'])
|
@route('/remove', methods=['POST'])
|
||||||
|
@ -179,24 +192,6 @@ class ServiceView(FlaskView):
|
||||||
|
|
||||||
return render_template('service/edit.html', form=form)
|
return render_template('service/edit.html', form=form)
|
||||||
|
|
||||||
@login_required
|
|
||||||
@route('/find_and_add', methods=['POST'])
|
|
||||||
def find_and_add(self):
|
|
||||||
sid = request.form['sid']
|
|
||||||
if ObjectId.is_valid(sid):
|
|
||||||
server = ServiceSettings.objects(id=sid).first()
|
|
||||||
if server:
|
|
||||||
for user in server.users:
|
|
||||||
if user.id == current_user.id:
|
|
||||||
return jsonify(status='failed'), 404
|
|
||||||
|
|
||||||
server.users.append(current_user.id)
|
|
||||||
server.save()
|
|
||||||
current_user.add_server(server)
|
|
||||||
return jsonify(status='ok'), 200
|
|
||||||
|
|
||||||
return jsonify(status='failed'), 404
|
|
||||||
|
|
||||||
@route('/log/<sid>', methods=['POST'])
|
@route('/log/<sid>', methods=['POST'])
|
||||||
def log(self, sid):
|
def log(self, sid):
|
||||||
# len = request.headers['content-length']
|
# len = request.headers['content-length']
|
||||||
|
|
4
app/templates/service/user/add.html
Normal file
4
app/templates/service/user/add.html
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{% extends 'service/user/base.html' %}
|
||||||
|
{% block title %}
|
||||||
|
Add user to server
|
||||||
|
{% endblock %}
|
43
app/templates/service/user/base.html
Normal file
43
app/templates/service/user/base.html
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{% 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 %}
|
||||||
|
|
||||||
|
{% macro render_bootstrap_form(form) %}
|
||||||
|
<div class="row">
|
||||||
|
<label class="col-md-4">{{ form.label }}</label>
|
||||||
|
<div class="col-md-8">
|
||||||
|
{{ form() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
<form id="user_entry_form" name="user_entry_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.email) }}
|
||||||
|
<br>
|
||||||
|
{{ render_bootstrap_form(form.role) }}
|
||||||
|
</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>
|
4
app/templates/service/user/edit.html
Normal file
4
app/templates/service/user/edit.html
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{% extends 'service/base.html' %}
|
||||||
|
{% block title %}
|
||||||
|
Edit service
|
||||||
|
{% endblock %}
|
|
@ -60,9 +60,13 @@ Settings | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
<td>{{ loop.index }}</td>
|
<td>{{ loop.index }}</td>
|
||||||
<td>{{ server.name }}</td>
|
<td>{{ server.name }}</td>
|
||||||
<td>
|
<td>
|
||||||
<button type="submit" class="btn btn-danger btn-xs" onclick="edit_server('{{ server.id }}')">
|
<button type="submit" class="btn btn-success btn-xs" onclick="edit_server('{{ server.id }}')">
|
||||||
{% trans %}Edit{% endtrans %}
|
{% trans %}Edit{% endtrans %}
|
||||||
</button>
|
</button>
|
||||||
|
<button type="submit" class="btn btn-success btn-xs"
|
||||||
|
onclick="add_user_to_server('{{ server.id }}')">
|
||||||
|
{% trans %}Add user{% endtrans %}
|
||||||
|
</button>
|
||||||
<button type="submit" class="btn btn-danger btn-xs" onclick="remove_server('{{ server.id }}')">
|
<button type="submit" class="btn btn-danger btn-xs" onclick="remove_server('{{ server.id }}')">
|
||||||
{% trans %}Remove{% endtrans %}
|
{% trans %}Remove{% endtrans %}
|
||||||
</button>
|
</button>
|
||||||
|
@ -80,21 +84,6 @@ Settings | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</br>
|
|
||||||
<div class="row well">
|
|
||||||
<h3>Find and add server by ID:</h3>
|
|
||||||
<form class="form-group row" action="{{ url_for('ServiceView:find_and_add') }}" method="post">
|
|
||||||
<div class="col-md-10">
|
|
||||||
<div class="form-group">
|
|
||||||
<input class="form-control" name="sid" minlength="24" maxlength="24"
|
|
||||||
placeholder="ID (24-character hex string)">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<button type="submit" class="btn btn-success">Find and Add</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="service_dialog" class="modal fade" tabindex=-1 role="dialog">
|
<div id="service_dialog" class="modal fade" tabindex=-1 role="dialog">
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
|
@ -126,6 +115,38 @@ Settings | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_user_to_server_entry(url) {
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: "POST",
|
||||||
|
dataType: 'json',
|
||||||
|
data: $('#user_entry_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 add_user_to_server(sid) {
|
||||||
|
var url = "/service/user/add/" + sid;
|
||||||
|
$.get(url, function(data) {
|
||||||
|
$('#service_dialog .modal-content').html(data);
|
||||||
|
$('#service_dialog').modal();
|
||||||
|
|
||||||
|
$('#apply').click(function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
add_user_to_server_entry(url);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function add_server() {
|
function add_server() {
|
||||||
var url = "{{ url_for('ServiceView:add') }}";
|
var url = "{{ url_for('ServiceView:add') }}";
|
||||||
$.get(url, function(data) {
|
$.get(url, function(data) {
|
||||||
|
@ -185,7 +206,5 @@ Settings | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue