{"id":28718762,"url":"https://github.com/mscbuild/user_story_use-case","last_synced_at":"2026-04-30T11:35:17.713Z","repository":{"id":298764253,"uuid":"1001067244","full_name":"mscbuild/User_story_use-case","owner":"mscbuild","description":"Flask API with MySQL and JWT Authentication","archived":false,"fork":false,"pushed_at":"2025-06-12T19:57:28.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-12T20:57:11.053Z","etag":null,"topics":["case","flask","jwt-authentication","mysql","mysql-database","python","storybook","user","user-interface"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mscbuild.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-12T19:06:47.000Z","updated_at":"2025-06-12T19:59:36.000Z","dependencies_parsed_at":"2025-06-12T20:57:58.901Z","dependency_job_id":"30ee8c3b-36c9-4d1c-b2a0-e01aee44c081","html_url":"https://github.com/mscbuild/User_story_use-case","commit_stats":null,"previous_names":["mscbuild/user_story_use-case"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mscbuild/User_story_use-case","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscbuild%2FUser_story_use-case","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscbuild%2FUser_story_use-case/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscbuild%2FUser_story_use-case/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscbuild%2FUser_story_use-case/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mscbuild","download_url":"https://codeload.github.com/mscbuild/User_story_use-case/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscbuild%2FUser_story_use-case/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259924677,"owners_count":22932782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["case","flask","jwt-authentication","mysql","mysql-database","python","storybook","user","user-interface"],"created_at":"2025-06-15T05:03:57.020Z","updated_at":"2026-04-30T11:35:17.361Z","avatar_url":"https://github.com/mscbuild.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔐 Flask API with MySQL and JWT Authentication\n  ![](https://komarev.com/ghpvc/?username=mscbuild) \n ![](https://img.shields.io/github/license/mscbuild/e-learning) \n  ![](https://img.shields.io/github/repo-size/mscbuild/e-learning)\n![](https://img.shields.io/badge/PRs-Welcome-green)\n![](https://img.shields.io/badge/code%20style-sql/python-green)\n![](https://img.shields.io/github/stars/mscbuild)\n![](https://img.shields.io/badge/Topic-Github-lighred)\n![](https://img.shields.io/website?url=https%3A%2F%2Fgithub.com%2Fmscbuild)\n\nThis is a basic Flask application that demonstrates how to integrate **MySQL**, **Flask-SQLAlchemy** for database interaction, and **JWT (JSON Web Token)** for authentication. The application allows users to register, log in, and retrieve information about their subscription plans based on their roles.\n\n ## 🛠️ Installation\n\n1. Clone the repository to your local machine:\n ~~~bash\n   git clone https://github.com/mscbuild/User_story_use-case.git\n ~~~\n\n2 Create a virtual environment (optional but recommended):\n~~~bash\npython -m venv venv\n~~~\n\n3.Activate the virtual environment:\n\n- Windows:\n~~~bash\nvenv\\Scripts\\activate\n~~~\n- MacOS/Linux:\n~~~bash\n  source venv/bin/activate\n~~~\n4.Install the required dependencies:\n~~~bash\npip install -r requirements.txt\n~~~\n5.You will need a MySQL database for the application. Follow the steps below to set it up.\n\n# ✅ Setup MySQL Database\n\n- Install MySQL on your local machine if you haven't already. You can download it from here.\n\n- Create a database named flask_db (or any name you prefer) and the following tables:\n\n 3. Update the SQLALCHEMY_DATABASE_URI in app.py to reflect your MySQL credentials:\n~~~bash\napp.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://username:password@localhost/flask_db'\n~~~\n4. Run the application.\n\n# 💼 Project Structure\n~~~bash\nflask-mysql-jwt/\n│\n├── app.py                    # Main application file\n├── requirements.txt           # Python dependencies\n├── README.md                  # Project documentation\n└── venv/                      # Virtual environment (optional)\n~~~\n\n# 🌐 API Endpoints\n\n***Register***\n\n***POST /register***\n\nRegisters a new user. The user will be added to the database with a hashed password.\n\n***Request Body:***\n~~~bash\n{\n    \"username\": \"john_doe\",\n    \"password\": \"password123\",\n    \"role\": \"premium\"\n}\n~~~\n***Response:***\n~~~bash\n{\n    \"message\": \"User registered successfully\"\n}\n~~~\n***Login***\n\n***POST /login***\n\nAuthenticates the user and generates a JWT access token.\n\n***Request Body:***\n~~~bash\n{\n    \"username\": \"john_doe\",\n    \"password\": \"password123\"\n}\n~~~\n***Response:***\n~~~bash\n{\n    \"access_token\": \"your_jwt_token\"\n}\n~~~\n***Get Tariff***\n\n***GET /tariffs/{user_id}***\n\nReturns the current subscription plan for the user, based on their role. This endpoint requires JWT authentication.\n\n***Request Header:***\n~~~bash\nAuthorization: Bearer your_jwt_token\n~~~\n***Response:***\n~~~bash\n{\n    \"userId\": 1,\n    \"tariffName\": \"Premium Plan\",\n    \"cost\": 999.99,\n    \"currency\": \"RUB\",\n    \"validity\": \"1 month\",\n    \"features\": [\n        \"Unlimited calls\",\n        \"10 GB internet\",\n        \"Free SMS\"\n    ]\n}\n~~~\n# ✨ Running the Application\n\n- Make sure MySQL is running and your database is set up as described above.\n\n- Run the Flask application:\n  ~~~bash\n  python app.py\n~~~\n- The application will be running at http://127.0.0.1:5000/.\n\n- Use an API testing tool like Postman or cURL to interact with the API.\n\n# 🔀 Example: Register a User\n\n***POST /register***\n\n~~~bash\ncurl -X POST http://127.0.0.1:5000/register -H \"Content-Type: application/json\" -d '{\"username\": \"john_doe\", \"password\": \"password123\", \"role\": \"premium\"}'\n~~~\n\n# 👤 Example: Login\n\n***POST /login***\n~~~bash\ncurl -X POST http://127.0.0.1:5000/login -H \"Content-Type: application/json\" -d '{\"username\": \"john_doe\", \"password\": \"password123\"}'\n~~~\n\n# 👥 Example: Get Tariff\n\n***GET /tariffs/1***\n~~~bash\ncurl -X GET http://127.0.0.1:5000/tariffs/1 -H \"Authorization: Bearer your_jwt_token\"\n~~~\n\n# 📢 Contributing\n\nWe welcome contributions! If you have suggestions, improvements, or bug fixes, feel free to open an issue or submit a pull request.\n\n- Fork the repository.\n\n- Create a new branch (git checkout -b feature-name).\n\n- Commit your changes (git commit -am 'Add new feature').\n\n- Push to the branch (git push origin feature-name).\n\n- Open a pull request.\n\n# 📜 License\n\nThis project is licensed under the MIT License - see the LICENSE file for details. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscbuild%2Fuser_story_use-case","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmscbuild%2Fuser_story_use-case","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscbuild%2Fuser_story_use-case/lists"}