diff --git a/app/controllers/users.py b/app/controllers/users.py index 9c07dc60..d4b339f8 100644 --- a/app/controllers/users.py +++ b/app/controllers/users.py @@ -31,8 +31,7 @@ from bson.json_util import dumps from app.models.app import App from app.helpers.crane_app_logger import logger - - +from app.helpers.email_validator import is_valid_email class UsersView(Resource): def post(self): @@ -44,8 +43,14 @@ def post(self): user_data = request.get_json() validated_user_data, errors = user_schema.load(user_data) - + email = validated_user_data.get('email', None) + print(email) + if not is_valid_email(email): + print(email) + return dict(status='fail', message=f'Invalid email address'), 400 + + client_base_url = os.getenv( 'CLIENT_BASE_URL', f'https://{request.host}/users' diff --git a/app/helpers/email_validator.py b/app/helpers/email_validator.py new file mode 100644 index 00000000..6e78410e --- /dev/null +++ b/app/helpers/email_validator.py @@ -0,0 +1,18 @@ +from validate_email import validate_email + +def is_valid_email(email: str) -> bool: + return validate_email( + email_address=email, + check_format=True, + check_blacklist=True, + check_dns=True, + dns_timeout=10, + check_smtp=True, + smtp_timeout=10, + smtp_helo_host='my.host.name', + smtp_from_address='my@from.addr.ess', + smtp_skip_tls=False, + smtp_tls_context=None, + smtp_debug=False, + + ) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c3d3453d..b5dd3cc9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,7 +35,6 @@ Flask-RESTful==0.3.9 Flask-SQLAlchemy==2.4.0 google-auth==1.6.3 gunicorn==20.1.0 -idna==2.8 importlib-metadata==4.8.3 iniconfig==1.1.1 ipaddress==1.0.22 @@ -78,7 +77,6 @@ pyxdg==0.25 PyYAML==6.0 rave-python==1.2.16 redis==4.3.6 -requests==2.27.1 requests-oauthlib==1.2.0 rsa==4.0 SecretStorage==2.3.1 @@ -95,3 +93,6 @@ wcwidth==0.2.5 websocket-client==0.56.0 Werkzeug==2.0.3 zipp==3.6.0 +py3-validate-email==1.0.5.post2 +requests>=2.27.1 +idna>=2.5