8000 Allow login form to define a custom field_name as a class attribute by codingjoe · Pull Request #84 · codingjoe/django-mail-auth · GitHub
[go: up one dir, main page]

Skip to content

Allow login form to define a custom field_name as a class attribute #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mailauth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ class EmailLoginForm(BaseLoginForm):
email_template_name = "registration/login_email.txt"
html_email_template_name = "registration/login_email.html"
from_email = None
field_name = None

def __init__(self, request, *args, **kwargs):
self.request = request
super().__init__(*args, **kwargs)

self.field_name = get_user_model().get_email_field_name()
self.field_name = self.field_name or get_user_model().get_email_field_name()
model_field = get_user_model()._meta.get_field(self.field_name)
field = model_field.formfield()
field.required = True
Expand Down
0