Unify the two login forms
authorMagnus Hagander <magnus@hagander.net>
Wed, 9 Aug 2017 14:27:52 +0000 (16:27 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 9 Aug 2017 14:27:52 +0000 (16:27 +0200)
Instead of having two completely different forms for general login and
community authentication login with the only difference being the url
and the intro text, make it take a parameter instead and have just one
copy of the rest.

pgweb/account/views.py
templates/account/communityauth.html [deleted file]
templates/account/login.html

index 21ba7532ba16f27825390d94feda3d5b2aa8c601..8acb292da63d1ed9f15484d437de9d9c85c77582 100644 (file)
@@ -326,11 +326,13 @@ def communityauth(request, siteid):
                        urldata = "?su=%s" % su
                else:
                        urldata = ""
-               return render_to_response('account/communityauth.html', {
-                               'sitename': site.name,
-                               'next': '/account/auth/%s/%s' % (siteid, urldata),
-                               }, NavContext(request, 'account'))
-
+               return authviews.login(request, template_name='account/login.html',
+                                                          authentication_form=PgwebAuthenticationForm,
+                                                          extra_context={
+                                                                  'sitename': site.name,
+                                                                  'next': '/account/auth/%s/%s' % (siteid, urldata),
+                                                          },
+                                                  )
 
        # When we reach this point, the user *has* already been authenticated.
        # The request variable "su" *may* contain a suburl and should in that
diff --git a/templates/account/communityauth.html b/templates/account/communityauth.html
deleted file mode 100644 (file)
index 212a89c..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-{%extends "base/page.html"%}
-{%block contents%}
-<h1>Community authentication</h1>
-<p>
-The website you are trying to log in to ({{sitename}}) is using the
-postgresql.org community login system. In this system you create a
-central account that is used to log into most postgresql.org services.
-Once you are logged into this account, you will automatically be
-logged in to the associated postgresql.org services. Note that this
-single sign on is only used for official postgresql.org websites.
-</p>
-<p>
-If you do not already have an account, you may
-<a href="/account/signup/">sign up</a> for one now.
-If you have one but have lost your
-password, you can use the <a href="/account/reset/">password reset</a> form.
-</p>
-
-<form action="/account/login/" method="post" id="login-form">{% csrf_token %}
-  <div class="form-row">
-    <label for="id_username">Username:</label> <input type="text" name="username" id="id_username" />
-  </div>
-  <div class="form-row">
-    <label for="id_password">Password:</label> <input type="password" name="password" id="id_password" />
-    <input type="hidden" name="this_is_the_login_form" value="1" />
-    <input type="hidden" name="next" value="{{next}}" />
-  </div>
-  <div class="submit-row">
-    <label>&nbsp;</label><input type="submit" value="Log in" />
-  </div>
-</form>
-
-<script type="text/javascript">
-document.getElementById('id_username').focus()
-</script>
-
-{%endblock%}
-
index 7783b1b3be4e46657dcfb104f4becedda5f9b28c..3cac7c8cd8b1d516516472f93189eebeaad3b82c 100644 (file)
@@ -2,7 +2,19 @@
 {%block contents%}
 <h1>Log in</h1>
 <p>
-Please log in to your community account to reach this area. If you do not already have an account,
+{%if sitename%}
+The website you are trying to log in to ({{sitename}}) is using the
+postgresql.org community login system. In this system you create a
+central account that is used to log into most postgresql.org services.
+Once you are logged into this account, you will automatically be
+logged in to the associated postgresql.org services. Note that this
+single sign on is only used for official postgresql.org websites.
+{%else%}
+Please log in to your community account to reach this area.
+{%endif%}
+</p>
+<p>
+If you do not already have an account,
 you may <a href="/account/signup/">sign up</a> for one now. If you have one but have lost your
 password, you can use the <a href="/account/reset/">password reset</a> form.
 </p>