Browse Source

Don't set CSRF cookie on first visit. Signup is exempt from CSRF protection.

pull/313/head
Pēteris Caune 5 years ago
parent
commit
1cdb6e6d1d
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 4 additions and 4 deletions
  1. +3
    -0
      CHANGELOG.md
  2. +1
    -0
      hc/accounts/views.py
  3. +0
    -2
      static/js/signup.js
  4. +0
    -2
      templates/front/signup_modal.html

+ 3
- 0
CHANGELOG.md View File

@ -8,6 +8,9 @@ All notable changes to this project will be documented in this file.
- Show Healthchecks version in Django admin header (#306) - Show Healthchecks version in Django admin header (#306)
- Added JSON endpoint for Shields.io (#304) - Added JSON endpoint for Shields.io (#304)
### Bug Fixes
- Don't set CSRF cookie on first visit. Signup is exempt from CSRF protection.
## v1.11.0 - 2019-11-22 ## v1.11.0 - 2019-11-22


+ 1
- 0
hc/accounts/views.py View File

@ -144,6 +144,7 @@ def logout(request):
@require_POST @require_POST
@csrf_exempt
def signup(request): def signup(request):
if not settings.REGISTRATION_OPEN: if not settings.REGISTRATION_OPEN:
return HttpResponseForbidden() return HttpResponseForbidden()


+ 0
- 2
static/js/signup.js View File

@ -3,13 +3,11 @@ $(function () {
function submitForm() { function submitForm() {
var base = document.getElementById("base-url").getAttribute("href").slice(0, -1); var base = document.getElementById("base-url").getAttribute("href").slice(0, -1);
var email = $("#signup-email").val(); var email = $("#signup-email").val();
var token = $('input[name=csrfmiddlewaretoken]').val();
$("#signup-go").prop("disabled", true); $("#signup-go").prop("disabled", true);
$.ajax({ $.ajax({
url: base + "/accounts/signup/", url: base + "/accounts/signup/",
type: "post", type: "post",
headers: {"X-CSRFToken": token},
data: {"identity": email}, data: {"identity": email},
success: function(data) { success: function(data) {
$("#signup-result").html(data).show(); $("#signup-result").html(data).show();


+ 0
- 2
templates/front/signup_modal.html View File

@ -20,8 +20,6 @@
We will email you a magic sign in link. We will email you a magic sign in link.
</p> </p>
{% csrf_token %}
<button id="signup-go" class="btn btn-lg btn-primary btn-block"> <button id="signup-go" class="btn btn-lg btn-primary btn-block">
Email Me a Link Email Me a Link
</button> </button>


Loading…
Cancel
Save