Package: django-auth-audit
Make your authentication logs more easy with django-auth-auditPlease notedjango-auth-auditstill an experimental project that originated as a feature in one of my professional projects. Due to the specific requirements and lack of existing GitHub repositories targeting this particular situation, I decided to create it as a separate project. As a result, the app is still in its early stages and may undergo frequent updates and improvements. Feedback and contributions are welcome.Introductiondjango-auth-auditis a Django reusable app that provides functionality for tracking user authentication events, such as logins,logouts,password rest rate limit ...
It allows you to define custom mixins that override specific CRUD methods in your target class, send signals, and handle the flow back to your target class. Additionally, django-auth-audit includes a pre-defined mixins,that can be used to send signals and create authentication logs.InstallationTo installdjango-auth-audit, follow these steps:Ensure you have Django installed in your project. If not, you can install it using pip:pipinstalldjangoDownload thedjango-auth-auditpackage from the GitHub repository or install it using pip:pipinstalldjango-auth-auditAdddjango-auth-auditto the INSTALLED_APPS setting in your Django project's settings.py file:INSTALLED_APPS=[...'django-auth-audit',...]Run the database migrations to create the necessary tables for the app:pythonmanage.pymigratedjango-auth-auditUsagedjango-auth-auditallows you to create custom mixins that override specific CRUD methods in your target class, send signals, and handle the flow back to your target class.
Here's an example:fromdj_auth_audit.mixinsimportFailedResetEmailSignalMixinclassCustomPasswordResetView(FailedResetEmailSignalMixin,PasswordResetView):class_name='PasswordResetView'serializer_class=CustomPasswordResetSerializerthrottle_scope='reset_password_rate'In this example, theCustomPasswordResetViewclass inherits fromFailedResetEmailSignalMixinandPasswordResetView. TheFailedResetEmailSignalMixinsends a signal and creates an authentication log in the database, indicating the time of the sent reset email and the user who requested the password reset. If the user reaches the rate limit, another signal is triggered to indicate that the user has exceeded the password reset rate.The FailedResetEmailSignalMixin is hooked with the POST and throttled methods, which are typically defined in the target class. To use this mixin, you need to define theclass_nameattribute in the subclass alongside with the self.user to define the actor.Notedjango-auth-audithas a built-in mixin for all basic authentication logs you will need ,inclusing but not limited to :Login,Logout,password change,password reset,verfication email... and if you define a throttle scope on the subclass , you will get rate limit signal the user have exceeded the allowed request rate.You can also define your own mixin by inheriting fromAbstractSignalMixinin themixin.pyfile.Note: TheFailedResetEmailSignalMixinor any other mixin will raise an exception if:class_nameis not defined.The target class doesn't have any of the required methods for sending requests(POST,GET...)Theself.useris not defined.
Please refer tomixin.pyfor more information on creating custom mixins and using the provided mixins.ContributingIf you'd like to contribute to this project, please follow these guidelines:Fork the repository on GitHub.
Create a new branch from the master branch for your feature or bug fix.
Make your changes and ensure they are properly tested.
Commit your changes with clear and descriptive commit messages.
Push your branch to your forked repository.
Submit a pull request to the master branch of the this repository.
Please refer to the Contribution Guidelines for more information.Licensedjango-auth-auditis released under the MIT License. See the LICENSE file for more details.SupportIf you encounter any issues or have questions, please open an issue on the GitHub repository.History0.1.0 (2023-07-16)
++++++++++++++++++First release on PyPI.