Repository: ocadotechnology/codeforlife-portal

Issue:
Convert login and register popups to actual pages



Discussion:

Resolving patch:
diff --git a/portal/urls.py b/portal/urls.py
--- a/portal/urls.py
+++ b/portal/urls.py
@@ -65,7 +65,7 @@
 
 from game.views.level import play_default_level
 
-from portal.views.home_new import home_new, teach_new, play_new, about_new, help_and_support_new, terms_new, login_popup, register_popup
+from portal.views.home_new import login_view, register_view
 
 js_info_dict = {
     'packages': ('conf.locale',),
@@ -196,21 +196,21 @@
     url(r'^teach/solutions_navigation/(?P<levelName>[A-Z0-9]+)/$', default_solution, name='default_solution'),
     url(r'^(?P<levelName>[A-Z0-9]+)/$', play_default_level, name='play_default_level'),
 
-    url(r'^redesign/home', home_new, name='home_new'),
-    url(r'^redesign/register', register_popup, name='register_popup'),
-    url(r'^redesign/login', login_popup, name='login_popup'),
+    url(r'^redesign/home', TemplateView.as_view(template_name='redesign/home_new.html'), name='home_new'),
+    url(r'^redesign/register_form', register_view, name='register_new'),
+    url(r'^redesign/login_form', login_view, name='login_new'),
     url(r'^redesign/verify_email/(?P<token>[0-9a-f]+)/$', verify_email_new, name='verify_email_new'),
-    url(r'^redesign/teach/$', teach_new, name='teach_new'),
+    url(r'^redesign/teach/$', TemplateView.as_view(template_name='redesign/teach_new.html'), name='teach_new'),
     url(r'^redesign/teach/onboarding1/$', TemplateView.as_view(template_name='redesign/teach_new/onboarding_school.html'), name='onboarding1'),
     url(r'^redesign/teach/onboarding1-join', TemplateView.as_view(template_name='redesign/teach_new/onboarding_join_pending.html'), name='onboarding1-join'),
     url(r'^redesign/teach/onboarding2', TemplateView.as_view(template_name='redesign/teach_new/onboarding_classes.html'), name='onboarding2'),
     url(r'^redesign/teach/onboarding3', TemplateView.as_view(template_name='redesign/teach_new/onboarding_students.html'), name='onboarding3'),
     url(r'^redesign/teach/onboarding4', TemplateView.as_view(template_name='redesign/teach_new/onboarding_print.html'), name='onboarding4'),
     url(r'^redesign/teach/onboarding5', TemplateView.as_view(template_name='redesign/teach_new/onboarding_complete.html'), name='onboarding5'),
-    url(r'^redesign/play', play_new, name='play_new'),
-    url(r'^redesign/about', about_new, name='about_new'),
-    url(r'^redesign/help', help_and_support_new, name='help_new'),
-    url(r'^redesign/terms', terms_new, name='terms_new'),
+    url(r'^redesign/play', TemplateView.as_view(template_name='redesign/play_new.html'), name='play_new'),
+    url(r'^redesign/about', TemplateView.as_view(template_name='redesign/about_new.html'), name='about_new'),
+    url(r'^redesign/help', TemplateView.as_view(template_name='redesign/help-and-support_new.html'), name='help_new'),
+    url(r'^redesign/terms', TemplateView.as_view(template_name='redesign/terms_new.html'), name='terms_new'),
     url(r'^redesign/teach/materials', TemplateView.as_view(template_name='redesign/teach_new/materials_new.html'), name='materials_new'),
     url(r'^redesign/teach/dashboard', TemplateView.as_view(template_name='redesign/teach_new/dashboard.html'), name='dashboard'),
     url(r'^redesign/teach/class', TemplateView.as_view(template_name='redesign/teach_new/class_new.html'), name='class_new'),
diff --git a/portal/views/home_new.py b/portal/views/home_new.py
--- a/portal/views/home_new.py
+++ b/portal/views/home_new.py
@@ -62,8 +62,8 @@ def teach_email_labeller(request):
     return ''
 
 
-def login_popup(request):
-    return render_forms(request, 'redesign/login_popup.html')
+def login_view(request):
+    return render_login_form(request)
 
 
 def logout_view(request):
@@ -71,37 +71,13 @@ def logout_view(request):
     return HttpResponseRedirect(reverse_lazy('home_new'))
 
 
-def register_popup(request):
-    return render_forms(request, 'redesign/register_popup.html')
-
-
-def home_new(request):
-    return render_forms(request, 'redesign/home_new.html')
-
-
-def teach_new(request):
-    return render_forms(request, 'redesign/teach_new.html')
-
-
-def play_new(request):
-    return render_forms(request, 'redesign/play_new.html')
-
-
-def about_new(request):
-    return render_forms(request, 'redesign/about_new.html')
-
-
-def help_and_support_new(request):
-    return render_forms(request, 'redesign/help-and-support_new.html')
-
-
-def terms_new(request):
-    return render_forms(request, 'redesign/terms_new.html')
+def register_view(request):
+    return render_signup_form(request)
 
 
 @ratelimit('ip', periods=['1m'], increment=lambda req, res: hasattr(res, 'count') and res.count)
 @ratelimit('email', labeller=teach_email_labeller, ip=False, periods=['1m'], increment=lambda req, res: hasattr(res, 'count') and res.count)
-def render_forms(request, rendered_url):
+def render_login_form(request):
     invalid_form = False
 
     limits = getattr(request, 'limits', {'ip': [0], 'email': [0]})
@@ -112,27 +88,18 @@ def render_forms(request, rendered_url):
     OutputLoginForm = compute_output_login_form(LoginFormWithCaptcha, limits, captcha_limit)
 
     login_form = OutputLoginForm(prefix='login')
-    signup_form = TeacherSignupForm(prefix='signup')
 
     if request.method == 'POST':
-        if 'login' in request.POST:
-            login_form = InputLoginForm(request.POST, prefix='login')
-            if login_form.is_valid():
-                return process_login_form(request, login_form)
-
-            else:
-                login_form = OutputLoginForm(request.POST, prefix='login')
-                invalid_form = True
-
-        elif 'signup' in request.POST:
-            signup_form = TeacherSignupForm(request.POST, prefix='signup')
-            if signup_form.is_valid():
-                data = signup_form.cleaned_data
-                return process_signup_form(request, data)
-
-    res = render(request, rendered_url, {
+        login_form = InputLoginForm(request.POST, prefix='login')
+        if login_form.is_valid():
+            return process_login_form(request, login_form)
+
+        else:
+            login_form = OutputLoginForm(request.POST, prefix='login')
+            invalid_form = True
+
+    res = render(request, 'redesign/login.html', {
         'login_form': login_form,
-        'signup_form': signup_form,
         'logged_in_as_teacher': is_logged_in_as_teacher(request),
     })
 
@@ -140,6 +107,27 @@ def render_forms(request, rendered_url):
     return res
 
 
+@ratelimit('ip', periods=['1m'], increment=lambda req, res: hasattr(res, 'count') and res.count)
+@ratelimit('email', labeller=teach_email_labeller, ip=False, periods=['1m'], increment=lambda req, res: hasattr(res, 'count') and res.count)
+def render_signup_form(request):
+    invalid_form = False
+
+    signup_form = TeacherSignupForm(prefix='signup')
+
+    if request.method == 'POST':
+        signup_form = TeacherSignupForm(request.POST, prefix='signup')
+        if signup_form.is_valid():
+            data = signup_form.cleaned_data
+            return process_signup_form(request, data)
+
+    res = render(request, 'redesign/register.html', {
+        'signup_form': signup_form
+    })
+
+    res.count = invalid_form
+    return res
+
+
 def compute_use_captcha(limits, captcha_limit):
     using_captcha = (limits['ip'][0] > captcha_limit or limits['email'][0] > captcha_limit)
     return using_captcha


Test patch:
diff --git a/portal/tests/pageObjects/portal/base_page.py b/portal/tests/pageObjects/portal/base_page.py
--- a/portal/tests/pageObjects/portal/base_page.py
+++ b/portal/tests/pageObjects/portal/base_page.py
@@ -137,7 +137,6 @@ def go_to_login_page(self):
 
     def go_to_signup_page(self):
         self.browser.find_element_by_id('signup-button').click()
-        time.sleep(2)
         return signup_page.SignupPage(self.browser)
 
     def go_to_terms_page(self):
diff --git a/portal/tests/pageObjects/portal/login_page.py b/portal/tests/pageObjects/portal/login_page.py
--- a/portal/tests/pageObjects/portal/login_page.py
+++ b/portal/tests/pageObjects/portal/login_page.py
@@ -41,7 +41,6 @@
 import email_verification_needed_page
 from portal.tests.pageObjects.registration.teacher_password_reset_form_page import TeacherPasswordResetFormPage
 import teach.dashboard_page_new
-import home_page_new
 
 
 class LoginPage(BasePage):
@@ -57,7 +56,7 @@ def login(self, email, password):
 
     def login_failure(self, email, password):
         self._login(email, password)
-        return home_page_new.HomePage(self.browser)
+        return self
 
     def _login(self, email, password):
         self.browser.find_element_by_id('id_login-email').send_keys(email)
diff --git a/portal/tests/test_teacher_new.py b/portal/tests/test_teacher_new.py
--- a/portal/tests/test_teacher_new.py
+++ b/portal/tests/test_teacher_new.py
@@ -60,9 +60,8 @@ def test_login_failure(self):
         selenium.get(self.live_server_url + "/portal/redesign/home")
         page = HomePage(selenium)
         page = page.go_to_login_page()
-        time.sleep(1)
         page = page.login_failure('non-existent-email@codeforlife.com', 'Incorrect password')
-        assert self.is_home_page(page)
+        assert page.has_login_failed()
 
     def test_login_success(self):
         selenium.get(self.live_server_url + "/portal/redesign/home")
@@ -71,7 +70,6 @@ def test_login_success(self):
         selenium.get(self.live_server_url + "/portal/redesign/home")
         page = HomePage(selenium)
         page = page.go_to_login_page()
-        time.sleep(1)
         page = page.login(email, password)
         assert self.is_teacher_dashboard(page)