GitHub Social Login + Auth flow fixes. Password reset, email verification, etc.
This commit is contained in:
1 parent
f7cf22f970
commit
921b760f80
23 files changed
+1087
-228
No files matched your search
@@ -1,4 +1,50 @@
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
|
||||
|
||||
from .models import ExternalIdentity
|
||||
|
||||
|
||||
class NativePasswordResetForm(PasswordResetForm):
|
||||
"""Password reset form that excludes SSO-linked accounts."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["email"].widget.attrs.update(
|
||||
{
|
||||
"class": "block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500",
|
||||
"placeholder": "you@example.com",
|
||||
}
|
||||
)
|
||||
|
||||
def get_users(self, email):
|
||||
UserModel = get_user_model()
|
||||
email_field_name = UserModel.get_email_field_name()
|
||||
users = UserModel._default_manager.filter(
|
||||
**{
|
||||
f"{email_field_name}__iexact": email,
|
||||
"is_active": True,
|
||||
}
|
||||
)
|
||||
for user in users:
|
||||
email_value = getattr(user, email_field_name, "") or ""
|
||||
if not user.has_usable_password():
|
||||
continue
|
||||
if ExternalIdentity.objects.filter(user=user).exists():
|
||||
continue
|
||||
if email.lower() != email_value.lower():
|
||||
continue
|
||||
yield user
|
||||
|
||||
|
||||
class StyledSetPasswordForm(SetPasswordForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
field_attrs = {
|
||||
"class": "block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500",
|
||||
}
|
||||
self.fields["new_password1"].widget.attrs.update(field_attrs)
|
||||
self.fields["new_password2"].widget.attrs.update(field_attrs)
|
||||
|
||||
|
||||
class ErasureRequestForm(forms.Form):
|
||||
|
||||
Reference in new issue
Block a user