diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index c30efb88ecb5..729ff04e214d 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -129,6 +129,11 @@ from openedx.core.djangoapps.user_api.preferences import api as preferences_api from openedx.core.djangoapps.catalog.utils import get_programs_data +# try to import appsembler fork of edx-organizations (if it's installed) +try: + from organizations.models import UserOrganizationMapping +except ImportError: + pass log = logging.getLogger("edx.student") AUDIT_LOG = logging.getLogger("audit") @@ -1857,13 +1862,21 @@ def create_account_with_params(request, params): else: registration.activate() _enroll_user_in_pending_courses(user) # Enroll student in any pending courses + + #if using custom Appsembler backend from edx-organizations + if u'organizations.backends.OrganizationMemberBackend' in settings.AUTHENTICATION_BACKENDS: + organization = request.site.organizations.first() + if organization: + UserOrganizationMapping.objects.get_or_create(user=user, organization=organization, is_active=False) # Immediately after a user creates an account, we log them in. They are only # logged in until they close the browser. They can't log in again until they click # the activation link from the email. new_user = authenticate(username=user.username, password=params['password']) - login(request, new_user) - request.session.set_expiry(0) + + if not settings.APPSEMBLER_FEATURES.get('SKIP_LOGIN_AFTER_REGISTRATION', False): + login(request, new_user) + request.session.set_expiry(0) try: record_registration_attributions(request, new_user) diff --git a/lms/envs/aws_appsembler.py b/lms/envs/aws_appsembler.py index e9144142a13c..727e41f0abc5 100644 --- a/lms/envs/aws_appsembler.py +++ b/lms/envs/aws_appsembler.py @@ -121,3 +121,14 @@ if 'LMS_AUTHENTICATION_BACKENDS' in APPSEMBLER_FEATURES.keys(): #default behavior is to replace the existing backends with those in APPSEMBLER_FEATURES AUTHENTICATION_BACKENDS = tuple(APPSEMBLER_FEATURES['LMS_AUTHENTICATION_BACKENDS']) + +#attempt to import model from our custom fork of edx-organizations +# if it works, then also add the middleware +try: + from organizations.models import UserOrganizationMapping + MIDDLEWARE_CLASSES += ( + 'organizations.middleware.OrganizationMiddleware', + ) +except ImportError: + pass + diff --git a/lms/envs/devstack_appsembler.py b/lms/envs/devstack_appsembler.py index 06586fea8d04..801237b6eb89 100644 --- a/lms/envs/devstack_appsembler.py +++ b/lms/envs/devstack_appsembler.py @@ -110,3 +110,15 @@ if 'LMS_AUTHENTICATION_BACKENDS' in APPSEMBLER_FEATURES.keys(): #default behavior is to replace the existing backends with those in APPSEMBLER_FEATURES AUTHENTICATION_BACKENDS = tuple(APPSEMBLER_FEATURES['LMS_AUTHENTICATION_BACKENDS']) + +#attempt to import model from our custom fork of edx-organizations +# if it works, then also add the middleware +try: + from organizations.models import UserOrganizationMapping + MIDDLEWARE_CLASSES += ( + 'organizations.middleware.OrganizationMiddleware', + ) +except ImportError: + pass + +