Validate Custom Email Domains with Django-Registration

☆樱花仙子☆ 提交于 2019-12-24 01:47:11

问题


I saw a version of JQuery EDU validation here but I'd love to use django-registraion to check a full domain @someschool.edu or @alumni.someschool.edu

Any ideas? Thanks for your help.


回答1:


You can create your own form in forms.py, you already have some example for :

  • registration with term of service
  • registration with unique mail
  • registration without freeemail

In your case add :

class RegistrationFormEduMail(RegistrationForm):

    good_domains = ['edu']

    def clean_email(self):

        email_domain = self.cleaned_data['email'].split('.')[-1]
        if email_domain not in self.good_domains:
            raise forms.ValidationError(_("Registration using non edu email addresses is prohibited. Please supply a different email address."))
        return self.cleaned_data['email']

Then go in registration/backends/default/init.py and import your form, change the name of the form returned by get_form_class() method to the name of your form (here: RegistrationFormEduMail)



来源:https://stackoverflow.com/questions/14179629/validate-custom-email-domains-with-django-registration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!