mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
setting for two mail fields on signup
This commit is contained in:
parent
1f03d43b92
commit
af286766ea
@ -13,7 +13,7 @@ from crispy_forms.helper import FormHelper
|
|||||||
from crispy_forms.layout import Layout, Field
|
from crispy_forms.layout import Layout, Field
|
||||||
from crispy_forms.bootstrap import PrependedText, AppendedText, PrependedAppendedText, StrictButton, Div
|
from crispy_forms.bootstrap import PrependedText, AppendedText, PrependedAppendedText, StrictButton, Div
|
||||||
|
|
||||||
from allauth.account.forms import SignupForm
|
from allauth.account.forms import SignupForm, set_form_field_order
|
||||||
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
||||||
|
|
||||||
from part.models import PartCategory
|
from part.models import PartCategory
|
||||||
@ -216,8 +216,36 @@ class CustomSignupForm(SignupForm):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
kwargs['email_required'] = InvenTreeSetting.get_setting('LOGIN_MAIL_REQUIRED')
|
kwargs['email_required'] = InvenTreeSetting.get_setting('LOGIN_MAIL_REQUIRED')
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# check for two mail fields
|
||||||
|
if InvenTreeSetting.get_setting('LOGIN_SIGNUP_MAIL_TWICE'):
|
||||||
|
self.fields["email2"] = forms.EmailField(
|
||||||
|
label=_("E-mail (again)"),
|
||||||
|
widget=forms.TextInput(
|
||||||
|
attrs={
|
||||||
|
"type": "email",
|
||||||
|
"placeholder": _("E-mail address confirmation"),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
# reorder fields
|
||||||
|
set_form_field_order(self, ["username", "email", "email2", "password1", "password2", ])
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super().clean()
|
||||||
|
|
||||||
|
# check for two mail fields
|
||||||
|
if InvenTreeSetting.get_setting('LOGIN_SIGNUP_MAIL_TWICE'):
|
||||||
|
email = cleaned_data.get("email")
|
||||||
|
email2 = cleaned_data.get("email2")
|
||||||
|
if (email and email2) and email != email2:
|
||||||
|
self.add_error("email2", _("You must type the same email each time."))
|
||||||
|
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
|
|
||||||
class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
|
class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
|
||||||
"""
|
"""
|
||||||
|
@ -858,6 +858,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
'default': True,
|
'default': True,
|
||||||
'validator': bool,
|
'validator': bool,
|
||||||
},
|
},
|
||||||
|
'LOGIN_SIGNUP_MAIL_TWICE': {
|
||||||
|
'name': _('Mail twice'),
|
||||||
|
'description': _('On signup ask users twice for their mail'),
|
||||||
|
'default': False,
|
||||||
|
'validator': bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<td>{% trans 'Signup' %}</td>
|
<td>{% trans 'Signup' %}</td>
|
||||||
<td colspan='4'></td>
|
<td colspan='4'></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_MAIL_TWICE" icon="fa-info-circle" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_SSO_AUTO" icon="fa-info-circle" %}
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_SSO_AUTO" icon="fa-info-circle" %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
Reference in New Issue
Block a user