Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Merge feature/more-allauth into feature/version-2.6

Roland Geider3cd525392ecf
diff --cc CHANGELOG.md
index 2cfcf9039,e045b112e..00fb898e1
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -1,44 -1,34 +1,37 @@@
# Changelog for the next release
- ## Upgrade steps
+ > [!IMPORTANT]
+ > This release comes with several breaking changes. Please read carefully.
- * Some unused thumbnail sizes have been deleted, run `./manage.py prune-thumbnails`
- to delete dangling files
+ ## New features
- * The default location for ingredient images has changed. Please run
- `./manage migrate-ingredient-image-paths` to migrate existing entries. Note
- that this is technically optional, as the old paths will continue working,
- but it is advised for consistency.
+ ### Offline mode (mobile app) 🥳
- * Set the `PS_DATABASE_URI` with the wger db password in the usual format
- `postgres://<user>:<password>@<host>:<port>/<dbname>`. Note that if you didn't
- change the default db config, you just need to update the docker compose files,
- and you're good to go.
+ Adds the necessary backend changes to (finally!) support offline mode in the
+ mobile app. The data is saved in a local sqlite database and synced with the
+ server when the network is reachable again. Basically the whole application
+ can be used without internet, with few exceptions such as
- * The Postgres container in the docker-compose setup now reads its credentials
- (`POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_DB`) from `prod.env` instead
- of having them hardcoded in `services/postgres.yaml`. As above, you only need
- to change this if you are using some non-standard password.
+ * routines (needs some backend logic to calculate the routine data)
+ * gallery (due to the image upload)
+ * account actions like changing the email, etc.
- ## Powersync
+ Buttons and menus will be grayed out if they can't currently be used.
- Adds powersync support. This allows clients (i.e. the mobile app) to finally
- implement offline support. The data is saved in a local sqlite database and
- synced with the server when possible.
+ ### Social login and 2FA
- Incompatible changes:
+ It's now possible to login with social auth providers like Google, Facebook, etc.
+ Also, we now support two-factor authentication like security codes or passkeys.
- The type for the ID for Measurement and MeasurementCategory was changed from integer
- to UUID. This was made to allow for clients to generate IDs locally and affects
- `/api/v2/measurement-category/` and `/api/v2/measurement/`.
+ * https://wger.readthedocs.io/en/latest/administration/mfa.html
+ * https://wger.readthedocs.io/en/latest/administration/social_auth.html
- Make sure you have set the values for `SITE_URL`.
- ## Other changes
+ ### Others
+* The exercise image API now exposes `thumbnails` with `small` and `medium`
+ URLs, consistent with the ingredient API
+
* The ingredient API filter now supports range lookups on `nutriscore`
(`gt`, `gte`, `lt`, `lte`) in addition to `exact` and `in`, enabling queries
like "better than C" (#2295).
@@@ -52,10 -42,54 +45,67 @@@
the next refresh call. It's recommended to update your `prod.env` and set
`REFRESH_TOKEN_LIFETIME` to a value like 3000.
+* When a username is already taken during registration, the system now suggests available
+ alternatives. This replaces the default DRF UniqueValidator with a custom validator that
+ includes suggested usernames in the error response. Suggestions are supported in both the
+ serializer and web registration form validation.
-
- * Exercise language are now also checked when performing edits, instead of only
- during submission.
++
+ * The exercise language is now also checked when performing edits, instead of only
+ during submission so it's not possible to e.g. save a Spanish text for the English
+ description.
+
+
+ ## Upgrade steps
+
+ * If you are using docker, make sure to pull the latest changes from the
+ [docker repo](https://github.com/wger-project/docker) as there is a new service
+ ("powersync") and configs (e.g. for nginx/Caddy).
+
+ * `SIGNING_KEY` is replaced by `JWT_PRIVATE_KEY` and `JWT_PUBLIC_KEY`.
+ Run `docker compose exec web ./manage.py generate-jwt-keys` to generate a new pair.
+
+ * The new powersync service needs its own dedicated user and schema inside the
+ Postgres database to store its sync state, run
+ `docker compose exec web ./manage.py setup-powersync-storage` to apply.
+ If you want to change the defaults, this can be configured in `PS_STORAGE_PG_URI`.
+
+ * Make sure you have set `SITE_URL` with your server's URL
+
+ * *(ignore if you didn't change the db password)* Set the `PS_DATABASE_URI` with
+ the wger db password in the usual format `postgres://<user>:<password>@<host>:<port>/<dbname>`.
+
+ * *(ignore if you didn't change the db password)* The Postgres container in the
+ docker-compose setup now reads its credentials (`POSTGRES_USER`, `POSTGRES_PASSWORD`,
+ `POSTGRES_DB`) from `prod.env` instead of having them hardcoded in the yaml file.
+
++* Some unused thumbnail sizes have been deleted, run `./manage.py prune-thumbnails`
++ to delete dangling files
++
++* The default location for ingredient images has changed. Please run
++ `./manage migrate-ingredient-image-paths` to migrate existing entries. Note
++ that this is technically optional, as the old paths will continue working,
++ but it is advised for consistency.
++
+ ## Breaking changes
+
+ *(only relevant if you have your own scripts or interact with the REST API)*
+
+ The type for the ID was changed from integer to string (UUID) for several models,
+ to allow clients to generate IDs locally. This affects the following endpoints:
+ * `/api/v2/measurement-category/`
+ * `/api/v2/measurement/`
+ * `/api/v2/nutritionplan/` and `/api/v2/nutritionplaninfo/`
+ * `/api/v2/meal/`
+ * `/api/v2/mealitem/`
+ * `/api/v2/nutritiondiary/`
+ * `/api/v2/workoutsession/`
+ * `/api/v2/workoutlog/`
+
+ **`/api/v2/login/` and `/api/v2/register/` endpoints removed.** These endpoints returned
+ a permanent token, use the allauth ones instead (JWT based). If you still need a permanent
+ one, visit the "API key" page in the user settings and paste it into scripts.
+
+ **`/api/v2/token` endpoint removed.** Exchanging username + password for a JWT
+ pair via this endpoint bypassed 2FA. To get tokens, either use
+ `/_allauth/app/v1/auth/login` (which respects the MFA challenge flow) or mint
+ a long-lived refresh token from the "API key" page in the user settings.
diff --cc pyproject.toml
index d3f0d1392,66e605bfa..d2ab6e942
--- a/pyproject.toml
+++ b/pyproject.toml
@@@ -32,7 -32,7 +32,7 @@@ dependencies =
"celery[redis]~=5.6.0",
"crispy-bootstrap5~=2026.3",
"django-activity-stream~=2.0.0",
- "django-allauth~=65.17.0",
- "django-allauth[mfa]~=65.16.1",
++ "django-allauth[mfa]~=65.17.0",
"django-axes[ipware]~=8.3.1",
"django-bootstrap-breadcrumbs2==1.0.0",
"django-cors-headers~=4.9.0",
diff --cc uv.lock
index ff85c0d3f,ab0ed519b..5acb303ad
--- a/uv.lock
+++ b/uv.lock
@@@ -497,11 -497,17 +497,17 @@@ dependencies =
{ name = "asgiref" },
{ name = "django" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/3d/df/357187dfff18c7783e4911827a6c69437e290d7259a32a99c23fcd85997f/django_allauth-65.16.1.tar.gz", hash = "sha256:4425ac3088541c4c54983e16e08f6e3eb9f438dc1b1009534fa51c8bb739ed31", size = 2232835, upload-time = "2026-04-17T18:53:59.475Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/ae/55/5580ab770bae3a885d1ef5a49646c3958c49cf67edfe956703a9bf815371/django_allauth-65.17.0.tar.gz", hash = "sha256:72bea057eaaf2952e4e22cd0195e031ef8e7de2cbac065cf35bd0067ef50a1e7", size = 2237395, upload-time = "2026-05-20T17:43:29.727Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/ad/58/d95b6c3088d83697bfd93782ee57bc6a6462e41eb19121a947b8a015396a/django_allauth-65.16.1-py3-none-any.whl", hash = "sha256:e49df24056bf37c44e56aaad1e51f78994b7d175bc3476d65e8f8f58390a8ce8", size = 2051868, upload-time = "2026-04-17T18:54:12.032Z" },
+ { url = "https://files.pythonhosted.org/packages/bd/5f/dbe29bb38ffc32c6c17590caa346fba8055876a54109a6f914b5916f5819/django_allauth-65.17.0-py3-none-any.whl", hash = "sha256:ff041190bc6f9b2854aa5d7215a1f64f1fc8eb0907990690daad19144b7d2757", size = 2054996, upload-time = "2026-05-20T17:43:41.601Z" },
]
+ [package.optional-dependencies]
+ mfa = [
+ { name = "fido2" },
+ { name = "qrcode" },
+ ]
+
[[package]]
name = "django-axes"
version = "8.3.1"
@@@ -1949,7 -1979,7 +1979,7 @@@ requires-dist =
{ name = "crispy-bootstrap5", specifier = "~=2026.3" },
{ name = "django", specifier = "~=6.0.5" },
{ name = "django-activity-stream", specifier = "~=2.0.0" },
- { name = "django-allauth", specifier = "~=65.17.0" },
- { name = "django-allauth", extras = ["mfa"], specifier = "~=65.16.1" },
++ { name = "django-allauth", extras = ["mfa"], specifier = "~=65.17.0" },
{ name = "django-axes", extras = ["ipware"], specifier = "~=8.3.1" },
{ name = "django-bootstrap-breadcrumbs2", specifier = "==1.0.0" },
{ name = "django-cors-headers", specifier = "~=4.9.0" },
diff --cc wger/core/tests/test_user_login.py
index 2f5e9fe6f,6e00d4577..9261d507e
--- a/wger/core/tests/test_user_login.py
+++ b/wger/core/tests/test_user_login.py
@@@ -84,87 -77,43 +77,59 @@@ class TrainerLoginTestCase(WgerTestCase
self.assertEqual(404, resp.status_code)
- class WgerLoginViewRedirectTestCase(WgerTestCase):
+ class WebLoginViewTestCase(WgerTestCase):
"""
- Tests the "next" parameter handling when an already-authenticated user
- visits the login page
+ The web login view (core:user:login) is allauth's LoginView, with one wger
+ carve-out: temporary (guest) users may still reach the login page.
"""
+ def test_login_page_renders(self):
+ response = self.client.get(reverse('core:user:login'))
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed(response, 'account/login.html')
+
+ def test_login_via_view_succeeds(self):
+ response = self.client.post(
+ reverse('core:user:login'),
+ {'login': 'test', 'password': 'testtest'},
+ )
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(int(self.client.session['_auth_user_id']), 2)
+
+ def test_authenticated_user_is_redirected_away(self):
+ self.user_login('test')
+ response = self.client.get(reverse('core:user:login'))
+ self.assertEqual(response.status_code, 302)
+
+ def test_already_logged_in_rejects_offsite_next(self):
+ """An off-site "next" URL is ignored and the user lands on the dashboard"""
+ self.user_login('admin')
+ response = self.client.get(
+ reverse('core:user:login'),
+ {'next': 'https://attacker.example/phish'},
+ )
+ self.assertRedirects(response, reverse('core:dashboard'), fetch_redirect_response=False)
+
+ def test_already_logged_in_allows_local_next(self):
+ """A safe, same-host relative "next" URL is honoured"""
+ self.user_login('admin')
+ target = reverse('core:dashboard')
+ response = self.client.get(reverse('core:user:login'), {'next': target})
+ self.assertRedirects(response, target, fetch_redirect_response=False)
+
+ def test_temporary_user_can_reach_login_page(self):
+ user = User.objects.get(username='test')
+ user.userprofile.is_temporary = True
+ user.userprofile.save()
+ self.user_login('test')
- class UserApiLoginApiTestCase(BaseTestCase, ApiBaseTestCase):
- url = '/api/v2/login/'
+ response = self.client.get(reverse('core:user:login'))
+ self.assertEqual(response.status_code, 200)
- def test_access_logged_out(self):
+ def test_login_page_shows_passkey_button(self):
"""
- Logged-out users are also allowed to use the search
+ With MFA_PASSKEY_LOGIN_ENABLED the login page offers passwordless
+ sign-in via a passkey.
"""
- response = self.client.get(self.url)
- self.assertEqual(response.status_code, status.HTTP_200_OK)
-
- def test_login_username_success(self):
- response = self.client.post(
- self.url,
- {'username': 'admin', 'password': 'adminadmin'},
- )
- result = response.data
-
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(result, {'token': 'apikey-admin'})
-
- def test_login_username_fail(self):
- response = self.client.post(self.url, {'username': 'admin', 'password': 'adminadmin123'})
- result = response.data
-
- self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
- self.assertEqual(
- result['non_field_errors'],
- [ErrorDetail(string='Username or password unknown', code='invalid')],
- )
-
- def test_login_email_success(self):
- response = self.client.post(
- self.url,
- {'email': '[email protected]', 'password': 'adminadmin'},
- )
- result = response.data
-
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(result, {'token': 'apikey-admin'})
-
- def test_login_email_fail(self):
- response = self.client.post(
- self.url, {'email': '[email protected]', 'password': 'adminadmin123'}
- )
- result = response.data
-
- self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
- self.assertEqual(
- result['non_field_errors'],
- [ErrorDetail(string='Username or password unknown', code='invalid')],
- )
-
- def test_no_parameters(self):
- response = self.client.post(self.url, {'foo': 'bar', 'password': 'adminadmin123'})
- result = response.data
-
- self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
- self.assertEqual(
- result['non_field_errors'],
- [ErrorDetail(string='Please provide an "email" or a "username"', code='invalid')],
- )
+ response = self.client.get(reverse('core:user:login'))
+ self.assertContains(response, 'id="passkey_login"')
diff --cc wger/core/views/user.py
index d9311dfea,91fcc7230..b65af241a
--- a/wger/core/views/user.py
+++ b/wger/core/views/user.py
@@@ -713,15 -749,14 +749,27 @@@ class WgerLoginView(AllauthLoginView)
"""
def dispatch(self, request, *args, **kwargs):
- if request.user.is_authenticated and not request.user.userprofile.is_temporary:
- if request.user.is_authenticated and request.user.userprofile.is_temporary:
- # Skip RedirectAuthenticatedUserMixin's "already logged in" redirect
- return super(RedirectAuthenticatedUserMixin, self).dispatch(
- request, *args, **kwargs
- )
++ if request.user.is_authenticated:
++ if request.user.userprofile.is_temporary:
++ # Skip RedirectAuthenticatedUserMixin's "already logged in"
++ # redirect so temp users can sign in as a real account.
++ return super(RedirectAuthenticatedUserMixin, self).dispatch(
++ request, *args, **kwargs
++ )
++
++ # Real authenticated user: respect ?next= or send them to the dashboard.
+ next_url = request.GET.get('next')
+ if next_url and url_has_allowed_host_and_scheme(
+ next_url,
+ allowed_hosts={request.get_host()},
+ require_https=request.is_secure(),
+ ):
+ return redirect(next_url)
+ return redirect(reverse('core:dashboard'))
+
- # Proceed with the normal login page logic
return super().dispatch(request, *args, **kwargs)
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context['use_social_auth'] = bool(settings.WGER_SOCIAL_PROVIDERS)
+ return context