Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_without_diagnosis(self):
result = is_email(self.address)
expected = create_diagnosis(self.diagnosis) < self.threshold
self.assertEqual(
result,
expected,
("%s (%s): Got %s, but expected %s."
% (self.id, self.address, result, expected))
)
def _cfg_emails(value):
"""Parse a list of emails separated by comma, colons, semicolons or spaces.
Args:
value (object): if list or tuple, use verbatim; else split
Returns:
list: validated emails
"""
import pyisemail
try:
if not isinstance(value, (list, tuple)):
value = re.split(r'[,;:\s]+', value)
except Exception:
pkcli.command_error('{}: invalid email list', value)
for v in value:
if not pyisemail.is_email(value):
pkcli.command_error('{}: invalid email', v)
def signup() -> Dict[str, SignupForm]:
"""Route for handling the signup page."""
from run import app
form = SignupForm(request.form)
if form.validate_on_submit():
if is_email(form.email.data):
# Check if user exists
user = User.query.filter_by(email=form.email.data).first()
if user is None:
expires = int(time.time()) + 86400
content_to_hash = "{email}|{expiry}".format(email=form.email.data, expiry=expires)
hmac_hash = generate_hmac_hash(app.config.get('HMAC_KEY', ''), content_to_hash)
# New user
template = app.jinja_env.get_or_select_template('email/registration_email.txt')
message = template.render(url=url_for(
'.complete_signup', email=form.email.data, expires=expires, mac=hmac_hash, _external=True)
)
else:
# Existing user
template = app.jinja_env.get_or_select_template('email/registration_existing.txt')
message = template.render(url=url_for('.reset', _external=True), name=user.name)
if g.mailer.send_simple_message({
def _parse_email(data):
res = data.email.strip().lower()
assert pyisemail.is_email(res), \
'invalid post data: email={}'.format(data.email)
return res
request, csv_file, discussion_id, with_role,
send_password_change=False, message_subject=None,
text_message=None, html_message=None, sender_name=None,
resend_if_not_logged_in=False):
r = reader(csv_file, skipinitialspace=True)
localizer = request.localizer
for i, row in enumerate(r):
if not len(row):
# tolerate empty lines
continue
row = [x.decode('utf-8').strip() for x in row]
if len(row) != 2:
raise RuntimeError(localizer.translate(_(
"The CSV file must have two columns")))
(name, email) = row
if not is_email(email):
if i == 0:
# Header
continue
raise RuntimeError(localizer.translate(_(
"Not an email: <%s> at line %d")) % (email, i))
if len(name) < 5:
raise RuntimeError(localizer.translate(_(
"Name too short: <%s> at line %d")) % (name, i))
(user, created_user, created_localrole) = add_user(
name, email, None, None, True, localrole=with_role,
discussion=discussion_id, change_old_password=False)
status_in_discussion = None
if send_password_change and not (created_user or created_localrole):
status_in_discussion = user.get_status_in_discussion(discussion_id)
if send_password_change and (
created_user or created_localrole or (
and asbool(config.get("accept_secure_connection")):
return HTTPFound(get_global_base_url(True) + request.path_qs)
response = get_login_context(request)
return response
forget(request)
session = AgentProfile.default_db
localizer = request.localizer
name = request.params.get('name', '').strip()
if not name or len(name) < 3:
return dict(get_default_context(request),
error=localizer.translate(_(
"Please use a name of at least 3 characters")))
password = request.params.get('password', '').strip()
password2 = request.params.get('password2', '').strip()
email = request.params.get('email', '').strip()
if not is_email(email):
return dict(get_default_context(request),
error=localizer.translate(_(
"This is not a valid email")))
email = EmailString.normalize_email_case(email)
# Find agent account to avoid duplicates!
if session.query(AbstractAgentAccount).filter_by(
email_ci=email, verified=True).count():
return dict(get_default_context(request),
error=localizer.translate(_(
"We already have a user with this email.")))
if password != password2:
return dict(get_default_context(request),
error=localizer.translate(_(
"The passwords should be identical")))
# TODO: Validate password quality
# No empty strings allowed
break
elif is_valid_ipv4_address(val):
condition = True
break
elif is_valid_ipv6_address(val):
condition = True
break
else:
# Must be a regular URL then. TODO: Check that the location has a DNS record
condition = True
break
assert condition, "Not a valid URL. Must follow the specification of a URI."
elif data_type == "email":
from pyisemail import is_email
assert is_email(value), "Not an email"
elif data_type == "locale":
pass # TODO
elif data_type == "permission":
assert value in ASSEMBL_PERMISSIONS
elif data_type == "role":
if value not in SYSTEM_ROLES:
from .auth import Role
assert self.db.query(Role).filter_by(
name=value).count() == 1, "Unknown role"
elif data_type == "domain":
from pyisemail.validators.dns_validator import DNSValidator
v = DNSValidator()
assert v.is_valid(value), "Not a valid domain"
value = value.lower()
else:
raise RuntimeError("Invalid data_type: " + data_type)
op.execute("""UPDATE post
SET message_id = concat(
substring(message_id, 10, length(message_id)), '_assembl@%s')
WHERE message_id LIKE 'urn:uuid:%%'""" % (
config.get('public_hostname'),))
# Do stuff with the app's models here.
from assembl import models as m
db = m.get_session_maker()()
accepted = (
pyisemail.diagnosis.valid_diagnosis.ValidDiagnosis(),
pyisemail.diagnosis.rfc5322_diagnosis.RFC5322Diagnosis('LOCAL_TOOLONG'))
with transaction.manager:
for id, email in db.execute("SELECT id, message_id FROM post"):
if pyisemail.is_email(email, diagnose=True) in accepted:
continue
c = m.Content.get(id)
if isinstance(c, m.ImportedPost):
c.message_id = c.source.generate_message_id(c.source_post_id)
elif isinstance(c, m.AssemblPost):
c.message_id = c.generate_message_id()
else:
print "ERROR: Pure post", id