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 %} -
-

Log In

-
- {% csrf_token %} - {{ form }} - -
- -
-
-
- {% csrf_token %} - -
-
+
+
+
+ +
+
+
{% endblock %} diff --git a/app/templates/accounts/password_reset_complete.html b/app/templates/accounts/password_reset_complete.html index caec7e04..47d75de7 100644 --- a/app/templates/accounts/password_reset_complete.html +++ b/app/templates/accounts/password_reset_complete.html @@ -1,11 +1,21 @@ {% extends 'base.html' %} +{% load static %} +{% load i18n %} -{% block title %}Password reset complete{% endblock %} +{% block title %}{% trans "Password reset complete" %}{% endblock %} {% block content %} -
-

Your password has been set. You may go ahead and log in now.

-
-

Log in

+
+
+ +
{% endblock %} diff --git a/app/templates/accounts/password_reset_confirm.html b/app/templates/accounts/password_reset_confirm.html index 74974523..89a7d6cb 100644 --- a/app/templates/accounts/password_reset_confirm.html +++ b/app/templates/accounts/password_reset_confirm.html @@ -1,43 +1,50 @@ {% extends "base.html" %} +{% load static %} +{% load i18n %} -{% block title %}Enter new password{% endblock %} +{% block title %}{% trans "Enter new password" %}{% endblock %} {% block content %} {% if validlink %} -
-

Please enter your new password twice so we can verify you typed it in correctly.

- -
{% csrf_token %} -
-
- {{ form.new_password1.errors }} -
- - {{ form.new_password1 }} +
+
+ -
- {{ form.new_password2.errors }} -
- - {{ form.new_password2 }} +
+ {{ form.new_password2.errors }} +
+ + {{ form.new_password2 }} +
+
+
+
+
+
- -
-
-
- -
-
+ - {% else %} + {% else %} -

"The password reset link was invalid, possibly because it has already been used. Please request a new - password reset.

+

{% blocktrans %}The password reset link was invalid, possibly because it has already been used. Please request a new + password reset.{% endblocktrans %}

- {% endif %} + {% endif %} +
+
+ {% endblock %} diff --git a/app/templates/accounts/password_reset_done.html b/app/templates/accounts/password_reset_done.html index 0083930c..3bb37be6 100644 --- a/app/templates/accounts/password_reset_done.html +++ b/app/templates/accounts/password_reset_done.html @@ -1,13 +1,19 @@ {% extends "base.html" %} +{% load static %} +{% load i18n %} {% block title %}Email Sent{% endblock %} {% block content %} -
-

We’ve emailed you instructions for setting your password, if an account exists with the email you entered. - You should receive them shortly.

+
+
+
+
{% endblock %} diff --git a/app/templates/accounts/password_reset_form.html b/app/templates/accounts/password_reset_form.html index 1f4ea298..a23fafcf 100644 --- a/app/templates/accounts/password_reset_form.html +++ b/app/templates/accounts/password_reset_form.html @@ -1,28 +1,34 @@ {% extends 'base.html' %} +{% load static %} +{% load i18n %} -{% block title %}Forgot Your Password?{% endblock %} +{% block title %}{% trans "Forgot Your Password?" %}{% endblock %} {% block content %} -
-

Forgotten your password? Enter your email address below, and we’ll email instructions for setting a new - one.

+
+
+ +
{% endblock %} diff --git a/app/templates/accounts/register.html b/app/templates/accounts/register.html index 8cfaafb3..9f0c4bf5 100644 --- a/app/templates/accounts/register.html +++ b/app/templates/accounts/register.html @@ -1,14 +1,47 @@ {% extends "base.html" %} +{% load static %} +{% load i18n %} -{% block title %}Sign Up{% endblock %} +{% block title %}{% trans "Sign Up" %}{% endblock %} {% block content %} -
-

Register

-
- {% csrf_token %} - {{ form.as_p }} - -
+
+
+
+ +
+
{% endblock %} diff --git a/app/templates/base_error.html b/app/templates/base_error.html index ade2424f..fb417d62 100644 --- a/app/templates/base_error.html +++ b/app/templates/base_error.html @@ -4,7 +4,7 @@ {% block content %}
-
+
{% trans "Error" %}