Override current user based on subdomain
Project description
# django-host-user-override
Overrides current user based on host prefix. For example any request to
```5.user.example.com``` becomes request as if you were logged in as
user with ID 5. Works only if you're actually logged in as superuser.
Also gives you big red banner on top of every page if your user is
overridden.
### Installing django-host-user-override
1. Install the package from PyPI: ```pip install django-host-user-override```
2. Add ```host_user_override``` to ```INSTALLED_APPS```:
```python
INSTALLED_APPS = [
...,
'host_user_override',
...,
]
```
3. Add ```HostUserOverrideMiddleware``` right after ```AuthenticationMiddleware```:
```python
MIDDLEWARE = [
...,
'django.contrib.auth.middleware.AuthenticationMiddleware',
'host_user_override.middleware.HostUserOverrideMiddleware',
...,
]
```
4. Update your ```settings.py``` file to support subdomains (don't forget about DNS as well):
```python
ALLOWED_HOSTS = ['.example.com']
SESSION_COOKIE_DOMAIN = '.example.com'
```
5. Set new ```change_form.html``` template in ```UserAdmin```:
```python
admin.site.unregister(User)
@admin.register(User)
class CustomUserAdmin(UserAdmin):
change_form_template = 'host_user_override/change_form.html'
```
## Usage
Open any non-superuser in Django Admin and press 'Login as multiuser' button.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
* Props to django-debug-toolbar team for HTML injection code
* Thanks to @dimoha for original idea
Overrides current user based on host prefix. For example any request to
```5.user.example.com``` becomes request as if you were logged in as
user with ID 5. Works only if you're actually logged in as superuser.
Also gives you big red banner on top of every page if your user is
overridden.
### Installing django-host-user-override
1. Install the package from PyPI: ```pip install django-host-user-override```
2. Add ```host_user_override``` to ```INSTALLED_APPS```:
```python
INSTALLED_APPS = [
...,
'host_user_override',
...,
]
```
3. Add ```HostUserOverrideMiddleware``` right after ```AuthenticationMiddleware```:
```python
MIDDLEWARE = [
...,
'django.contrib.auth.middleware.AuthenticationMiddleware',
'host_user_override.middleware.HostUserOverrideMiddleware',
...,
]
```
4. Update your ```settings.py``` file to support subdomains (don't forget about DNS as well):
```python
ALLOWED_HOSTS = ['.example.com']
SESSION_COOKIE_DOMAIN = '.example.com'
```
5. Set new ```change_form.html``` template in ```UserAdmin```:
```python
admin.site.unregister(User)
@admin.register(User)
class CustomUserAdmin(UserAdmin):
change_form_template = 'host_user_override/change_form.html'
```
## Usage
Open any non-superuser in Django Admin and press 'Login as multiuser' button.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
* Props to django-debug-toolbar team for HTML injection code
* Thanks to @dimoha for original idea
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-host-user-override-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d29938016653e63a5c70d773a2b3e0752c58bc8931bfb1da0ae5d5567490e09 |
|
MD5 | a04508577c5eb05cc2b114daf25f1eeb |
|
BLAKE2b-256 | 68a966e648737dc2125a78601715b42c3993e5e3d77e5e8389d95c2eebaecb7e |
Close
Hashes for django_host_user_override-0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 731f7adc859c5904e8701cb4ef2be8908d6419090f6b27b14d87e71f7001ae79 |
|
MD5 | a4fc81426c12e45ea6750294a34db9ae |
|
BLAKE2b-256 | 8c2ac87121da9366e475557281d03841627cd737d71e5a8afdf8afb9cb3cd404 |