diff --git a/rowers/backends.py b/rowers/backends.py index 55ae2ca1..a9cf55b2 100644 --- a/rowers/backends.py +++ b/rowers/backends.py @@ -1,6 +1,10 @@ from rules.permissions import ObjectPermissionBackend from rowers.models import User +from django.contrib.auth import get_user_model # gets the user_model django default or your own custom +from django.contrib.auth.backends import ModelBackend +from django.db.models import Q + class MyObjectPermissionBackend(ObjectPermissionBackend): def user_can_authenticate(self, user): return getattr(user, "is_active", True) @@ -11,4 +15,31 @@ class MyObjectPermissionBackend(ObjectPermissionBackend): except User.DoesNotExist: return None return user if self.user_can_authenticate(user) else None + +class EmailLoginBackend(ModelBackend): + def user_can_authenticate(self, user): + return getattr(user, "is_active", True) + + def authenticate(self, request, username=None, password=None, **kwargs): + try: + user = User.objects.filter( + Q(username__iexact=username) | + Q(email__iexact=username) + ).distinct() + except User.DoesNotExist: + return None + + if user.exists(): + user_obj = user.first() + if user_obj.check_password(password) and user_obj.is_active: + return user_obj + return None + else: + return None + + def get_user(self, user_id): + try: + return User.objects.get(pk=user_id) + except User.DoesNotExist: + return None diff --git a/rowers/forms.py b/rowers/forms.py index 311f1fa5..641afe89 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -1233,12 +1233,12 @@ class ExportChoices(forms.Form): class AssignChoices(forms.Form): remove_workout = forms.BooleanField(initial=False, required=False) - destination = forms.ModelMultipleChoiceField(label='Rowers', required=False, + rowers = forms.ModelMultipleChoiceField(label='Rowers', required=False, queryset=Rower.objects.filter(), widget=forms.CheckboxSelectMultiple()) def __init__(self, *args, **kwargs): super(AssignChoices, self).__init__(*args, **kwargs) - self.fields['destination'].queryset = Rower.objects.filter() + self.fields['rowers'].queryset = Rower.objects.filter() class WorkoutMultipleCompareForm(forms.Form): workouts = forms.ModelMultipleChoiceField( diff --git a/rowers/templates/workout_bulk_actions.html b/rowers/templates/workout_bulk_actions.html index 0c50413c..3d24853a 100644 --- a/rowers/templates/workout_bulk_actions.html +++ b/rowers/templates/workout_bulk_actions.html @@ -5,6 +5,7 @@ {% block title %}Change Workout {% endblock %} {% block main %} +
Edit and confirm the action you want to perform on the following workouts:
-+
+
+
+