Skip to content
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

Enforce academic email requirements for students, postdocs, and academic researchers #2158

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions physionet-django/user/fixtures/demo-user.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"pk": 6,
"fields": {
"password": "pbkdf2_sha256$150000$6e8RyzxeUEDC$XjhKiSVwTTucKJIvpC2gYWL/6jCeSBWuZQRMSe8bm3g=",
"email": "eula_easley@fake_gmail.com",
"email": "eula_easley@mit.edu",
"username": "eulaeasley",
"join_date": "2020-03-29",
"last_login": null,
Expand Down Expand Up @@ -3438,7 +3438,7 @@
"user": [
"eulaeasley"
],
"email": "eula_easley@fake_gmail.com",
"email": "eula_easley@mit.edu",
"is_primary_email": true,
"added_date": "2020-03-29T21:51:08.458Z",
"verification_date": "2020-03-29T21:51:08.458Z",
Expand Down
18 changes: 17 additions & 1 deletion physionet-django/user/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.contrib.auth import forms as auth_forms
from django.contrib.auth import password_validation
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import UploadedFile
from django.db import transaction
from django.db.models import F, Q
Expand Down Expand Up @@ -474,7 +475,6 @@ def __init__(self, user, *args, **kwargs):
'organization_name':self.profile.affiliation,
'webpage':self.profile.website}


class ResearchCAF(forms.ModelForm):
"""
Credential application form research attributes
Expand Down Expand Up @@ -599,6 +599,7 @@ def clean(self):
ref_required = True
supervisor_required = data['researcher_category'] in [0, 1, 7]
state_required = data['country'] in ['US', 'CA']
category = data['researcher_category']

# Students and postdocs must provide their supervisor as a reference
if supervisor_required and data['reference_category'] != 0:
Expand All @@ -624,6 +625,21 @@ def clean(self):
.filter(user=self.user, status=CredentialApplication.Status.PENDING)):
raise forms.ValidationError('Outstanding application exists.')

# If the user is a student, postdoc, or academic researcher, an associated email should be provided
if category in [0, 1, 2, 7]:
has_institutional_email = False
for email in self.user.get_emails():
try:
validate_institutional_email(email)
has_institutional_email = True
except ValidationError:
pass
if not has_institutional_email:
raise ValidationError(
'Please provide your academic email address'
' in your email settings.'
)

def save(self):
credential_application = super().save(commit=False)
slug = get_random_string(20)
Expand Down
3 changes: 2 additions & 1 deletion physionet-django/user/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ def validate_institutional_email(value):
Validate that the email address is from an institutional domain.
"""
validate_email(value)
domains = ["yahoo.com", "163.com", "126.com", "outlook.com", "gmail.com", "qq.com", "foxmail.com"]
domains = ["yahoo.com", "163.com", "126.com", "outlook.com", "gmail.com", "qq.com",
"foxmail.com", "hotmail.com", "168.com"]
if value.split('@')[-1].lower() in domains:
raise ValidationError('Please provide an academic or institutional email address.')

Expand Down
Loading