Repository navigation
Skip login after registration (mostly for NYIF) #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a05f9fa
6b25443
425efc5
0dbd8c5
e8fd8a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,24 @@ 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: | ||
| try: | ||
| organization = request.site.organizations.first() | ||
| if organization: | ||
| UserOrganizationMapping.objects.get_or_create(user=user, organization=organization, is_active=False) | ||
| except: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tkeemon don't take my word for it. Please double check whether this works or not. Generally it's advisable to avoid
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OmarIthawi thanks for catching this. This is definitely a bad habit of mine. Take a look and let me know if this addresses your concern. |
||
| pass | ||
|
|
||
| # 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): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| login(request, new_user) | ||
| request.session.set_expiry(0) | ||
|
|
||
| try: | ||
| record_registration_attributions(request, new_user) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not specific to this PR at all. But we do need to DRY in the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. And @johnbaldwin has raised this same point as well: https://trello.com/c/wfj1jPTd/98-dry-up-awsappsembler-and-devstackappsembler-py-files That's what I was attempting to do with the But with this setup we were running into some problems. I can't remember specifically, but I think it was related to the fact that this file was called without importing We can definitely do this, we just need to be careful about how we structure the imports. |
||
| # if it works, then also add the middleware | ||
| try: | ||
| from organizations.models import UserOrganizationMapping | ||
| MIDDLEWARE_CLASSES += ( | ||
| 'organizations.middleware.OrganizationMiddleware', | ||
| ) | ||
| except ImportError: | ||
| pass | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much better. I'd like to take it further:
Why not completely avoid the
try/except? I think havingif u'organizations.backends.OrganizationMemberBackend' in settings.AUTHENTICATION_BACKENDS:makes it safe to assume that all the rest will go well:Do we expect that
organization = request.site.organizations.first()to beNone? If so, let's keep theif organization:part.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I'll remove the
try/except. I do expectorganization = request.site.organizations.first()to returnNonewhen the site in question is the default site, so I'm going to leave that lastifstatement in there.Making that change and merging.