diff --git a/accounts_app/backends.py b/accounts_app/backends.py new file mode 100644 index 0000000..7cf0fe5 --- /dev/null +++ b/accounts_app/backends.py @@ -0,0 +1,27 @@ +from django.contrib.auth.backends import ModelBackend +from django.contrib.auth import get_user_model + +User = get_user_model() + + +class EmailBackend(ModelBackend): + """ + Custom authentication backend that authenticates users using email instead of username. + """ + + def authenticate(self, request, email=None, password=None, **kwargs): + if email is None or password is None: + return None + + try: + user = User.objects.get(email=email) + except User.DoesNotExist: + # Run the default password hasher once to reduce timing attacks + User().set_password(password) + return None + + if user.check_password(password) and self.user_can_authenticate(user): + return user + + return None + diff --git a/accounts_app/forms/edit_user_form.py b/accounts_app/forms/edit_user_form.py index 53fbcef..4469eac 100644 --- a/accounts_app/forms/edit_user_form.py +++ b/accounts_app/forms/edit_user_form.py @@ -6,4 +6,4 @@ class EditUserForm(forms.ModelForm): class Meta: model = User - fields = ["first_name", "last_name"] \ No newline at end of file + fields = ["first_name", "last_name", "occupation"] \ No newline at end of file diff --git a/accounts_app/templates/accounts_app/profile.html b/accounts_app/templates/accounts_app/profile.html index 31b5137..ea59233 100644 --- a/accounts_app/templates/accounts_app/profile.html +++ b/accounts_app/templates/accounts_app/profile.html @@ -10,9 +10,10 @@

Welcome back, {{ user.full_na id="edit_profile_form" hx-post="{% url 'home' %}" hx-trigger="submit" - hx-swap="multi:#edit_profile_form:outerHTML,h1:outerHTML" + hx-swap="multi:#edit_profile_form:outerHTML,#edit_profile_header:outerHTML" hx-ext="multi" > + {% csrf_token %}
Welcome back, {{ user.full_na required >
+
+ + +
+ + + + + + +