Skip to content

Commit 436fc9f

Browse files
committed
Added a configuration of registration open, and a test
1 parent d4bd32a commit 436fc9f

File tree

6 files changed

+46
-5
lines changed

6 files changed

+46
-5
lines changed

lms/lmsweb/config.py.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ MAILGUN_DOMAIN = os.getenv('MAILGUN_DOMAIN', 'mail.pythonic.guru')
1010
SERVER_ADDRESS = os.getenv('SERVER_ADDRESS', '127.0.0.1:5000')
1111
SITE_NAME = 'Learning Python'
1212

13+
# REGISTRATION CONFIGURATIONS
14+
REGISTRATION_OPEN = True
1315
CONFIRMATION_TIME = 3600
1416

1517
# MAIL CONFIGURATION

lms/lmsweb/translations/en/LC_MESSAGES/messages.po

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: lmsweb-1.0\n"
99
"Report-Msgid-Bugs-To: bugs@mesicka.com\n"
10-
"POT-Creation-Date: 2021-09-12 11:15+0300\n"
10+
"POT-Creation-Date: 2021-09-12 15:10+0300\n"
1111
"PO-Revision-Date: 2020-09-16 18:29+0300\n"
1212
"Last-Translator: Or Ronai\n"
1313
"Language: en\n"
@@ -45,15 +45,19 @@ msgstr "The automatic checker couldn't run your code."
4545
msgid "אחי, בדקת את הקוד שלך?"
4646
msgstr "Bro, did you check your code?"
4747

48-
#: lmsweb/views.py:134
48+
#: lmsweb/views.py:122
49+
msgid "לא ניתן להירשם כעת"
50+
msgstr "Can not register now"
51+
52+
#: lmsweb/views.py:139
4953
msgid "ההרשמה בוצעה בהצלחה"
5054
msgstr "Registration successfully"
5155

52-
#: lmsweb/views.py:156
56+
#: lmsweb/views.py:161
5357
msgid "קישור האימות פג תוקף, קישור חדש נשלח אל תיבת המייל שלך"
5458
msgstr "The confirmation link is expired, new link has been sent to your email"
5559

56-
#: lmsweb/views.py:169
60+
#: lmsweb/views.py:174
5761
#, fuzzy
5862
msgid "המשתמש שלך אומת בהצלחה, כעת אתה יכול להתחבר למערכת"
5963
msgstr "Your user has been successfully confirmed, you can now login"
@@ -177,7 +181,7 @@ msgstr "Password"
177181
msgid "התחבר"
178182
msgstr "Login"
179183

180-
#: templates/login.html:38 templates/signup.html:22
184+
#: templates/login.html:39 templates/signup.html:22
181185
msgid "הירשם"
182186
msgstr "Register"
183187

lms/lmsweb/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def login(login_message: Optional[str] = None):
117117

118118
@webapp.route('/signup', methods=['GET', 'POST'])
119119
def signup():
120+
if not webapp.config.get('REGISTRATION_OPEN', False):
121+
return redirect(url_for(
122+
'login', login_message=_('לא ניתן להירשם כעת'),
123+
))
124+
120125
form = RegisterForm()
121126
if not form.validate_on_submit():
122127
return render_template('signup.html', form=form)

lms/templates/login.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ <h1 id="main-title" class="h3 font-weight-normal">{{ _('התחברות') }}</h1>
3434
<input class="form-control form-control-lg" type="hidden" name="next" id="next" value="{{ request.args.get('next', '') }}">
3535
<button class="btn btn-primary btn-lg btn-block">{{ _('התחבר') }}</button>
3636
</form>
37+
{% if config.REGISTRATION_OPEN %}
3738
<hr class="mt-3 mb-3"/>
3839
<a href="/signup" class="btn btn-success btn-sm" role="button">{{ _('הירשם') }}</a>
40+
{% endif %}
3941
</div>
4042
</div>
4143
</div>

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ def disable_mail_sending():
7575
webapp.config['TESTING'] = True
7676

7777

78+
@pytest.fixture(autouse=True, scope='session')
79+
def enable_registration():
80+
webapp.config['REGISTRATION_OPEN'] = True
81+
82+
7883
def disable_shareable_solutions():
7984
webapp.config['SHAREABLE_SOLUTIONS'] = False
8085

@@ -87,6 +92,10 @@ def enable_users_comments():
8792
webapp.config['USERS_COMMENTS'] = True
8893

8994

95+
def disable_registration():
96+
webapp.config['REGISTRATION_OPEN'] = False
97+
98+
9099
def use_limiter(func):
91100
@wraps(func)
92101
def wrapper(*args, **kwargs):

tests/test_registration.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from lms.lmsweb.config import CONFIRMATION_TIME
77
from lms.lmsdb.models import User
88
from lms.models.register import generate_confirmation_token
9+
from tests import conftest
910

1011

1112
class TestRegistration:
@@ -157,3 +158,21 @@ def test_expired_token(client: FlaskClient):
157158
}, follow_redirects=True)
158159
success_login_response = client.get('/exercises')
159160
assert success_login_response.status_code == 200
161+
162+
@staticmethod
163+
def test_registartion_closed(client: FlaskClient, captured_templates):
164+
conftest.disable_registration()
165+
client.post('/signup', data={
166+
'email': 'some_user123@mail.com',
167+
'username': 'some_user',
168+
'fullname': 'some_name',
169+
'password': 'some_password',
170+
'confirm': 'some_password',
171+
}, follow_redirects=True)
172+
user = User.get_or_none(User.username == 'some_user')
173+
assert user is None
174+
175+
response = client.get('/signup')
176+
template, _ = captured_templates[-1]
177+
assert template.name == 'login.html'
178+
assert '/signup' not in response.get_data(as_text=True)

0 commit comments

Comments
 (0)