django-solomon 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. django_solomon-0.1.2/.forgejo/workflows/release.yml +34 -0
  2. django_solomon-0.1.2/.forgejo/workflows/tests.yml +45 -0
  3. django_solomon-0.1.2/.gitignore +170 -0
  4. django_solomon-0.1.2/.pre-commit-config.yaml +45 -0
  5. django_solomon-0.1.2/.readthedocs.yml +16 -0
  6. django_solomon-0.1.2/CHANGELOG.md +1 -0
  7. django_solomon-0.1.2/LICENSE +21 -0
  8. django_solomon-0.1.2/PKG-INFO +198 -0
  9. django_solomon-0.1.2/README.md +148 -0
  10. django_solomon-0.1.2/docs/changelog.md +6 -0
  11. django_solomon-0.1.2/docs/index.md +6 -0
  12. django_solomon-0.1.2/docs/requirements.txt +2 -0
  13. django_solomon-0.1.2/justfile +57 -0
  14. django_solomon-0.1.2/mkdocs.yml +51 -0
  15. django_solomon-0.1.2/pyproject.toml +137 -0
  16. django_solomon-0.1.2/src/django_solomon/__init__.py +3 -0
  17. django_solomon-0.1.2/src/django_solomon/admin.py +45 -0
  18. django_solomon-0.1.2/src/django_solomon/apps.py +6 -0
  19. django_solomon-0.1.2/src/django_solomon/backends.py +61 -0
  20. django_solomon-0.1.2/src/django_solomon/config.py +23 -0
  21. django_solomon-0.1.2/src/django_solomon/forms.py +12 -0
  22. django_solomon-0.1.2/src/django_solomon/locale/de/LC_MESSAGES/django.po +27 -0
  23. django_solomon-0.1.2/src/django_solomon/locale/en/LC_MESSAGES/django.po +27 -0
  24. django_solomon-0.1.2/src/django_solomon/management/__init__.py +0 -0
  25. django_solomon-0.1.2/src/django_solomon/management/commands/__init__.py +0 -0
  26. django_solomon-0.1.2/src/django_solomon/migrations/0001_initial.py +47 -0
  27. django_solomon-0.1.2/src/django_solomon/migrations/__init__.py +0 -0
  28. django_solomon-0.1.2/src/django_solomon/models.py +133 -0
  29. django_solomon-0.1.2/src/django_solomon/py.typed +0 -0
  30. django_solomon-0.1.2/src/django_solomon/templates/django_solomon/base/invalid_magic_link.html +16 -0
  31. django_solomon-0.1.2/src/django_solomon/templates/django_solomon/base/login_form.html +17 -0
  32. django_solomon-0.1.2/src/django_solomon/templates/django_solomon/base/magic_link_sent.html +12 -0
  33. django_solomon-0.1.2/src/django_solomon/templates/django_solomon/email/magic_link.mjml +42 -0
  34. django_solomon-0.1.2/src/django_solomon/templates/django_solomon/email/magic_link.txt +14 -0
  35. django_solomon-0.1.2/src/django_solomon/urls.py +23 -0
  36. django_solomon-0.1.2/src/django_solomon/utilities.py +81 -0
  37. django_solomon-0.1.2/src/django_solomon/views.py +141 -0
  38. django_solomon-0.1.2/tests/.gitignore +0 -0
  39. django_solomon-0.1.2/tests/__init__.py +0 -0
  40. django_solomon-0.1.2/tests/conftest.py +55 -0
  41. django_solomon-0.1.2/tests/settings.py +60 -0
  42. django_solomon-0.1.2/tests/templates/base.html +10 -0
  43. django_solomon-0.1.2/tests/test_admin.py +228 -0
  44. django_solomon-0.1.2/tests/test_backends.py +167 -0
  45. django_solomon-0.1.2/tests/test_config.py +81 -0
  46. django_solomon-0.1.2/tests/test_forms.py +127 -0
  47. django_solomon-0.1.2/tests/test_models.py +216 -0
  48. django_solomon-0.1.2/tests/test_urls.py +5 -0
  49. django_solomon-0.1.2/tests/test_utilities.py +339 -0
  50. django_solomon-0.1.2/tests/test_views.py +305 -0
  51. django_solomon-0.1.2/tox.ini +25 -0
  52. django_solomon-0.1.2/uv.lock +410 -0
