diff --git a/CHANGELOG b/CHANGELOG index 07d1dedbd..d010c076e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,10 @@ Changelog - Front: Now reset player colors when track has no cover (#46) - Front: play button now disabled for unplayable tracks +- API: You can now enable or disable registration on the fly, via a preference (#58) +- Front: can now signup via the web interface (#35) +- Front: Fixed broken redirection on login +- Front: Fixed broken error handling on settings and login form Transcoding: diff --git a/api/config/settings/common.py b/api/config/settings/common.py index 5fe55e53a..491babdd1 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -264,7 +264,7 @@ AUTHENTICATION_BACKENDS = ( ) # Some really nice defaults -ACCOUNT_AUTHENTICATION_METHOD = 'username' +ACCOUNT_AUTHENTICATION_METHOD = 'username_email' ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_VERIFICATION = 'mandatory' @@ -317,7 +317,6 @@ CORS_ORIGIN_ALLOW_ALL = True # ) CORS_ALLOW_CREDENTIALS = True API_AUTHENTICATION_REQUIRED = env.bool("API_AUTHENTICATION_REQUIRED", True) -REGISTRATION_MODE = env('REGISTRATION_MODE', default='disabled') REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', diff --git a/api/config/urls.py b/api/config/urls.py index de67ebb57..8f7e37bc2 100644 --- a/api/config/urls.py +++ b/api/config/urls.py @@ -13,8 +13,8 @@ urlpatterns = [ url(settings.ADMIN_URL, admin.site.urls), url(r'^api/', include(("config.api_urls", 'api'), namespace="api")), - url(r'^api/auth/', include('rest_auth.urls')), - url(r'^api/auth/registration/', include('funkwhale_api.users.rest_auth_urls')), + url(r'^api/v1/auth/', include('rest_auth.urls')), + url(r'^api/v1/auth/registration/', include('funkwhale_api.users.rest_auth_urls')), url(r'^accounts/', include('allauth.urls')), # Your stuff: custom urls includes go here diff --git a/api/funkwhale_api/users/adapters.py b/api/funkwhale_api/users/adapters.py index 792b4860f..96d1b8b1d 100644 --- a/api/funkwhale_api/users/adapters.py +++ b/api/funkwhale_api/users/adapters.py @@ -1,15 +1,10 @@ from allauth.account.adapter import DefaultAccountAdapter -from django.conf import settings +from dynamic_preferences.registries import global_preferences_registry class FunkwhaleAccountAdapter(DefaultAccountAdapter): def is_open_for_signup(self, request): - - if settings.REGISTRATION_MODE == "disabled": - return False - if settings.REGISTRATION_MODE == "public": - return True - - return False + manager = global_preferences_registry.manager() + return manager['users__registration_enabled'] diff --git a/api/funkwhale_api/users/dynamic_preferences_registry.py b/api/funkwhale_api/users/dynamic_preferences_registry.py new file mode 100644 index 000000000..16d79da14 --- /dev/null +++ b/api/funkwhale_api/users/dynamic_preferences_registry.py @@ -0,0 +1,15 @@ +from dynamic_preferences import types +from dynamic_preferences.registries import global_preferences_registry + +users = types.Section('users') + + +@global_preferences_registry.register +class RegistrationEnabled(types.BooleanPreference): + show_in_api = True + section = users + name = 'registration_enabled' + default = False + verbose_name = ( + 'Can visitors open a new account on this instance?' + ) diff --git a/api/tests/users/test_views.py b/api/tests/users/test_views.py index 1eb8ef222..569acbd15 100644 --- a/api/tests/users/test_views.py +++ b/api/tests/users/test_views.py @@ -6,7 +6,7 @@ from django.urls import reverse from funkwhale_api.users.models import User -def test_can_create_user_via_api(settings, client, db): +def test_can_create_user_via_api(preferences, client, db): url = reverse('rest_register') data = { 'username': 'test1', @@ -14,7 +14,7 @@ def test_can_create_user_via_api(settings, client, db): 'password1': 'testtest', 'password2': 'testtest', } - settings.REGISTRATION_MODE = "public" + preferences['users__registration_enabled'] = True response = client.post(url, data) assert response.status_code == 201 @@ -22,7 +22,7 @@ def test_can_create_user_via_api(settings, client, db): assert u.username == 'test1' -def test_can_disable_registration_view(settings, client, db): +def test_can_disable_registration_view(preferences, client, db): url = reverse('rest_register') data = { 'username': 'test1', @@ -30,7 +30,7 @@ def test_can_disable_registration_view(settings, client, db): 'password1': 'testtest', 'password2': 'testtest', } - settings.REGISTRATION_MODE = "disabled" + preferences['users__registration_enabled'] = False response = client.post(url, data) assert response.status_code == 403 diff --git a/deploy/env.prod.sample b/deploy/env.prod.sample index 5bdfeb9c6..6a4b15b67 100644 --- a/deploy/env.prod.sample +++ b/deploy/env.prod.sample @@ -74,11 +74,6 @@ DJANGO_SECRET_KEY= # If True, unauthenticated users won't be able to query the API API_AUTHENTICATION_REQUIRED=True -# What is the workflow for registration on funkwhale ? Possible values: -# public: anybody can register an account -# disabled: nobody can register an account -REGISTRATION_MODE=disabled - # Sentry/Raven error reporting (server side) # Enable Raven if you want to help improve funkwhale by # automatically sending error reports our Sentry instance. diff --git a/front/src/components/auth/Login.vue b/front/src/components/auth/Login.vue index 99b439af8..2cf6d5f6d 100644 --- a/front/src/components/auth/Login.vue +++ b/front/src/components/auth/Login.vue @@ -12,13 +12,13 @@