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/register.html', form=form) email = form.email.data.lower() if not is_valid_email(email, False): flash_error('Invalid email.') return render_template('home/register.html', form=form) existing_user = ProviderAdminUser.get_by_email(email) if existing_user: return redirect(url_for('HomeView:signin')) new_user = ProviderAdminUser.make_provider(email=email, first_name=form.first_name, last_name=form.last_name, password=form.password.data, country=form.country.data, language=form.language.data) new_user.save() 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='Confirm Email', recipients=[email], html=html) mail.send(msg) flash_success('Please check email: {0}.'.format(email)) return redirect(url_for('HomeView:signin')) return render_template('home/register.html', form=form)
def provider_remove(self, sid): data = request.get_json() pid = data['pid'] provider = ProviderAdminUser.objects(id=pid).first() server = _get_server_by_id(sid) if provider and server: server.remove_provider(provider) provider.remove_server(server) return jsonify(status='ok'), 200 return jsonify(status='failed'), 404
def post_login(form: SignInForm): if not form.validate_on_submit(): flash_error(form.errors) return render_template('home/login.html', form=form) email = form.email.data.lower() check_user = ProviderAdminUser.get_by_email(email) if not check_user: flash_error('User not found.') return render_template('home/login.html', form=form) if check_user.status == ProviderAdminUser.Status.NO_ACTIVE: flash_error('User not active.') return render_template('home/login.html', form=form) if not ProviderAdminUser.check_password_hash(check_user.password, form.password.data): flash_error('Invalid password.') return render_template('home/login.html', form=form) check_user.login() return redirect(url_for('ProviderView:dashboard'))
def provider_add(self, sid): form = ServerProviderForm() if request.method == 'POST' and form.validate_on_submit(): email = form.email.data.lower() provider = ProviderAdminUser.objects(email=email).first() server = _get_server_by_id(sid) if server and provider: admin = ProviderPair(provider.id, form.role.data) server.add_provider(admin) provider.add_server(server) return jsonify(status='ok'), 200 return render_template('service/provider/add.html', form=form)
def provider_remove(self, sid): data = request.get_json() pid = data['pid'] provider = ProviderAdminUser.get_by_id(ObjectId(pid)) server = ServiceSettings.get_by_id(ObjectId(sid)) if provider and server: server.remove_provider(provider) server.save() provider.remove_server(server) provider.save() return jsonify(status='ok'), 200 return jsonify(status='failed'), 404
def confirm_email(self, token): try: email = self._confirm_link_generator.loads(token, salt=HomeView.SALT_LINK, max_age=HomeView.CONFIRM_LINK_TTL) confirm_user = ProviderAdminUser.get_by_email(email) if confirm_user: confirm_user.status = ProviderAdminUser.Status.ACTIVE confirm_user.save() confirm_user.login() return redirect(url_for('HomeView:signin')) else: return '<h1>We can\'t find user.</h1>' except SignatureExpired: return '<h1>The token is expired!</h1>'
PROJECT_NAME = 'create_provider' if __name__ == '__main__': parser = argparse.ArgumentParser(prog=PROJECT_NAME, usage='%(prog)s [options]') parser.add_argument('--mongo_uri', help='MongoDB credentials', default='mongodb://localhost:27017/iptv') parser.add_argument('--email', help='Provider email') parser.add_argument('--password', help='Provider password') parser.add_argument('--country', help='Provider country', default='US') parser.add_argument('--language', help='Provider language', default='en') argv = parser.parse_args() email = argv.email password = argv.password mongo = connect(host=argv.mongo_uri) if not mongo: sys.exit(1) new_user = ProviderAdminUser.make_provider(email=email.lower(), password=password, country=argv.country, language=argv.language) new_user.status = ProviderAdminUser.Status.ACTIVE new_user.save() print('Successfully created provider email: {0}, password: {1}'.format( email, password))
def load_user(user_id): return ProviderAdminUser.objects(pk=user_id).first()
def load_user(user_id): return ProviderAdminUser.get_by_id(ObjectId(user_id))
if __name__ == '__main__': parser = argparse.ArgumentParser(prog=PROJECT_NAME, usage='%(prog)s [options]') parser.add_argument('--mongo_uri', help='MongoDB credentials', default='mongodb://localhost:27017/iptv') parser.add_argument('--email', help='Provider email') parser.add_argument('--first_name', help='First name') parser.add_argument('--last_name', help='Last name') parser.add_argument('--password', help='Provider password') parser.add_argument('--country', help='Provider country', default='US') parser.add_argument('--language', help='Provider language', default='en') argv = parser.parse_args() email = argv.email.lower() first_name = argv.first_name last_name = argv.last_name password = argv.password connect(mongodb_uri=argv.mongo_uri) new_user = ProviderAdminUser.make_provider(email=email, first_name=first_name, last_name=last_name, password=password, country=argv.country, language=argv.language) new_user.status = ProviderAdminUser.Status.ACTIVE new_user.save() print('Successfully created provider email: {0}, password: {1}'.format( email, password))