diff --git a/parent/mailauth/templates/mailauth/login.html b/parent/mailauth/templates/mailauth/login.html index 94dff2b8..0ed67788 100644 --- a/parent/mailauth/templates/mailauth/login.html +++ b/parent/mailauth/templates/mailauth/login.html @@ -1,10 +1,7 @@ -{% extends 'base/base.html' %} +{% extends 'base/babex_base.html' %} {% load i18n %} {% block content %} -
-

ILS Babylab

-

{% trans 'parent:mailauth:login:header' %}

diff --git a/parent/mailauth/views.py b/parent/mailauth/views.py index 651c7ded..7bfb5d31 100644 --- a/parent/mailauth/views.py +++ b/parent/mailauth/views.py @@ -47,6 +47,9 @@ class LoginFormView(FormView): success_url = reverse_lazy("mailauth:sent") def form_valid(self, form): - # TODO: check the response - gateway(self.request, "/gateway/mailauth/", data=dict(email=form.cleaned_data["email"])) - return super().form_valid(form) + ok, _ = gateway(self.request, "/gateway/mailauth/", data=dict(email=form.cleaned_data["email"])) + if ok: + return super().form_valid(form) + messages.error(self.request, "login failed") + return super().get(self.request) + diff --git a/parent/parent/templates/base/babex_base.html b/parent/parent/templates/base/babex_base.html new file mode 100644 index 00000000..39c2f151 --- /dev/null +++ b/parent/parent/templates/base/babex_base.html @@ -0,0 +1,7 @@ +{% extends 'base/base.html' %} +{% block uu-content %} +
+

ILS Babylab

+
+ {{ block.super }} +{% endblock %} \ No newline at end of file diff --git a/parent/parent/utils.py b/parent/parent/utils.py index cd4f876a..529c55d8 100644 --- a/parent/parent/utils.py +++ b/parent/parent/utils.py @@ -43,12 +43,17 @@ def gateway( else: method = "get" - response = requests.request( - method=method.upper(), - url=settings.API_HOST + url, - headers=headers, - json=data, - ) + try: + response = requests.request( + method=method.upper(), + url=settings.API_HOST + url, + headers=headers, + json=data, + ) + except Exception: + log.exception("Could not reach gateway") + return False, dict() + if not response.ok: log.error("Gateway request %s failed: %s", url, response.text) if len(response.text): diff --git a/parent/parent/views.py b/parent/parent/views.py index 9587d4db..6dbfd2ac 100644 --- a/parent/parent/views.py +++ b/parent/parent/views.py @@ -52,8 +52,11 @@ def form_valid(self, form): # filter out blank fields fields = {key: value for key, value in form.cleaned_data.items() if value is not None} signup = Signup(**fields) - signup.put(as_json=True) - return super().form_valid(form) + if signup.put(as_json=True): + return super().form_valid(form) + + log.error("Couldn't reach server while processing signup") + return super().get(self.request) class SignupDone(TemplateView):