diff --git a/framework/auth/campaigns.py b/framework/auth/campaigns.py index 5bb973d83019..76b63ba9c86e 100644 --- a/framework/auth/campaigns.py +++ b/framework/auth/campaigns.py @@ -69,6 +69,17 @@ def get_campaigns(): } }) + # Proxy campaigns: Registries, OSF only + newest_campaigns.update({ + 'osf-registries': { + 'system_tag': 'osf_registries', + 'redirect_url': furl.furl(DOMAIN).add(path='registries/').url, + 'confirmation_email_template': mails.CONFIRM_EMAIL_REGISTRIES_OSF, + 'login_type': 'proxy', + 'provider': 'osf', + } + }) + CAMPAIGNS = newest_campaigns CAMPAIGNS_LAST_REFRESHED = timezone.now() diff --git a/framework/auth/views.py b/framework/auth/views.py index acab1c45f950..15319f16ba5a 100644 --- a/framework/auth/views.py +++ b/framework/auth/views.py @@ -14,7 +14,7 @@ from modularodm.exceptions import ValidationError from modularodm.exceptions import ValidationValueError -from framework import forms, status +from framework import forms, sentry, status from framework import auth as framework_auth from framework.auth import exceptions from framework.auth import cas, campaigns @@ -262,8 +262,14 @@ def login_and_register_handler(auth, login=True, campaign=None, next_url=None, l else: data['next_url'] = destination else: - # invalid campaign - raise HTTPError(http.BAD_REQUEST) + # invalid campaign, inform sentry and redirect to non-campaign sign up or sign in + redirect_view = 'auth_login' if login else 'auth_register' + data['status_code'] = http.FOUND + data['next_url'] = web_url_for(redirect_view, campaigns=None, next=next_url) + data['campaign'] = None + sentry.log_message( + '{} is not a valid campaign. Please add it if this is a new one'.format(campaign) + ) # login or register with next parameter elif next_url: if logout: diff --git a/tests/test_campaigns.py b/tests/test_campaigns.py index 4bcb4349f665..46de24cdc18b 100644 --- a/tests/test_campaigns.py +++ b/tests/test_campaigns.py @@ -48,6 +48,7 @@ def setUp(self): 'socarxiv-preprints', 'engrxiv-preprints', 'psyarxiv-preprints', + 'osf-registries', ] self.refresh = timezone.now() campaigns.CAMPAIGNS = None # force campaign refresh now that preprint providers are populated diff --git a/tests/test_views.py b/tests/test_views.py index 4e3a29c279ed..1c05ede9e8e9 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -3488,6 +3488,7 @@ def setUp(self): self.user_auth = AuthUserFactory() self.auth = Auth(user=self.user_auth) self.next_url = web_url_for('my_projects', _absolute=True) + self.invalid_campaign = 'invalid_campaign' def test_osf_login_with_auth(self): # login: user with auth @@ -3600,7 +3601,7 @@ def test_campaign_register_with_auth(self): assert_equal(data.get('status_code'), http.FOUND) assert_equal(data.get('next_url'), campaign_url_for(campaign)) - def test_campaign_register_without_campaign(self): + def test_campaign_register_without_auth(self): for campaign in get_campaigns(): if is_institution_login(campaign): continue @@ -3668,6 +3669,31 @@ def test_campaign_next_url_register_without_auth(self): web_url_for('auth_login', next= next_url, _absolute=True) ) + def test_invalid_campaign_login_without_auth(self): + data = login_and_register_handler( + self.no_auth, + login=True, + campaign=self.invalid_campaign, + next_url=self.next_url + ) + redirect_url = web_url_for('auth_login', campaigns=None, next=self.next_url) + assert_equal(data['status_code'], http.FOUND) + assert_equal(data['next_url'], redirect_url) + assert_equal(data['campaign'], None) + + def test_invalid_campaign_register_without_auth(self): + data = login_and_register_handler( + self.no_auth, + login=False, + campaign=self.invalid_campaign, + next_url=self.next_url + ) + redirect_url = web_url_for('auth_register', campaigns=None, next=self.next_url) + assert_equal(data['status_code'], http.FOUND) + assert_equal(data['next_url'], redirect_url) + assert_equal(data['campaign'], None) + + # The following two tests handles the special case for `claim_user_registered` # When an authenticated user clicks the claim confirmation clink, there are two ways to trigger this flow: # 1. If the authenticated user is already a contributor to the project, OSF will ask the user to sign out diff --git a/website/mails/mails.py b/website/mails/mails.py index 2afb0e160195..c332ca9c417e 100644 --- a/website/mails/mails.py +++ b/website/mails/mails.py @@ -174,6 +174,10 @@ def get_english_article(word): 'confirm_preprints_{}'.format(name), subject='Open Science Framework Account Verification, {} Preprints Service'.format(provider) ) +CONFIRM_EMAIL_REGISTRIES_OSF = Mail( + 'confirm_registries_osf', + subject='Open Science Framework Account Verification, OSF Registries' +) # Merge account, add or remove email confirmation emails. CONFIRM_MERGE = Mail('confirm_merge', subject='Confirm account merge') diff --git a/website/static/img/registries/osf-registries-black.png b/website/static/img/registries/osf-registries-black.png new file mode 100644 index 000000000000..dbb5edd30d89 Binary files /dev/null and b/website/static/img/registries/osf-registries-black.png differ diff --git a/website/templates/emails/confirm_registries_osf.txt.mako b/website/templates/emails/confirm_registries_osf.txt.mako new file mode 100644 index 000000000000..30f491851b0c --- /dev/null +++ b/website/templates/emails/confirm_registries_osf.txt.mako @@ -0,0 +1,9 @@ +Hello ${user.fullname}, + +Welcome to the Open Science Framework and OSF Registries. To continue, please verify your email address by visiting this link: + +${confirmation_url} + + +Sincerely, +From the team at the Center for Open Science diff --git a/website/templates/public/register.mako b/website/templates/public/register.mako index b72441dfff3d..c4084bcee7cc 100644 --- a/website/templates/public/register.mako +++ b/website/templates/public/register.mako @@ -61,12 +61,26 @@ %endif + %if campaign == "osf-registries": +
+

OSF Registries


+

Please login to the Open Science Framework or create a free account to continue.

+
+ %endif +
%if campaign != "institution" or not enable_institutions:
- %if campaign == "osf-preprints": + %if campaign == "osf-registries": + + + + + +

Create a free OSF account

+ %elif campaign == "osf-preprints":