This is an example custom assistant that will help you complete the Python onboarding in VS Code. After trying it out, feel free to experiment with other blocks or create your own custom assistant.
Rule: Generate a reusable Flask authentication module with the following requirements:
1. Use Flask Blueprint to isolate auth routes (login, logout, register).
2. Implement User model with SQLAlchemy ORM:
- Fields: id (int, primary key), username (unique), email (unique), password_hash.
3. Use secure password hashing (e.g., Werkzeug's generate_password_hash and check_password_hash).
4. Provide WTForms form classes for login and registration, with validation:
- LoginForm: email, password.
- RegistrationForm: username, email, password, confirm password.
5. Implement routes for:
- /login: GET to display login form; POST to process login with validation.
- /logout: logs out user and redirects to login page.
- /register: GET to display registration form; POST to create new user with validation.
6. Use Flask-Login for user session management.
7. Render HTML templates stored under templates/auth/:
- login.html
- register.html
8. Structure the module as a Python package with:
- __init__.py to create Blueprint instance.
- models.py for User model.
- forms.py for WTForms classes.
- routes.py for route definitions.
9. Write clean, readable, and well-commented code.
10. Ensure all database interactions are via SQLAlchemy session.
11. Provide clear error handling for invalid inputs or failed logins.
12. Avoid hardcoding secrets or configurations; use config variables.
13. Make the module easily integrable by importing and registering the Blueprint in any Flask app.
Use Cargo to write a comprehensive suite of unit tests for this function
No Data configured
No MCP Servers configured