Skip to content

Commit

Permalink
Merge f0f6a8c into e71d98b
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Apr 5, 2017
2 parents e71d98b + f0f6a8c commit a02fd37
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 5 deletions.
11 changes: 11 additions & 0 deletions framework/auth/campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
12 changes: 9 additions & 3 deletions framework/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions website/mails/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions website/templates/emails/confirm_registries_osf.txt.mako
Original file line number Diff line number Diff line change
@@ -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
16 changes: 15 additions & 1 deletion website/templates/public/register.mako
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,26 @@
</div>
%endif
%if campaign == "osf-registries":
<div class="text-center m-t-lg">
<h3>OSF Registries</h3><hr>
<p>Please login to the Open Science Framework or create a free account to continue.</p>
</div>
%endif
<div class="row m-t-xl">
%if campaign != "institution" or not enable_institutions:
<div id="signUpScope" class="col-sm-10 col-sm-offset-1 col-md-9 col-md-offset-2 col-lg-8 signup-form p-b-md m-b-m bg-color-light">
<form data-bind="submit: submit" class="form-horizontal">
%if campaign == "osf-preprints":
%if campaign == "osf-registries":
<table style="border-collapse: separate; border-spacing: 30px 0; margin-top: 20px; margin-bottom: 10px;">
<tr>
<td><img src="/static/img/registries/osf-registries-black.png" style="width: 200px; margin-top: 15px" /></td>
<td><h3>Create a free OSF account</h3></td>
</tr>
</table>
%elif campaign == "osf-preprints":
<table style="border-collapse: separate; border-spacing: 30px 0; margin-top: 20px; margin-bottom: 10px;">
<tr>
<td><img src="/static/img/preprint_providers/osf-preprints-login.png" style="width: 200px; margin-top: 15px" /></td>
Expand Down

0 comments on commit a02fd37

Please sign in to comment.