def remove(self): servers = ServiceSettings.objects() for server in servers: server.remove_user(current_user) current_user.delete() return redirect(url_for('HomeView:index'))
def playlist(self, sid): server = ServiceSettings.objects(id=sid).first() if server: return Response(server.generate_playlist(), mimetype='application/x-mpequrl'), 200 return jsonify(status='failed'), 404
def remove(self): sid = request.form['sid'] server = ServiceSettings.objects(id=sid).first() if server: current_user.remove_server(server) return jsonify(status='ok'), 200 return jsonify(status='failed'), 404
def edit(self, sid): server = ServiceSettings.objects(id=sid).first() form = ServiceSettingsForm(obj=server) if request.method == 'POST' and form.validate_on_submit(): server = form.update_entry(server) server.save() return jsonify(status='ok'), 200 return render_template('service/edit.html', form=form)
def add(self): form = ServiceSettingsForm(obj=ServiceSettings()) if request.method == 'POST' and form.validate_on_submit(): new_entry = form.make_entry() admin = UserPair(current_user.id, constants.Roles.ADMIN) new_entry.add_provider(admin) current_user.add_server(new_entry) return jsonify(status='ok'), 200 return render_template('service/add.html', form=form)
def provider_remove(self, sid): data = request.get_json() pid = data['pid'] provider = ProviderUser.objects(id=pid).first() server = ServiceSettings.objects(id=sid).first() if provider and server: server.remove_provider(provider) provider.remove_server(server) return jsonify(status='ok'), 200 return jsonify(status='failed'), 404
def subscriber_add(self, sid): form = SignupForm() if request.method == 'POST' and form.validate_on_submit(): server = ServiceSettings.objects(id=sid).first() if server: new_entry = form.make_active_entry() new_entry.add_server(server) server.add_subscriber(new_entry) return jsonify(status='ok'), 200 return render_template('service/subscriber/add.html', form=form)
def provider_add(self, sid): form = UserServerForm() if request.method == 'POST' and form.validate_on_submit(): user = ProviderUser.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_provider(admin) user.add_server(server) return jsonify(status='ok'), 200 return render_template('service/provider/add.html', form=form)
def signup(self): form = SignupForm( country=get_country_code_by_remote_addr(request.remote_addr)) if request.method == 'POST': if not form.validate_on_submit(): flash_error(form.errors) return render_template('home/signup.html', form=form) email = form.email.data.lower() if not is_valid_email(email, False): flash_error(gettext(u'Invalid email.')) return render_template('home/signup.html', form=form) existing_user = SubscriberUser.objects(email=email, class_check=False).first() if existing_user: return redirect(url_for('HomeView:signin')) new_user = SubscriberUser.make_subscriber(email, form.password.data, form.country.data) new_user.save() servers = ServiceSettings.objects() for serv in servers: new_user.add_server(serv) serv.add_subscriber(new_user) token = self._confirm_link_generator.dumps(email, salt=HomeView.SALT_LINK) confirm_url = url_for('HomeView:confirm_email', token=token, _external=True) config = app.config['PUBLIC_CONFIG'] html = render_template( 'home/email/activate.html', confirm_url=confirm_url, contact_email=config['support']['contact_email'], title=config['site']['title'], company=config['company']['title']) msg = Message(subject=gettext(u'Confirm Email'), recipients=[email], html=html) mail.send(msg) flash_success(gettext(u'Please check email: {0}.'.format(email))) return redirect(url_for('HomeView:signin')) return render_template('home/signup.html', form=form)
def subscribers(self, sid): server = ServiceSettings.objects(id=sid).first() if server: return render_template('service/subscribers.html', server=server) return redirect(url_for('ProviderView:dashboard'))
def update_entry(self, settings: ServiceSettings): settings.name = self.name.data settings.host = self.host.get_data() settings.http_host = self.http_host.get_data() settings.vods_host = self.vods_host.get_data() settings.cods_host = self.cods_host.get_data() settings.feedback_directory = self.feedback_directory.data settings.timeshifts_directory = self.timeshifts_directory.data settings.hls_directory = self.hls_directory.data settings.playlists_directory = self.playlists_directory.data settings.dvb_directory = self.dvb_directory.data settings.capture_card_directory = self.capture_card_directory.data settings.vods_in_directory = self.vods_in_directory.data settings.vods_directory = self.vods_directory.data settings.cods_directory = self.cods_directory.data return settings
def make_entry(self): return self.update_entry(ServiceSettings())