# qr_server
This project is the extension of Flask project (https://pypi.org/project/Flask/), aimed on fast creation of web-apps with minimalistic syntax.
The solution provides support for basic HTTP-routing (with file sending), fast DTOs
(data transfer objects for formalization and validation of response data),
simple jwt-token system, role manager (database-side rights system) and configurable logging.
See 'example' directory for a minimal working application built using this library
### Usage example:
```python
from qr_server.Server import MethodResult, QRContext
from qr_server.Config import QRYamlConfig
from qr_server.TokenManager import require_token, JwtTokenManager
from qr_server.FlaskServer import FlaskServer
def login(ctx: QRContext):
login = ctx.json_data['login']
password = ctx.json_data['password']
user_id = ctx.repository.check_credentials(login, password)
if user_id is None:
return MethodResult('wrong credentials', 500)
user = ctx.repository.get_user_data(user_id)
if user is None:
return MethodResult('account not found', 500)
jwt_token = ctx.managers['token_manager'].make_token(user_id)
return MethodResult(JwtDTO(jwt_token))
@require_token()
def user_info(ctx: QRContext, user_id):
user = ctx.repository.get_user_data(user_id)
if user is None:
return MethodResult('account not found', 500)
return MethodResult(UserInfoDTO(**user))
class AuthServer(FlaskServer, AuthRepository):
"""DI class"""
if __name__ == "__main__":
config = QRYamlConfig()
config.read_config('config.yaml')
host = config['app']['host']
port = config['app']['port']
token_man = JwtTokenManager()
token_man.load_config(config['jwt'])
server = AuthServer()
server.init_server(config['app'])
if config['app']['logging']:
server.configure_logger(config['app']['logging'])
server.register_manager(token_man)
server.register_method('/login', login, 'POST')
server.register_method('/info', user_info, 'GET')
server.run(host, port)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Kurush7/qr_server",
"name": "qr-server",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Kurush",
"author_email": "ze17@ya.ru",
"download_url": "https://files.pythonhosted.org/packages/ad/f6/4c1a91d9a4ee6eea581c26d5b992ca11b6cc570020601a82243fe242cbca/qr_server-1.1.14.tar.gz",
"platform": null,
"description": "\n# qr_server\n\nThis project is the extension of Flask project (https://pypi.org/project/Flask/), aimed on fast creation of web-apps with minimalistic syntax.\nThe solution provides support for basic HTTP-routing (with file sending), fast DTOs \n(data transfer objects for formalization and validation of response data),\nsimple jwt-token system, role manager (database-side rights system) and configurable logging.\nSee 'example' directory for a minimal working application built using this library\n\n### Usage example:\n```python\nfrom qr_server.Server import MethodResult, QRContext\nfrom qr_server.Config import QRYamlConfig\nfrom qr_server.TokenManager import require_token, JwtTokenManager\nfrom qr_server.FlaskServer import FlaskServer\n\ndef login(ctx: QRContext):\n login = ctx.json_data['login']\n password = ctx.json_data['password']\n user_id = ctx.repository.check_credentials(login, password)\n if user_id is None:\n return MethodResult('wrong credentials', 500)\n\n user = ctx.repository.get_user_data(user_id)\n if user is None:\n return MethodResult('account not found', 500)\n\n jwt_token = ctx.managers['token_manager'].make_token(user_id)\n return MethodResult(JwtDTO(jwt_token))\n\n\n@require_token()\ndef user_info(ctx: QRContext, user_id):\n user = ctx.repository.get_user_data(user_id)\n if user is None:\n return MethodResult('account not found', 500)\n\n return MethodResult(UserInfoDTO(**user))\n\n\nclass AuthServer(FlaskServer, AuthRepository):\n \"\"\"DI class\"\"\"\n\n\nif __name__ == \"__main__\":\n config = QRYamlConfig()\n config.read_config('config.yaml')\n\n host = config['app']['host']\n port = config['app']['port']\n\n token_man = JwtTokenManager()\n token_man.load_config(config['jwt'])\n\n server = AuthServer()\n server.init_server(config['app'])\n if config['app']['logging']:\n server.configure_logger(config['app']['logging'])\n server.register_manager(token_man)\n\n server.register_method('/login', login, 'POST')\n server.register_method('/info', user_info, 'GET')\n server.run(host, port)\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "console app builder",
"version": "1.1.14",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "adf64c1a91d9a4ee6eea581c26d5b992ca11b6cc570020601a82243fe242cbca",
"md5": "e541b98775bcec76ef34e911a03cc02c",
"sha256": "e4e3d20db4059f12ac0d65ba76b59bfc371c3f32d76b0dcd28d7d21073e904d1"
},
"downloads": -1,
"filename": "qr_server-1.1.14.tar.gz",
"has_sig": false,
"md5_digest": "e541b98775bcec76ef34e911a03cc02c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 10942,
"upload_time": "2023-04-19T08:17:40",
"upload_time_iso_8601": "2023-04-19T08:17:40.116269Z",
"url": "https://files.pythonhosted.org/packages/ad/f6/4c1a91d9a4ee6eea581c26d5b992ca11b6cc570020601a82243fe242cbca/qr_server-1.1.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-19 08:17:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Kurush7",
"github_project": "qr_server",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "qr-server"
}