Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed registration form, cleaned up login flow #3821

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hypha/apply/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PasswordlessAuthForm(forms.Form):
"""

email = forms.EmailField(
label=_("Email Address"),
label=_("Email address"),
required=True,
max_length=254,
widget=forms.EmailInput(attrs={"autofocus": True, "autocomplete": "email"}),
Expand Down
4 changes: 2 additions & 2 deletions hypha/apply/users/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_email_context(self) -> dict:

def send_email_no_account_found(self, to):
context = self.get_email_context()
subject = "Login attempt at {org_long_name}".format(**context)
subject = "Log in attempt at {org_long_name}".format(**context)
# Force subject to a single line to avoid header-injection issues.
subject = "".join(subject.splitlines())

Expand Down Expand Up @@ -91,7 +91,7 @@ def send_login_email(self, user):
}
)

subject = "Login to {username} at {org_long_name}".format(**context)
subject = "Log in to {username} at {org_long_name}".format(**context)
# Force subject to a single line to avoid header-injection issues.
subject = "".join(subject.splitlines())

Expand Down
37 changes: 17 additions & 20 deletions hypha/apply/users/templates/users/login.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% extends "base-apply.html" %}
{% load i18n wagtailcore_tags %}
{% load i18n wagtailcore_tags heroicons %}

{% block title %}{% trans "Login" %}{% endblock %}
{% block title %}{% trans "Log in" %}{% endblock %}
{% block body_class %}bg-white{% endblock %}

{% block content %}
<div class="w-full grid bg-white mt-5 md:py-4">
<div class="max-w-2xl grid bg-white mt-5 md:py-4">

<section>
<div class="px-4 pt-4">
Expand All @@ -23,10 +23,10 @@ <h2 class="text-2xl">{% trans "Two factor verification" %}</h2>
{% elif wizard.steps.current == 'backup' %}
<h2 class="text-2xl">{% trans "Two factor verification" %}</h2>
<p>
{% blocktrans trimmed %}Please enter one of the backup codes to login to your account.{% endblocktrans %}
{% blocktrans trimmed %}Please enter one of the backup codes to log in to your account.{% endblocktrans %}
</p>
<p class="text-sm mb-4 text-fg-muted">
Those codes were generated for you during 2FA setup to print or keep safe in a password manager.
{% blocktrans trimmed %}Those codes were generated for you during 2FA setup to print or keep safe in a password manager.{% endblocktrans %}
</p>
{% endif %}

Expand Down Expand Up @@ -61,24 +61,21 @@ <h2 class="text-2xl">{% blocktrans %}Log in to {{ ORG_SHORT_NAME }}{% endblocktr
{% endif %}

<div class="form__group max-w-sm flex items-center justify-between gap-4">
<button class="link link--button link--button-secondary" type="submit">{% trans "Log in" %}</button>

{% if ENABLE_PUBLIC_SIGNUP %}
<a class="hover:opacity-75" href="{% url 'users:register' %}{% if redirect_url %}?next={{ redirect_url }}{% endif %}" hx-boost="true"> {% trans "Create account" %}</a>
{% endif %}
<button class="link link--button link--button--login" type="submit">{% trans "Log in" %}</button>
</div>

{% if GOOGLE_OAUTH2 %}
<div class="flex items-center justify-start relative">
<hr class="inline w-32 h-px my-6 bg-gray-300 border-0">
<span class="px-3 text-gray-400 font-medium">{% trans "or" %}</span>
<hr class="inline w-32 h-px my-6 bg-gray-300 border-0">
</div>
<div class="flex items-center justify-center min-[465px]:justify-start relative mb-4">
<hr class="inline w-32 h-px my-6 bg-gray-300 border-0">
<span class="px-3 text-gray-400 font-medium">{% trans "or" %}</span>
<hr class="inline w-32 h-px my-6 bg-gray-300 border-0">
</div>

<div class="">
<a class="link link--button link--button-tertiary" href="{% url "social:begin" "google-oauth2" %}{% if next %}?next={{ next }}{% endif %}">{% blocktrans %}Log in with your {{ ORG_SHORT_NAME }} email{% endblocktrans %}</a>
</div>
{% endif %}
<section class="space-y-0.5">
{% if GOOGLE_OAUTH2 %}
{% include "includes/org_login_button.html" %}
{% endif %}
{% include "includes/passwordless_login_button.html" %}
</section
{% else %}

<div class="form__group">
Expand Down
8 changes: 1 addition & 7 deletions hypha/apply/users/templates/users/password_reset/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ <h2 class="text-2xl">{% trans "Forgot password?" %}</h2>
<p>{{ form.email.label_tag }}</p>
<p>{{ form.email }}</p>

<button class="btn btn-primary" type="submit">{% trans "Send reset email" %}</button>
<button class="link link--button link--button--login" type="submit">{% trans "Send reset email" %}</button>
</form>

<div class="mt-4">
<a href="{% url 'users:login' %}{% if redirect_url %}?next={{ redirect_url }}{% endif %}" hx-boost="true">
{% trans "Log in" %}
</a>
</div>
</div>
</section>
{% endblock %}
29 changes: 10 additions & 19 deletions hypha/apply/users/templates/users/passwordless_login_signup.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% extends base_template %}
{% load i18n wagtailcore_tags heroicons %}

{% block title %}{% trans "Login or Signup" %}{% endblock %}
{% block title %}
{% trans "Log in" %}{% if ENABLE_PUBLIC_SIGNUP %} {% trans "or" %} {% trans "Sign up" %}{% endif %}
{% endblock %}

{% block content %}
<div class="max-w-2xl bg-white mt-5 md:py-4">
Expand All @@ -16,9 +18,9 @@

<h2 class="text-2xl">
{% if ENABLE_PUBLIC_SIGNUP %}
{% blocktrans %}Login or signup to {{ ORG_SHORT_NAME }}{% endblocktrans %}
{% blocktrans %}Log in or signup to {{ ORG_SHORT_NAME }}{% endblocktrans %}
{% else %}
{% blocktrans %}Login to {{ ORG_SHORT_NAME }}{% endblocktrans %}
{% blocktrans %}Log in to {{ ORG_SHORT_NAME }}{% endblocktrans %}
{% endif %}
</h2>

Expand All @@ -42,32 +44,21 @@ <h2 class="text-2xl">
{% endif %}

<div class="form__group">
<button class="link link--button link--button-secondary" type="submit">{% trans "Next" %}</button>
<button class="link link--button link--button--login" type="submit">{% trans "Next" %}</button>
</div>

<div class="flex items-center justify-start relative mb-4">
<div class="flex items-center justify-center min-[465px]:justify-start relative mb-4">
<hr class="inline w-32 h-px my-6 bg-gray-300 border-0">
<span class="px-3 text-gray-400 font-medium">{% trans "or" %}</span>
<hr class="inline w-32 h-px my-6 bg-gray-300 border-0">
</div>

<section>
<section class="space-y-0.5">
{% if GOOGLE_OAUTH2 %}
<a
class="link link--button link--button-tertiary"
href="{% url "social:begin" "google-oauth2" %}{% if next %}?next={{ next }}{% endif %}"
>
{% blocktrans %}Log in with your {{ ORG_SHORT_NAME }} email{% endblocktrans %}
</a>
{% include "includes/org_login_button.html" %}
{% endif %}

<a
class="link link--button link--button-tertiary"
href="{% url 'users:login' %}{% if next %}?next={{next}}{% endif %}"
>
{% heroicon_mini "key" size=18 class="inline align-text-bottom me-1" aria_hidden=true %}
{% trans "Login with Password" %}
</a>
{% include "includes/password_login_button.html" %}
</section>
</form>
</section>
Expand Down
45 changes: 0 additions & 45 deletions hypha/apply/users/templates/users/register.html

This file was deleted.

71 changes: 0 additions & 71 deletions hypha/apply/users/tests/test_registration.py

This file was deleted.

6 changes: 0 additions & 6 deletions hypha/apply/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
PasswordlessSignupView,
PasswordResetConfirmView,
PasswordResetView,
RegisterView,
RegistrationSuccessView,
TWOFAAdminDisableView,
TWOFADisableView,
TWOFASetupView,
Expand All @@ -39,10 +37,6 @@
),
path("login/", LoginView.as_view(), name="login"),
path("logout/", auth_views.LogoutView.as_view(next_page="/"), name="logout"),
path("register/", RegisterView.as_view(), name="register"),
path(
"register-success/", RegistrationSuccessView.as_view(), name="register-success"
),
]

account_urls = [
Expand Down
64 changes: 2 additions & 62 deletions hypha/apply/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.core.exceptions import PermissionDenied
from django.core.signing import TimestampSigner, dumps, loads
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import Http404, get_object_or_404, redirect, render, resolve_url
from django.shortcuts import Http404, get_object_or_404, redirect, render
from django.template.loader import render_to_string
from django.template.response import TemplateResponse
from django.urls import reverse, reverse_lazy
Expand All @@ -30,7 +30,7 @@
from django.views.decorators.cache import never_cache
from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic import UpdateView
from django.views.generic.base import TemplateView, View
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView
from django_htmx.http import HttpResponseClientRedirect
from django_otp import devices_for_user
Expand All @@ -56,7 +56,6 @@
from .forms import (
BecomeUserForm,
CustomAuthenticationForm,
CustomUserCreationForm,
Disable2FAConfirmationForm,
PasswordlessAuthForm,
ProfileForm,
Expand All @@ -74,65 +73,6 @@
User = get_user_model()


@method_decorator(
ratelimit(key="ip", rate=settings.DEFAULT_RATE_LIMIT, method="POST"),
name="dispatch",
)
class RegisterView(View):
redirect_field_name = "next"
form = CustomUserCreationForm

def get(self, request):
# We keep /register in the urls in order to test (where we turn on/off
# the setting per test), but when disabled, we want to pretend it doesn't
# exist va 404
if not settings.ENABLE_PUBLIC_SIGNUP:
raise Http404

if request.user.is_authenticated:
return redirect(settings.LOGIN_REDIRECT_URL)

ctx = {
"form": self.form(register_view=True),
"redirect_url": get_redirect_url(request, self.redirect_field_name),
}
return render(request, "users/register.html", ctx)

def post(self, request):
# See comment in get() above about doing this here rather than in urls
if not settings.ENABLE_PUBLIC_SIGNUP:
raise Http404

form = self.form(register_view=True, data=request.POST)
context = {}
if form.is_valid():
# If using wagtail password management
if "password1" in form.cleaned_data:
context["password"] = form.cleaned_data["password1"]

site = Site.find_for_request(self.request)
user, created = User.objects.get_or_create_and_notify(
email=form.cleaned_data["email"],
site=site,
redirect_url=get_redirect_url(request, self.redirect_field_name),
defaults={
"full_name": form.cleaned_data["full_name"],
},
**context,
)
if created:
params = {"name": user.full_name, "email": user.email}
# redirect to success page with params as query params
return HttpResponseRedirect(
resolve_url("users:register-success") + "?" + urlencode(params)
)
return render(request, "users/register.html", {"form": form})


class RegistrationSuccessView(TemplateView):
template_name = "users/register-success.html"


@method_decorator(
ratelimit(key="ip", rate=settings.DEFAULT_RATE_LIMIT, method="POST"),
name="dispatch",
Expand Down
Loading
Loading