diff --git a/setup.py b/setup.py index 9c9aa907..922f9f88 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -73,6 +73,7 @@ requires = [ # (still, probably a better idea is to refactor so we can use 0.9) 'webhelpers2_grid==0.1', # 0.1 + 'colander', # 1.7.0 'ColanderAlchemy', # 0.3.3 'cornice', # 3.4.2 'deform', # 2.0.4 diff --git a/tailbone/util.py b/tailbone/util.py index f9317018..862104e9 100644 --- a/tailbone/util.py +++ b/tailbone/util.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -35,6 +35,7 @@ import humanize from rattail.time import timezone, make_utc from rattail.files import resource_path +import colander from pyramid.renderers import get_renderer from webhelpers2.html import HTML, tags @@ -175,3 +176,25 @@ def get_effective_theme(rattail_config, theme=None, session=None): raise ValueError("theme not available: {}".format(theme)) return theme + + +def validate_email_address(address): + """ + Perform basic validation on the given email address. This leverages the + ``colander`` package for actual validation logic. + """ + node = colander.SchemaNode(typ=colander.String) + validator = colander.Email() + validator(node, address) + return address + + +def email_address_is_valid(address): + """ + Returns boolean indicating whether the address can validate. + """ + try: + validate_email_address(address) + except colander.Invalid: + return False + return True