diff --git a/app/accounts/forms.py b/app/accounts/forms.py index e8cb29e7..c58c33a4 100644 --- a/app/accounts/forms.py +++ b/app/accounts/forms.py @@ -1,14 +1,26 @@ from django import forms -from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.forms import AuthenticationForm, UserCreationForm +from django.utils.translation import gettext_lazy as _ from users.models import CustomUser class CustomUserCreationForm(UserCreationForm): - email = forms.EmailField(required=True, help_text="Required. Add a valid email address.") - username = forms.CharField(required=True, help_text="Required. Add a valid username.") - first_name = forms.CharField(required=True, help_text="Required. Add a valid first name.") - last_name = forms.CharField(required=True, help_text="Required. Add a valid last name.") + email = forms.EmailField( + required=True, + help_text=_("Required. Add a valid email address."), + ) + username = forms.CharField( + required=True, + help_text=_("Required. Add a valid username."), + ) + first_name = forms.CharField( + required=True, + help_text=_("Required. Add a valid first name."), + ) + last_name = forms.CharField( + required=True, + ) class Meta: model = CustomUser @@ -16,7 +28,15 @@ class Meta: def __init__(self, *args, **kwargs): super(CustomUserCreationForm, self).__init__(*args, **kwargs) - self.fields["email"].required = True - self.fields["username"].required = True - self.fields["first_name"].required = True - self.fields["last_name"].required = True + for field_name, field in self.fields.items(): + field.widget.attrs["class"] = "form-control" + + +class CustomAuthenticationForm(AuthenticationForm): + username = forms.CharField(label=_("Username"), help_text=_("Required. Enter your username.")) + password = forms.CharField(label=_("Password"), help_text=_("Required. Enter your password.")) + + def __init__(self, *args, **kwargs): + super(CustomAuthenticationForm, self).__init__(*args, **kwargs) + for field in self.fields.values(): + field.widget.attrs.update({"class": "form-control"}) diff --git a/app/accounts/views.py b/app/accounts/views.py index b2eabcb4..e02657fa 100644 --- a/app/accounts/views.py +++ b/app/accounts/views.py @@ -1,7 +1,8 @@ -from django.contrib.auth import login +from django.contrib.auth import authenticate +from django.contrib.auth import login as auth_login from django.shortcuts import redirect, render -from .forms import CustomUserCreationForm +from .forms import CustomAuthenticationForm, CustomUserCreationForm def register(request): @@ -11,8 +12,21 @@ def register(request): user = form.save(commit=False) user.is_staff = True user.save() - login(request, user) + auth_login(request, user) return redirect("home") else: form = CustomUserCreationForm() return render(request, "accounts/register.html", {"form": form}) + + +def user_login(request): + if request.method == "POST": + form = CustomAuthenticationForm(request, data=request.POST) + if form.is_valid(): + user = form.get_user() + auth_login(request, user) + return redirect("home") + else: + form = CustomAuthenticationForm() + + return render(request, "accounts/login.html", {"form": form}) diff --git a/app/static/css/styles.css b/app/static/css/styles.css index d8ff1f36..438c5e2e 100755 --- a/app/static/css/styles.css +++ b/app/static/css/styles.css @@ -344,12 +344,20 @@ html { font-size: 0.875rem; } +/*Accounts*/ +.user-account-body { + margin: 30px; +} +.login-form-group .form-control { + width: 100%; + max-width: 500px; +} /*Error pages*/ -.error-card { +.body-card { border-color: var(--primary-red); - margin: 0 10px 0 10px; + margin: 10px; width: 100%; } diff --git a/app/templates/accounts/login.html b/app/templates/accounts/login.html index 99b7250d..b782503b 100644 --- a/app/templates/accounts/login.html +++ b/app/templates/accounts/login.html @@ -1,22 +1,76 @@ {% extends "base.html" %} +{% load static %} +{% load i18n %} -{% block title %}Log In{% endblock %} +{% block title %}{% trans "Log In" %}{% endblock %} {% block content %} -
{% trans "Don't have an account?" %} {% trans "Create one" %}
+Your password has been set. You may go ahead and log in now.
-{% trans "Your password has been set. You may go ahead and log in now." %}
+Please enter your new password twice so we can verify you typed it in correctly.
- -