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

adding ability to make signup private process #427

Open
wants to merge 1 commit into
base: develop
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
24 changes: 14 additions & 10 deletions bookie/templates/index.mako
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
<div id="welcome" class="" style="max-width: 1000px;">
<div class="signup">
<div class="form">
<h2>Enter Email to Signup</h2>
<form id="#signup_form" action="signup_process" method="POST">
<ul>
<li>
<input type="email" id="email" name="email"
placeholder="email address" />
<input type="submit" id="send_signup" name="send_signup" value="Sign Up" />
</li>
</ul>
</form>
% if signup:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about making this more explicit. 'signup_enabled'

<h2>Enter Email to Signup</h2>
<form id="#signup_form" action="signup_process" method="POST">
<ul>
<li>
<input type="email" id="email" name="email"
placeholder="email address" />
<input type="submit" id="send_signup" name="send_signup" value="Sign Up" />
</li>
</ul>
</form>
% else:
<h2>This site is private please contact admin for invitation.</h2>
%endif
</div>
</div>

Expand Down
41 changes: 41 additions & 0 deletions bookie/tests/test_auth/test_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
urlencode,
)
import transaction
from pyramid import testing
from unittest import TestCase

from bookie.models import DBSession
from bookie.models.auth import Activation
Expand Down Expand Up @@ -204,3 +206,42 @@ def testSignupWorks(self):
email,
act.user.email,
"The activation email is the correct one.")


class TestPrivateHosting(TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extend the WebTest from the test/init.py and have the setup waiting for you.I know you need to tweak the config, but perhaps we can do that by sticking an override_config attribute on the class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome idea, i'll work on it

"""Check if Signup is disabled in private hosting"""

message = 'This site is private please contact admin for invitation.'

def setUp(self):
from pyramid.paster import get_app
from bookie.tests import BOOKIE_TEST_INI
app = get_app(BOOKIE_TEST_INI, 'bookie')
# Changing signup_process to false to disable signups
app.registry.settings['signup_process'] = "false"
from webtest import TestApp
self.testapp = TestApp(app)
testing.setUp()

def tearDown(self):
testing.tearDown()

def testSignupPage(self):
"""A signup form is not available."""
res = self.testapp.get('/signup')
self.assertIn(self.message, res.body)

def testMainPage(self):
"""A signup form is not available in main page."""
res = self.testapp.get('/')
self.assertIn(self.message, res.body)

def testManualHit(self):
"""Message should be shown if /signup_process is hit manually"""
res = self.testapp.post(
'/signup_process',
params={
'email': '[email protected]'
}
)
self.assertIn(self.message, res.body)
8 changes: 7 additions & 1 deletion bookie/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Basic views with no home"""
from pyramid.httpexceptions import HTTPFound
from pyramid.httpexceptions import HTTPNotFound
from pyramid.settings import asbool
from pyramid.view import view_config

from bookie.models.auth import UserMgr
Expand Down Expand Up @@ -30,7 +31,12 @@ def home(request):
username = username.lower()

if not request.user:
return {}
if asbool(request.registry.settings.get('signup_process')):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so then I'd make this match. 'signup_enabled'. It makes it clear what true/false do to this.

return {
'signup': True
}
else:
return {}
else:
if not username:
return HTTPFound(location=request.route_url("bmark_recent"))
Expand Down
2 changes: 1 addition & 1 deletion bookie/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def reset_password(request):
new = params.get('new_password', None)

# if we don't have any password info, try a json_body in case it's a json
#POST
# POST
if current is None and new is None:
params = request.json_body
current = params.get('current_password', None)
Expand Down
12 changes: 11 additions & 1 deletion bookie/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pyramid.renderers import render_to_response
from pyramid.security import remember
from pyramid.security import forget
from pyramid.settings import asbool
from pyramid.url import route_url
from pyramid.view import view_config

Expand Down Expand Up @@ -105,7 +106,12 @@ def signup(request):
this time so that we can stage invites across a specific number in waves.

"""
return {}
if not asbool(request.registry.settings.get('signup_process')):
return {
'message': 'This site is private please contact admin for invitation.'
}
else:
return {}


@view_config(route_name="signup_process", renderer="/auth/signup.mako")
Expand All @@ -116,6 +122,10 @@ def signup_process(request):
information.

"""
if not asbool(request.registry.settings.get('signup_process')):
return {
'message': 'This site is private please contact admin for invitation.'
}
params = request.params
email = params.get('email', None)

Expand Down
3 changes: 3 additions & 0 deletions sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ email.host=sendmail
fulltext.engine=whoosh
fulltext.index=bookie_index

#Change to false to disable signups
signup_process = true

# what is the host that's providing the YUI combo loader?
combo_server=
# Set this to help bust the cache. It will add a prefix to the combo url you
Expand Down
3 changes: 3 additions & 0 deletions test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ email.host=sendmail
fulltext.engine=whoosh
fulltext.index=bookie_test

#Change to false to disable signups
signup_process = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also needs to go into the test_pgsql.ini. We've recently set that up on the CI server. http://ci.bookie.io:8080


# what is the host that's providing the YUI combo loader?
combo_server = http://127.0.0.1:8000
# set this to help bust the cache. It will add a prefix to the combo url you
Expand Down