@@ -0,0 +1,34 @@
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*' # Trigger on tags starting with 'v'
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ with:
14
+ fetch-depth: 0 # Required for hatch-vcs to determine version from tags
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v4
18
+ with:
19
+ python-version: '3.10'
20
+
21
+ - name: Install uv
22
+ run: |
23
+ python -m pip install --upgrade pip
24
+ python -m pip install uv
25
+
26
+ - name: Run tests
27
+ run: |
28
+ python -m pip install tox tox-uv
29
+ tox -e django52-py310 --parallel auto
30
+
31
+ - name: Build and publish to PyPI
32
+ run: |
33
+ uv build
34
+ uv publish --token ${{ secrets.PYPI_TOKEN }}
@@ -0,0 +1,45 @@
1
+ name: Run Tests with tox and tox-uv
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ include:
16
+ - python-version: '3.10'
17
+ django-versions: 'django40,django41,django42,django50,django51,django52'
18
+ - python-version: '3.11'
19
+ django-versions: 'django41,django42,django50,django51,django52'
20
+ - python-version: '3.12'
21
+ django-versions: 'django42,django50,django51,django52'
22
+ - python-version: '3.13'
23
+ django-versions: 'django51,django52'
24
+
25
+ steps:
26
+ - uses: actions/checkout@v3
27
+
28
+ - name: Set up Python ${{ matrix.python-version }}
29
+ uses: actions/setup-python@v4
30
+ with:
31
+ python-version: ${{ matrix.python-version }}
32
+
33
+ - name: Install dependencies
34
+ run: |
35
+ python -m pip install --upgrade pip
36
+ python -m pip install tox tox-uv
37
+
38
+ - name: Test with tox and tox-uv
39
+ run: |
40
+ # Convert Python version to tox format (e.g., 3.10 -> py310)
41
+ PY_VERSION=py$(echo ${{ matrix.python-version }} | tr -d '.')
42
+
43
+ # Run tox with tox-uv for faster dependency resolution
44
+ # The --uv flag is automatically used when tox-uv is installed
45
+ tox -e $(echo ${{ matrix.django-versions }} | tr ',' '\n' | xargs -I{} echo {}-$PY_VERSION | tr '\n' ',') --parallel auto
@@ -0,0 +1,170 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3*
62
+ static/
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ .idea/
165
+
166
+ # VScode
167
+ .vscode/
168
+
169
+ # macOS
170
+ .DS_Store
@@ -0,0 +1,45 @@
1
+ default_language_version:
2
+ python: python3.9
3
+
4
+ repos:
5
+ - repo: https://github.com/pre-commit/pre-commit-hooks
6
+ rev: v5.0.0
7
+ hooks:
8
+ - id: trailing-whitespace
9
+ - id: end-of-file-fixer
10
+ - id: check-yaml
11
+ - id: check-toml
12
+ - id: check-added-large-files
13
+ - id: check-merge-conflict
14
+ - id: check-case-conflict
15
+ - id: check-symlinks
16
+ - id: check-json
17
+
18
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
19
+ rev: "v0.11.6"
20
+ hooks:
21
+ - id: ruff
22
+ - id: ruff-format
23
+
24
+ - repo: https://github.com/asottile/pyupgrade
25
+ rev: v3.19.1
26
+ hooks:
27
+ - id: pyupgrade
28
+ args: [--py310-plus]
29
+
30
+ - repo: https://github.com/adamchainz/django-upgrade
31
+ rev: "1.24.0"
32
+ hooks:
33
+ - id: django-upgrade
34
+ args: [--target-version, "4.2"]
35
+
36
+ - repo: https://github.com/adamchainz/djade-pre-commit
37
+ rev: "1.4.0"
38
+ hooks:
39
+ - id: djade
40
+ args: [--target-version, "4.2"]
41
+
42
+ - repo: https://github.com/owenlamont/uv-secure
43
+ rev: 0.9.0
44
+ hooks:
45
+ - id: uv-secure
@@ -0,0 +1,16 @@
1
+ # Required
2
+ version: 2
3
+
4
+ # Set the version of Python and other tools you might need
5
+ build:
6
+ os: ubuntu-22.04
7
+ tools:
8
+ python: "3.12"
9
+
10
+ mkdocs:
11
+ configuration: mkdocs.yml
12
+
13
+ # Optionally declare the Python requirements required to build your docs
14
+ python:
15
+ install:
16
+ - requirements: docs/requirements.txt
@@ -0,0 +1 @@
1
+ # Changelog
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Oliver Andrich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-solomon
3
+ Version: 0.1.2
4
+ Project-URL: Home, https://django-solomon.rtfd.io/
5
+ Project-URL: Documentation, https://django-solomon.rtfd.io/
6
+ Project-URL: Repository, https://codeberg.org/oliverandrich/django-solomon
7
+ Author-email: Oliver Andrich <oliver@andrich.me>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2025 Oliver Andrich
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: django
31
+ Classifier: Development Status :: 3 - Alpha
32
+ Classifier: Environment :: Web Environment
33
+ Classifier: Framework :: Django :: 4.2
34
+ Classifier: Framework :: Django :: 5.0
35
+ Classifier: Framework :: Django :: 5.1
36
+ Classifier: Framework :: Django :: 5.2
37
+ Classifier: Intended Audience :: Developers
38
+ Classifier: License :: OSI Approved :: MIT License
39
+ Classifier: Operating System :: OS Independent
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Programming Language :: Python :: 3.13
44
+ Classifier: Topic :: Software Development :: Libraries
45
+ Classifier: Topic :: Utilities
46
+ Requires-Python: >=3.10
47
+ Requires-Dist: django>=4.2
48
+ Requires-Dist: mjml-python>=1.3.5
49
+ Description-Content-Type: text/markdown
50
+
51
+ # django-solomon
52
+
53
+ [![PyPI version](https://img.shields.io/pypi/v/django-solomon.svg)](https://pypi.org/project/django-solomon/)
54
+ [![Python versions](https://img.shields.io/pypi/pyversions/django-solomon.svg)](https://pypi.org/project/django-solomon/)
55
+ [![Django versions](https://img.shields.io/pypi/djversions/django-solomon.svg)](https://pypi.org/project/django-solomon/)
56
+ [![Documentation Status](https://readthedocs.org/projects/django-solomon/badge/?version=latest)](https://django-solomon.rtfd.io/en/latest/?badge=latest)
57
+
58
+ A Django app for passwordless authentication using magic links.
59
+
60
+ ## Features
61
+
62
+ - Passwordless authentication using magic links sent via email
63
+ - Configurable link expiration time
64
+ - Blacklist functionality to block specific email addresses
65
+ - Support for auto-creating users when they request a magic link
66
+ - Customizable templates for emails and pages
67
+ - Compatible with Django's authentication system
68
+
69
+ ## Installation
70
+
71
+ ```bash
72
+ pip install django-solomon
73
+ ```
74
+
75
+ ## Configuration
76
+
77
+ 1. Add `django_solomon` to your `INSTALLED_APPS` in your Django settings:
78
+
79
+ ```python
80
+ INSTALLED_APPS = [
81
+ # ...
82
+ 'django_solomon',
83
+ # ...
84
+ ]
85
+ ```
86
+
87
+ 2. Add the authentication backend to your settings:
88
+
89
+ ```python
90
+ AUTHENTICATION_BACKENDS = [
91
+ 'django_solomon.backends.MagicLinkBackend',
92
+ 'django.contrib.auth.backends.ModelBackend', # Keep the default backend
93
+ ]
94
+ ```
95
+
96
+ 3. Include the django-solomon URLs in your project's `urls.py`:
97
+
98
+ ```python
99
+ from django.urls import include, path
100
+
101
+ urlpatterns = [
102
+ # ...
103
+ path('auth/', include('django_solomon.urls')),
104
+ # ...
105
+ ]
106
+ ```
107
+
108
+ 4. Set the login URL in your settings to use django-solomon's login view:
109
+
110
+ ```python
111
+ LOGIN_URL = 'django_solomon:login'
112
+ ```
113
+
114
+ This ensures that when users need to authenticate, they'll be redirected to the magic link login page.
115
+
116
+ 5. Configure your email settings to ensure emails can be sent:
117
+
118
+ ```python
119
+ EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
120
+ EMAIL_HOST = 'smtp.example.com'
121
+ EMAIL_PORT = 587
122
+ EMAIL_USE_TLS = True
123
+ EMAIL_HOST_USER = 'your-email@example.com'
124
+ EMAIL_HOST_PASSWORD = 'your-password'
125
+ DEFAULT_FROM_EMAIL = 'your-email@example.com'
126
+ ```
127
+
128
+ ## Settings
129
+
130
+ django-solomon provides several settings that you can customize in your Django settings file:
131
+
132
+ | Setting | Default | Description |
133
+ |---------------------------------------|-------------------------------------------------|----------------------------------------------------------------------------------------|
134
+ | `SOLOMON_LINK_EXPIRATION` | `300` | The expiration time for magic links in seconds |
135
+ | `SOLOMON_ONLY_ONE_LINK_ALLOWED` | `True` | If enabled, only one active magic link is allowed per user |
136
+ | `SOLOMON_CREATE_USER_IF_NOT_FOUND` | `False` | If enabled, creates a new user when a magic link is requested for a non-existent email |
137
+ | `SOLOMON_LOGIN_REDIRECT_URL` | `settings.LOGIN_REDIRECT_URL` | The URL to redirect to after successful authentication |
138
+ | `SOLOMON_ALLOW_ADMIN_LOGIN` | `True` | If enabled, allows superusers to log in using magic links |
139
+ | `SOLOMON_ALLOW_STAFF_LOGIN` | `True` | If enabled, allows staff users to log in using magic links |
140
+ | `SOLOMON_MAIL_TEXT_TEMPLATE` | `"django_solomon/email/magic_link.txt"` | The template to use for plain text magic link emails |
141
+ | `SOLOMON_MAIL_MJML_TEMPLATE` | `"django_solomon/email/magic_link.mjml"` | The template to use for HTML magic link emails (MJML format) |
142
+ | `SOLOMON_LOGIN_FORM_TEMPLATE` | `"django_solomon/base/login_form.html"` | The template to use for the login form page |
143
+ | `SOLOMON_INVALID_MAGIC_LINK_TEMPLATE` | `"django_solomon/base/invalid_magic_link.html"` | The template to use for the invalid magic link page |
144
+ | `SOLOMON_MAGIC_LINK_SENT_TEMPLATE` | `"django_solomon/base/magic_link_sent.html"` | The template to use for the magic link sent confirmation page |
145
+
146
+ ## Usage
147
+
148
+ ### Basic Usage
149
+
150
+ 1. Direct users to the magic link request page at `/auth/magic-link/`
151
+ 2. Users enter their email address
152
+ 3. A magic link is sent to their email
153
+ 4. Users click the link in their email
154
+ 5. They are authenticated and redirected to the success URL
155
+
156
+ ### Template Customization
157
+
158
+ You can override the default templates by creating your own versions in your project:
159
+
160
+ - `django_solomon/login_form.html` - The form to request a magic link
161
+ - `django_solomon/magic_link_sent.html` - The confirmation page after a magic link is sent
162
+ - `django_solomon/invalid_magic_link.html` - The error page for invalid magic links
163
+ - `django_solomon/email/magic_link.txt` - The plain text email template for the magic link
164
+ - `django_solomon/email/magic_link.mjml` - The HTML email template for the magic link (in MJML format)
165
+
166
+ Alternatively, you can specify custom templates using the settings variables:
167
+
168
+ - `SOLOMON_LOGIN_FORM_TEMPLATE` - Custom template for the login form
169
+ - `SOLOMON_MAGIC_LINK_SENT_TEMPLATE` - Custom template for the confirmation page
170
+ - `SOLOMON_INVALID_MAGIC_LINK_TEMPLATE` - Custom template for the error page
171
+ - `SOLOMON_MAIL_TEXT_TEMPLATE` - Custom template for the plain text email
172
+ - `SOLOMON_MAIL_MJML_TEMPLATE` - Custom template for the HTML email (MJML format)
173
+
174
+ ### Programmatic Usage
175
+
176
+ You can also use django-solomon programmatically in your views:
177
+
178
+ ```python
179
+ from django.contrib.auth import authenticate, login
180
+ from django_solomon.models import MagicLink
181
+
182
+ # Create a magic link for a user
183
+ magic_link = MagicLink.objects.create_for_user(user)
184
+
185
+ # Authenticate a user with a token
186
+ user = authenticate(request=request, token=token)
187
+ if user:
188
+ login(request, user)
189
+ ```
190
+
191
+ ## License
192
+
193
+ This software is licensed under [MIT license](./LICENSE).
194
+
195
+ ## Contributing
196
+
197
+ Contributions are welcome! Please feel free to submit a Pull Request
198
+ on [Codeberg](https://codeberg.org/oliverandrich/django-solomon).
@@ -0,0 +1,148 @@
1
+ # django-solomon
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/django-solomon.svg)](https://pypi.org/project/django-solomon/)
4
+ [![Python versions](https://img.shields.io/pypi/pyversions/django-solomon.svg)](https://pypi.org/project/django-solomon/)
5
+ [![Django versions](https://img.shields.io/pypi/djversions/django-solomon.svg)](https://pypi.org/project/django-solomon/)
6
+ [![Documentation Status](https://readthedocs.org/projects/django-solomon/badge/?version=latest)](https://django-solomon.rtfd.io/en/latest/?badge=latest)
7
+
8
+ A Django app for passwordless authentication using magic links.
9
+
10
+ ## Features
11
+
12
+ - Passwordless authentication using magic links sent via email
13
+ - Configurable link expiration time
14
+ - Blacklist functionality to block specific email addresses
15
+ - Support for auto-creating users when they request a magic link
16
+ - Customizable templates for emails and pages
17
+ - Compatible with Django's authentication system
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install django-solomon
23
+ ```
24
+
25
+ ## Configuration
26
+
27
+ 1. Add `django_solomon` to your `INSTALLED_APPS` in your Django settings:
28
+
29
+ ```python
30
+ INSTALLED_APPS = [
31
+ # ...
32
+ 'django_solomon',
33
+ # ...
34
+ ]
35
+ ```
36
+
37
+ 2. Add the authentication backend to your settings:
38
+
39
+ ```python
40
+ AUTHENTICATION_BACKENDS = [
41
+ 'django_solomon.backends.MagicLinkBackend',
42
+ 'django.contrib.auth.backends.ModelBackend', # Keep the default backend
43
+ ]
44
+ ```
45
+
46
+ 3. Include the django-solomon URLs in your project's `urls.py`:
47
+
48
+ ```python
49
+ from django.urls import include, path
50
+
51
+ urlpatterns = [
52
+ # ...
53
+ path('auth/', include('django_solomon.urls')),
54
+ # ...
55
+ ]
56
+ ```
57
+
58
+ 4. Set the login URL in your settings to use django-solomon's login view:
59
+
60
+ ```python
61
+ LOGIN_URL = 'django_solomon:login'
62
+ ```
63
+
64
+ This ensures that when users need to authenticate, they'll be redirected to the magic link login page.
65
+
66
+ 5. Configure your email settings to ensure emails can be sent:
67
+
68
+ ```python
69
+ EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
70
+ EMAIL_HOST = 'smtp.example.com'
71
+ EMAIL_PORT = 587
72
+ EMAIL_USE_TLS = True
73
+ EMAIL_HOST_USER = 'your-email@example.com'
74
+ EMAIL_HOST_PASSWORD = 'your-password'
75
+ DEFAULT_FROM_EMAIL = 'your-email@example.com'
76
+ ```
77
+
78
+ ## Settings
79
+
80
+ django-solomon provides several settings that you can customize in your Django settings file:
81
+
82
+ | Setting | Default | Description |
83
+ |---------------------------------------|-------------------------------------------------|----------------------------------------------------------------------------------------|
84
+ | `SOLOMON_LINK_EXPIRATION` | `300` | The expiration time for magic links in seconds |
85
+ | `SOLOMON_ONLY_ONE_LINK_ALLOWED` | `True` | If enabled, only one active magic link is allowed per user |
86
+ | `SOLOMON_CREATE_USER_IF_NOT_FOUND` | `False` | If enabled, creates a new user when a magic link is requested for a non-existent email |
87
+ | `SOLOMON_LOGIN_REDIRECT_URL` | `settings.LOGIN_REDIRECT_URL` | The URL to redirect to after successful authentication |
88
+ | `SOLOMON_ALLOW_ADMIN_LOGIN` | `True` | If enabled, allows superusers to log in using magic links |
89
+ | `SOLOMON_ALLOW_STAFF_LOGIN` | `True` | If enabled, allows staff users to log in using magic links |
90
+ | `SOLOMON_MAIL_TEXT_TEMPLATE` | `"django_solomon/email/magic_link.txt"` | The template to use for plain text magic link emails |
91
+ | `SOLOMON_MAIL_MJML_TEMPLATE` | `"django_solomon/email/magic_link.mjml"` | The template to use for HTML magic link emails (MJML format) |
92
+ | `SOLOMON_LOGIN_FORM_TEMPLATE` | `"django_solomon/base/login_form.html"` | The template to use for the login form page |
93
+ | `SOLOMON_INVALID_MAGIC_LINK_TEMPLATE` | `"django_solomon/base/invalid_magic_link.html"` | The template to use for the invalid magic link page |
94
+ | `SOLOMON_MAGIC_LINK_SENT_TEMPLATE` | `"django_solomon/base/magic_link_sent.html"` | The template to use for the magic link sent confirmation page |
95
+
96
+ ## Usage
97
+
98
+ ### Basic Usage
99
+
100
+ 1. Direct users to the magic link request page at `/auth/magic-link/`
101
+ 2. Users enter their email address
102
+ 3. A magic link is sent to their email
103
+ 4. Users click the link in their email
104
+ 5. They are authenticated and redirected to the success URL
105
+
106
+ ### Template Customization
107
+
108
+ You can override the default templates by creating your own versions in your project:
109
+
110
+ - `django_solomon/login_form.html` - The form to request a magic link
111
+ - `django_solomon/magic_link_sent.html` - The confirmation page after a magic link is sent
112
+ - `django_solomon/invalid_magic_link.html` - The error page for invalid magic links
113
+ - `django_solomon/email/magic_link.txt` - The plain text email template for the magic link
114
+ - `django_solomon/email/magic_link.mjml` - The HTML email template for the magic link (in MJML format)
115
+
116
+ Alternatively, you can specify custom templates using the settings variables:
117
+
118
+ - `SOLOMON_LOGIN_FORM_TEMPLATE` - Custom template for the login form
119
+ - `SOLOMON_MAGIC_LINK_SENT_TEMPLATE` - Custom template for the confirmation page
120
+ - `SOLOMON_INVALID_MAGIC_LINK_TEMPLATE` - Custom template for the error page
121
+ - `SOLOMON_MAIL_TEXT_TEMPLATE` - Custom template for the plain text email
122
+ - `SOLOMON_MAIL_MJML_TEMPLATE` - Custom template for the HTML email (MJML format)
123
+
124
+ ### Programmatic Usage
125
+
126
+ You can also use django-solomon programmatically in your views:
127
+
128
+ ```python
129
+ from django.contrib.auth import authenticate, login
130
+ from django_solomon.models import MagicLink
131
+
132
+ # Create a magic link for a user
133
+ magic_link = MagicLink.objects.create_for_user(user)
134
+
135
+ # Authenticate a user with a token
136
+ user = authenticate(request=request, token=token)
137
+ if user:
138
+ login(request, user)
139
+ ```
140
+
141
+ ## License
142
+
143
+ This software is licensed under [MIT license](./LICENSE).
144
+
145
+ ## Contributing
146
+
147
+ Contributions are welcome! Please feel free to submit a Pull Request
148
+ on [Codeberg](https://codeberg.org/oliverandrich/django-solomon).
@@ -0,0 +1,6 @@
1
+ ---
2
+ hide:
3
+ - navigation
4
+ ---
5
+
6
+ --8<-- "CHANGELOG.md"