django-nigerians-only


Namedjango-nigerians-only JSON
Version 1.0 PyPI version JSON
download
home_pagehttps://github.com/Afeez1131/nigerians-only
SummaryDjango Nigerians Only is a third application that allows developers to restrict access to their applications to only Nigerian users.
upload_time2024-09-09 19:10:30
maintainerNone
docs_urlNone
authorattr: nigerian_only.__author__
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Django Nigerians Only

**Django Nigerians Only** is a third-party Django application that restricts access to Django applications to only Nigerian users. It can be extended to other countries with a few simple steps.

## Requirements

- Django >= 4.1
- geoip2 >= 4.8.0

## Installation

1. **Install Nigerian Only** using pip:

   ```bash
   pip install django-nigerians-only
   ```

2. **Add `'nigerian_only'` to `INSTALLED_APPS`** in your Django project's `settings.py`:

   ```python
   INSTALLED_APPS = [
       ...
       'nigerian_only',
   ]
   ```

3. **Add the middleware** to `MIDDLEWARE` in `settings.py`:

   ```python
   MIDDLEWARE = [
       ...
       'nigerian_only.middleware.NigeriansOnlyMiddleware',
   ]
   ```

4. **Whitelist allowed countries** by setting the list of allowed countries using ISO Alpha-2 country codes. [Find Country Codes Alpha-2 & Alpha-3 here](https://www.iban.com/country-codes).

   ```python
   WHITELISTED_COUNTRIES = ["NG"]  # Example: "NG" for Nigeria
   ```

5. **Download the GeoIP2 database** from [MaxMind](https://dev.maxmind.com/geoip/geoip2/geolite2/) and set the path in `settings.py`. You can read more on setting up GeoIP for Django [here](https://docs.djangoproject.com/en/5.1/ref/contrib/gis/geoip2/).

   ```python
   GEOIP_PATH = "path/to/GeoLite2-Country.mmdb"
   ```

## Usage

Once the above steps are completed, the middleware will restrict access to users from the whitelisted countries.

- **Example Usage with Middleware**: The middleware automatically restricts access for all views.

- **Restrict Access Per View**: You can also restrict access on a per-view basis using the `whitelisted_country_only` decorator:

   ```python
   from django.http import HttpResponse
   from nigerian_only.decorators import whitelisted_country_only

   @whitelisted_country_only
   def restricted_view(request):
       return HttpResponse("This is a restricted view to only whitelisted countries.")
   ```

## Important Notes

- **Access will not be restricted** if any of the steps mentioned above is not completed correctly.
- **Development Environment**: During development, the default IP address is `127.0.0.1`, which cannot determine the user's country. You need to set `WHITELISTED_IPS` in `settings.py` to allow access during development:

   ```python
   WHITELISTED_IPS = ['127.0.0.1']
   ```

- **Testing**: To test the middleware, use a VPN to change your location to one of the specified countries or use a valid IP address to determine the user's country.

## Example Project

You can check out this app with a basic setup example of the package here: [Django Nigeria Only Example](https://github.com/Afeez1131/django-nigerians-only-example).

## Contributing

Contributions are welcome and appreciated! Follow these steps to contribute:

1. Fork the repository.
2. Create a new branch for your feature or bug fix.
3. Make changes and write tests to ensure your changes don't break anything.
4. Push the changes to your fork.
5. Submit a pull request.

## License

This project is licensed under the MIT License - see the `LICENSE` file for details.

## Developed by Afeez Lawal

### Contact Me:

- **Email**: [lawalafeez052@gmail.com](mailto:lawalafeez052@gmail.com)
- **LinkedIn**: [LinkedIn](https://www.linkedin.com/in/lawal-afeez/)
- **GitHub**: [GitHub](https://github.com/Afeez31)

---

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Afeez1131/nigerians-only",
    "name": "django-nigerians-only",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "attr: nigerian_only.__author__",
    "author_email": "lawalafeez052@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/11/a5/f4782a835e525511c4866b8c44599a1d63c5175e9a0d71157573dfb363ff/django_nigerians_only-1.0.tar.gz",
    "platform": null,
    "description": "\n# Django Nigerians Only\n\n**Django Nigerians Only** is a third-party Django application that restricts access to Django applications to only Nigerian users. It can be extended to other countries with a few simple steps.\n\n## Requirements\n\n- Django >= 4.1\n- geoip2 >= 4.8.0\n\n## Installation\n\n1. **Install Nigerian Only** using pip:\n\n   ```bash\n   pip install django-nigerians-only\n   ```\n\n2. **Add `'nigerian_only'` to `INSTALLED_APPS`** in your Django project's `settings.py`:\n\n   ```python\n   INSTALLED_APPS = [\n       ...\n       'nigerian_only',\n   ]\n   ```\n\n3. **Add the middleware** to `MIDDLEWARE` in `settings.py`:\n\n   ```python\n   MIDDLEWARE = [\n       ...\n       'nigerian_only.middleware.NigeriansOnlyMiddleware',\n   ]\n   ```\n\n4. **Whitelist allowed countries** by setting the list of allowed countries using ISO Alpha-2 country codes. [Find Country Codes Alpha-2 & Alpha-3 here](https://www.iban.com/country-codes).\n\n   ```python\n   WHITELISTED_COUNTRIES = [\"NG\"]  # Example: \"NG\" for Nigeria\n   ```\n\n5. **Download the GeoIP2 database** from [MaxMind](https://dev.maxmind.com/geoip/geoip2/geolite2/) and set the path in `settings.py`. You can read more on setting up GeoIP for Django [here](https://docs.djangoproject.com/en/5.1/ref/contrib/gis/geoip2/).\n\n   ```python\n   GEOIP_PATH = \"path/to/GeoLite2-Country.mmdb\"\n   ```\n\n## Usage\n\nOnce the above steps are completed, the middleware will restrict access to users from the whitelisted countries.\n\n- **Example Usage with Middleware**: The middleware automatically restricts access for all views.\n\n- **Restrict Access Per View**: You can also restrict access on a per-view basis using the `whitelisted_country_only` decorator:\n\n   ```python\n   from django.http import HttpResponse\n   from nigerian_only.decorators import whitelisted_country_only\n\n   @whitelisted_country_only\n   def restricted_view(request):\n       return HttpResponse(\"This is a restricted view to only whitelisted countries.\")\n   ```\n\n## Important Notes\n\n- **Access will not be restricted** if any of the steps mentioned above is not completed correctly.\n- **Development Environment**: During development, the default IP address is `127.0.0.1`, which cannot determine the user's country. You need to set `WHITELISTED_IPS` in `settings.py` to allow access during development:\n\n   ```python\n   WHITELISTED_IPS = ['127.0.0.1']\n   ```\n\n- **Testing**: To test the middleware, use a VPN to change your location to one of the specified countries or use a valid IP address to determine the user's country.\n\n## Example Project\n\nYou can check out this app with a basic setup example of the package here: [Django Nigeria Only Example](https://github.com/Afeez1131/django-nigerians-only-example).\n\n## Contributing\n\nContributions are welcome and appreciated! Follow these steps to contribute:\n\n1. Fork the repository.\n2. Create a new branch for your feature or bug fix.\n3. Make changes and write tests to ensure your changes don't break anything.\n4. Push the changes to your fork.\n5. Submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License - see the `LICENSE` file for details.\n\n## Developed by Afeez Lawal\n\n### Contact Me:\n\n- **Email**: [lawalafeez052@gmail.com](mailto:lawalafeez052@gmail.com)\n- **LinkedIn**: [LinkedIn](https://www.linkedin.com/in/lawal-afeez/)\n- **GitHub**: [GitHub](https://github.com/Afeez31)\n\n---\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django Nigerians Only is a third application that allows developers to restrict access to their applications to only Nigerian users.",
    "version": "1.0",
    "project_urls": {
        "Documentation": "https://github.com/Afeez1131/nigerians-only",
        "Homepage": "https://github.com/Afeez1131/nigerians-only",
        "Source Code": "https://github.com/Afeez1131/nigerians-only"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "80e47c80cd382c438cb969709d34b6d07b6044ebcc96ca8cda5eac37ecd645ee",
                "md5": "978002a246c19aaa7205a29294db1724",
                "sha256": "06f3aae37e23fd83c2695fa7d4fb986436bc1becf1079e37b75839e4a58f8491"
            },
            "downloads": -1,
            "filename": "django_nigerians_only-1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "978002a246c19aaa7205a29294db1724",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7787,
            "upload_time": "2024-09-09T19:10:28",
            "upload_time_iso_8601": "2024-09-09T19:10:28.356886Z",
            "url": "https://files.pythonhosted.org/packages/80/e4/7c80cd382c438cb969709d34b6d07b6044ebcc96ca8cda5eac37ecd645ee/django_nigerians_only-1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11a5f4782a835e525511c4866b8c44599a1d63c5175e9a0d71157573dfb363ff",
                "md5": "64054876a25d900cd4da1f568b955587",
                "sha256": "2ea59683ab85965c44b3e49f7e248adde85cc9ea91eccca5da74142129072a13"
            },
            "downloads": -1,
            "filename": "django_nigerians_only-1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "64054876a25d900cd4da1f568b955587",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 6614,
            "upload_time": "2024-09-09T19:10:30",
            "upload_time_iso_8601": "2024-09-09T19:10:30.239642Z",
            "url": "https://files.pythonhosted.org/packages/11/a5/f4782a835e525511c4866b8c44599a1d63c5175e9a0d71157573dfb363ff/django_nigerians_only-1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-09 19:10:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Afeez1131",
    "github_project": "nigerians-only",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "django-nigerians-only"
}
        
Elapsed time: 0.43630s