|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import logging |
| 6 | +from urllib.parse import quote |
6 | 7 |
|
7 | 8 | from django.conf import settings |
8 | 9 | from django.contrib.auth.decorators import login_required |
| 10 | +from django.contrib.messages import get_messages |
9 | 11 | from django.core.exceptions import PermissionDenied, ValidationError |
10 | 12 | from django.db import DatabaseError |
11 | 13 | from django.http import ( |
|
32 | 34 | from common.djangoapps.student.models import UserProfile |
33 | 35 | from common.djangoapps.student.views import compose_and_send_activation_email |
34 | 36 | from common.djangoapps.third_party_auth import pipeline, provider |
| 37 | +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers |
35 | 38 |
|
36 | 39 | from .models import SAMLConfiguration, SAMLProviderConfig |
37 | 40 |
|
@@ -273,3 +276,21 @@ def disconnect_json_view(request, backend, association_id=None): |
273 | 276 | 'backend': backend, |
274 | 277 | 'association_id': association_id |
275 | 278 | }, status=500) |
| 279 | + |
| 280 | +def account_settings_redirect_view(request): |
| 281 | + """ |
| 282 | + Redirect to Account MFE, preserving auth error messages (e.g., AuthAlreadyAssociated). |
| 283 | + """ |
| 284 | + account_mfe_url = configuration_helpers.get_value( |
| 285 | + 'ACCOUNT_MICROFRONTEND_URL', |
| 286 | + settings.ACCOUNT_MICROFRONTEND_URL, |
| 287 | + ).rstrip('/') |
| 288 | + |
| 289 | + duplicate_backend = pipeline.get_duplicate_provider(get_messages(request)) |
| 290 | + if not duplicate_backend: |
| 291 | + return redirect(account_mfe_url) |
| 292 | + |
| 293 | + enabled_providers = list(provider.Registry.get_enabled_by_backend_name(duplicate_backend)) |
| 294 | + provider_name = enabled_providers[0].name if enabled_providers else duplicate_backend |
| 295 | + |
| 296 | + return redirect(f'{account_mfe_url}/?duplicate_provider={quote(provider_name)}') |
0 commit comments