本文整理汇总了Python中django.core.validators.validate_email方法的典型用法代码示例。如果您正苦于以下问题:Python validators.validate_email方法的具体用法?Python validators.validate_email怎么用?Python validators.validate_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.validators
的用法示例。
在下文中一共展示了validators.validate_email方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: same_realm_zephyr_user
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def same_realm_zephyr_user(user_profile: UserProfile, email: str) -> bool:
#
# Are the sender and recipient both addresses in the same Zephyr
# mirroring realm? We have to handle this specially, inferring
# the domain from the e-mail address, because the recipient may
# not existing in Zulip and we may need to make a stub Zephyr
# mirroring user on the fly.
try:
validators.validate_email(email)
except ValidationError:
return False
domain = email_to_domain(email)
# Assumes allow_subdomains=False for all RealmDomain's corresponding to
# these realms.
return user_profile.realm.is_zephyr_mirror_realm and \
RealmDomain.objects.filter(realm=user_profile.realm, domain=domain).exists()
示例2: check_email_address_validity
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def check_email_address_validity(email_address):
"""Given a string, determine if it is a valid email address using Django's validate_email() function."""
try:
validate_email(email_address)
valid_email = True
except ValidationError:
valid_email = False
return valid_email
示例3: same_realm_irc_user
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def same_realm_irc_user(user_profile: UserProfile, email: str) -> bool:
# Check whether the target email address is an IRC user in the
# same realm as user_profile, i.e. if the domain were example.com,
# the IRC user would need to be username@irc.example.com
try:
validators.validate_email(email)
except ValidationError:
return False
domain = email_to_domain(email).replace("irc.", "")
# Assumes allow_subdomains=False for all RealmDomain's corresponding to
# these realms.
return RealmDomain.objects.filter(realm=user_profile.realm, domain=domain).exists()
示例4: same_realm_jabber_user
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def same_realm_jabber_user(user_profile: UserProfile, email: str) -> bool:
try:
validators.validate_email(email)
except ValidationError:
return False
# If your Jabber users have a different email domain than the
# Zulip users, this is where you would do any translation.
domain = email_to_domain(email)
# Assumes allow_subdomains=False for all RealmDomain's corresponding to
# these realms.
return RealmDomain.objects.filter(realm=user_profile.realm, domain=domain).exists()
示例5: test_all_errors_get_reported
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def test_all_errors_get_reported(self):
class UserForm(forms.Form):
full_name = forms.CharField(
max_length=50,
validators=[
validators.validate_integer,
validators.validate_email,
]
)
string = forms.CharField(
max_length=50,
validators=[
validators.RegexValidator(
regex='^[a-zA-Z]*$',
message="Letters only.",
)
]
)
ignore_case_string = forms.CharField(
max_length=50,
validators=[
validators.RegexValidator(
regex='^[a-z]*$',
message="Letters only.",
flags=re.IGNORECASE,
)
]
)
form = UserForm({
'full_name': 'not int nor mail',
'string': '2 is not correct',
'ignore_case_string': "IgnORE Case strIng",
})
with self.assertRaises(ValidationError) as e:
form.fields['full_name'].clean('not int nor mail')
self.assertEqual(2, len(e.exception.messages))
self.assertFalse(form.is_valid())
self.assertEqual(form.errors['string'], ["Letters only."])
self.assertEqual(form.errors['string'], ["Letters only."])
示例6: test_field_validators_can_be_any_iterable
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def test_field_validators_can_be_any_iterable(self):
class UserForm(forms.Form):
full_name = forms.CharField(
max_length=50,
validators=(
validators.validate_integer,
validators.validate_email,
)
)
form = UserForm({'full_name': 'not int nor mail'})
self.assertFalse(form.is_valid())
self.assertEqual(form.errors['full_name'], ['Enter a valid integer.', 'Enter a valid email address.'])
示例7: test_field_validates_valid_data
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def test_field_validates_valid_data(self):
value = ["test@example.com", "me@example.com"]
field = ValidatorMultipleChoiceField(validator=validate_email)
self.assertEqual(value, field.clean(value))
示例8: test_field_uses_validator
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def test_field_uses_validator(self):
value = ["test@example.com", "invalid-email"]
field = ValidatorMultipleChoiceField(validator=validate_email)
error = self.assertRaises(ValidationError, field.clean, value)
self.assertEqual(["Enter a valid email address."], error.messages)
示例9: __call__
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def __call__(self, value):
value = force_text(value)
addresses = getaddresses([value])
[validate_email(email) for name, email in addresses if email]
示例10: find_account
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def find_account(request: HttpRequest) -> HttpResponse:
from zerver.context_processors import common_context
url = reverse('zerver.views.registration.find_account')
emails: List[str] = []
if request.method == 'POST':
form = FindMyTeamForm(request.POST)
if form.is_valid():
emails = form.cleaned_data['emails']
for user in UserProfile.objects.filter(
delivery_email__in=emails, is_active=True, is_bot=False,
realm__deactivated=False):
context = common_context(user)
context.update({
'email': user.delivery_email,
})
send_email('zerver/emails/find_team', to_user_ids=[user.id], context=context,
from_address=FromAddress.SUPPORT)
# Note: Show all the emails in the result otherwise this
# feature can be used to ascertain which email addresses
# are associated with Zulip.
data = urllib.parse.urlencode({'emails': ','.join(emails)})
return redirect(add_query_to_redirect_url(url, data))
else:
form = FindMyTeamForm()
result = request.GET.get('emails')
# The below validation is perhaps unnecessary, in that we
# shouldn't get able to get here with an invalid email unless
# the user hand-edits the URLs.
if result:
for email in result.split(','):
try:
validators.validate_email(email)
emails.append(email)
except ValidationError:
pass
return render(request,
'zerver/find_account.html',
context={'form': form, 'current_url': lambda: url,
'emails': emails})
示例11: handle
# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import validate_email [as 别名]
def handle(self, *args: Any, **options: Any) -> None:
if not options["tos"]:
raise CommandError("""You must confirm that this user has accepted the
Terms of Service by passing --this-user-has-accepted-the-tos.""")
realm = self.get_realm(options)
assert realm is not None # Should be ensured by parser
try:
email = options['email']
full_name = options['full_name']
try:
validators.validate_email(email)
except ValidationError:
raise CommandError("Invalid email address.")
except KeyError:
if 'email' in options or 'full_name' in options:
raise CommandError("""Either specify an email and full name as two
parameters, or specify no parameters for interactive user creation.""")
else:
while True:
email = input("Email: ")
try:
validators.validate_email(email)
break
except ValidationError:
print("Invalid email address.", file=sys.stderr)
full_name = input("Full name: ")
try:
if options['password_file']:
with open(options['password_file']) as f:
pw = f.read()
elif options['password']:
pw = options['password']
else:
user_initial_password = initial_password(email)
if user_initial_password is None:
raise CommandError("Password is unusable.")
pw = user_initial_password
do_create_user(email, pw, realm, full_name, email_to_username(email))
except IntegrityError:
raise CommandError("User already exists.")