Skip to content

Commit

Permalink
Added UAM login/register filters
Browse files Browse the repository at this point in the history
  • Loading branch information
angellareo committed Feb 2, 2024
1 parent 3ea51dc commit b26f9b6
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions uamx_social_auth/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
from django.http import HttpResponse
from openedx_filters import PipelineStep
from openedx_filters.learning.filters import (
# AccountSettingsRenderStarted,
# CertificateCreationRequested,
# CertificateRenderStarted,
# CohortAssignmentRequested,
# CohortChangeRequested,
# CourseAboutRenderStarted,
# CourseEnrollmentStarted,
# CourseUnenrollmentStarted,
# DashboardRenderStarted,
StudentLoginRequested,
StudentRegistrationRequested,
)

# Modified from: https://github.com/eduNEXT/eox-tenant/blob/master/eox_tenant/pipeline.py

class UAMxAuthException(ValueError):
Expand Down Expand Up @@ -41,3 +57,50 @@ def safer_associate_by_email(backend, details, user=None, *args, **kwargs):
# )
return {'user': users[0],
'is_new': False}

class StopUAMDomainRegister(PipelineStep):
"""
Stop registration process raising PreventRegister exception.
Example usage:
Add the following configurations to your configuration file:
"OPEN_EDX_FILTERS_CONFIG": {
"org.openedx.learning.student.registration.requested.v1": {
"fail_silently": false,
"pipeline": [
"openedx_filters_samples.samples.pipeline.StopUAMDomainRegister"
]
}
}
"""
def run_filter(self, form_data, *args, **kwargs):
if form_data["email"].endswith("uam.es"):
raise StudentRegistrationRequested.PreventRegistration(
"You can't register. UAM users should use ID-UAM.", status_code=403
)

class StopUAMDomainLogin(PipelineStep):
"""
Stop login process raising PreventLogin exception.
Example usage:
Add the following configurations to your configuration file:
"OPEN_EDX_FILTERS_CONFIG": {
"org.openedx.learning.student.login.requested.v1": {
"fail_silently": false,
"pipeline": [
"openedx_filters_samples.samples.pipeline.StopUAMDomainLogin"
]
}
}
"""

def run_filter(self, user, *args, **kwargs): # pylint: disable=arguments-differ
if user.email.endswith("uam.es"):
raise StudentLoginRequested.PreventLogin(
"You can't login. UAM users should use ID-UAM.", redirect_to="", error_code="pre-register-login-forbidden"
)

0 comments on commit b26f9b6

Please sign in to comment.