Skip to content

Commit

Permalink
added an email validator
Browse files Browse the repository at this point in the history
  • Loading branch information
CHRISTOPHERKADOGO committed Jul 10, 2024
1 parent 060a447 commit e9358eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 8 additions & 3 deletions app/controllers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'
Expand Down
18 changes: 18 additions & 0 deletions app/helpers/email_validator.py
Original file line number Diff line number Diff line change
@@ -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,

)
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit e9358eb

Please sign in to comment.