initial commit
This commit is contained in:
commit
87c4aa1cde
|
@ -0,0 +1,264 @@
|
||||||
|
teste/*
|
||||||
|
teste.py
|
||||||
|
*.session
|
||||||
|
*-env
|
||||||
|
old
|
||||||
|
link.sh
|
||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/python,pycharm+all
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm+all
|
||||||
|
|
||||||
|
### PyCharm+all ###
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
### PyCharm+all Patch ###
|
||||||
|
# Ignores the whole .idea folder and all .iml files
|
||||||
|
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||||
|
|
||||||
|
.idea/*
|
||||||
|
|
||||||
|
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
modules.xml
|
||||||
|
.idea/misc.xml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
# Sonarlint plugin
|
||||||
|
.idea/sonarlint
|
||||||
|
|
||||||
|
### Python ###
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/python,pycharm+all
|
||||||
|
|
||||||
|
# Glade temporary files
|
||||||
|
*.glade~
|
||||||
|
*.glade\#
|
|
@ -0,0 +1,2 @@
|
||||||
|
bcrypt
|
||||||
|
flask
|
|
@ -0,0 +1,54 @@
|
||||||
|
[metadata]
|
||||||
|
name = TODO
|
||||||
|
#version = attr: meexer.settings.__version__
|
||||||
|
description = TODO
|
||||||
|
long_description = file: README.md
|
||||||
|
long_description_content_type = text/markdown
|
||||||
|
author = Gabriel Carneiro
|
||||||
|
author_email = therealcarneiro@gmail.com
|
||||||
|
license = MIT
|
||||||
|
license_files = LICENSE
|
||||||
|
#url = https://github.com/theRealCarneiro/pulsemeeter
|
||||||
|
keywords = audio, mixing, mixer
|
||||||
|
classifiers =
|
||||||
|
Programming Language :: Python :: 3
|
||||||
|
Environment :: X11 Applications
|
||||||
|
License :: OSI Approved :: MIT License
|
||||||
|
|
||||||
|
[options]
|
||||||
|
include_package_data = True
|
||||||
|
packages = find:
|
||||||
|
python_requires = >=3.10
|
||||||
|
install_requires = file: requirements.txt
|
||||||
|
#scripts = src/scripts/pmctl
|
||||||
|
package_dir =
|
||||||
|
= src
|
||||||
|
|
||||||
|
[options.entry_points]
|
||||||
|
console_scripts =
|
||||||
|
meexer = meexer.main:main
|
||||||
|
|
||||||
|
[options.packages.find]
|
||||||
|
where=src
|
||||||
|
|
||||||
|
#[pylint.MAIN]
|
||||||
|
#init-hook = from gi import require_version; require_version('Gtk', '3.0')
|
||||||
|
#load-plugins = pylint_pydantic
|
||||||
|
#extension-pkg-whitelist = pydantic
|
||||||
|
#fail-under = 8
|
||||||
|
|
||||||
|
[pylint.REPORTS]
|
||||||
|
output-format = colorized
|
||||||
|
|
||||||
|
[pylint.DESIGN]
|
||||||
|
max-args = 10
|
||||||
|
max-attributes = 10
|
||||||
|
|
||||||
|
[pylint.FORMAT]
|
||||||
|
max-line-length = 120
|
||||||
|
|
||||||
|
[pylint]
|
||||||
|
disable = missing-module-docstring, missing-function-docstring, missing-class-docstring
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
max-line-length = 120
|
|
@ -0,0 +1,3 @@
|
||||||
|
'''
|
||||||
|
For managing streams
|
||||||
|
'''
|
|
@ -0,0 +1,3 @@
|
||||||
|
'''
|
||||||
|
For managing users
|
||||||
|
'''
|
|
@ -0,0 +1,21 @@
|
||||||
|
'''
|
||||||
|
Entry point
|
||||||
|
'''
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from flask import Flask
|
||||||
|
from stream_auth import settings
|
||||||
|
from stream_auth.routes.user import user as user_routes
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app.register_blueprint(user_routes)
|
||||||
|
app.run(host=settings.HOST, port=settings.PORT)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -0,0 +1,53 @@
|
||||||
|
'''
|
||||||
|
User model
|
||||||
|
'''
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
import logging
|
||||||
|
import bcrypt
|
||||||
|
|
||||||
|
STREAM_KEY_LENGTH = 64
|
||||||
|
|
||||||
|
|
||||||
|
def generate_stream_key(key_length: int):
|
||||||
|
'''
|
||||||
|
Generate a new stream key
|
||||||
|
'''
|
||||||
|
key_types = string.ascii_letters + string.digits
|
||||||
|
return ''.join(random.choice(key_types) for i in range(key_length))
|
||||||
|
|
||||||
|
|
||||||
|
class User:
|
||||||
|
'''
|
||||||
|
User class, for managing a specific user
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, username: str, password: str):
|
||||||
|
salt = bcrypt.gensalt()
|
||||||
|
self.username = username
|
||||||
|
self.password = bcrypt.hashpw(password.encode('utf-8'), salt)
|
||||||
|
self.stream_key = generate_stream_key(STREAM_KEY_LENGTH)
|
||||||
|
|
||||||
|
def regenerate_stream_key(self):
|
||||||
|
'''
|
||||||
|
Recreate stream_key
|
||||||
|
'''
|
||||||
|
self.stream_key = generate_stream_key(STREAM_KEY_LENGTH)
|
||||||
|
|
||||||
|
def check_passwrod(self, password: str):
|
||||||
|
input_pass = password.encode('utf-8')
|
||||||
|
result = bcrypt.checkpw(input_pass, self.password)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def change_password(self, current_password: str, new_password: str):
|
||||||
|
'''
|
||||||
|
Changes user defualt password
|
||||||
|
'''
|
||||||
|
ecpass = current_password.encode('utf-8')
|
||||||
|
enpass = new_password.encode('utf-8')
|
||||||
|
result = bcrypt.checkpw(ecpass, self.password)
|
||||||
|
if not result:
|
||||||
|
logging.warning("PASSWORDS DO NOT MATCH")
|
||||||
|
|
||||||
|
salt = bcrypt.gensalt()
|
||||||
|
self.password = bcrypt.hashpw(enpass, salt)
|
|
@ -0,0 +1,46 @@
|
||||||
|
'''
|
||||||
|
For controlling user routes
|
||||||
|
'''
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from flask import Blueprint, Response, request
|
||||||
|
from stream_auth.models.user import User
|
||||||
|
|
||||||
|
user = Blueprint('user', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@user.route("/signin", methods=["POST"])
|
||||||
|
def create():
|
||||||
|
'''
|
||||||
|
Create a new user
|
||||||
|
'''
|
||||||
|
|
||||||
|
json = request.get_json()
|
||||||
|
username = json['username']
|
||||||
|
password = json['password']
|
||||||
|
|
||||||
|
new_user = User(username, password)
|
||||||
|
|
||||||
|
logging.info('User %s created with stream key %s',
|
||||||
|
new_user.username, new_user.stream_key)
|
||||||
|
|
||||||
|
return Response('OK', 200)
|
||||||
|
|
||||||
|
|
||||||
|
@user.route("/login", methods=["POST"])
|
||||||
|
def login():
|
||||||
|
'''
|
||||||
|
Create a new user
|
||||||
|
'''
|
||||||
|
|
||||||
|
json = request.get_json()
|
||||||
|
username = json['username']
|
||||||
|
password = json['password']
|
||||||
|
|
||||||
|
# TODO: actully do this
|
||||||
|
new_user = User(username, password)
|
||||||
|
|
||||||
|
# logging.info('User %s created with stream key %s',
|
||||||
|
# new_user.username, new_user.stream_key)
|
||||||
|
|
||||||
|
return Response('OK', 200)
|
|
@ -0,0 +1,6 @@
|
||||||
|
'''
|
||||||
|
Settings file, where all globals should be
|
||||||
|
'''
|
||||||
|
|
||||||
|
HOST = '0.0.0.0'
|
||||||
|
PORT = 8080
|
Loading…
Reference in New Issue