Skip to content

Commit

Permalink
enh: do not allow signing up from gmail addresses (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 9, 2021
1 parent d586c19 commit aa955bc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.15.13
- enh: do not allow signing up from gmail addresses (#14)
0.15.12
- fix: add redis connection
0.15.11
Expand Down
40 changes: 40 additions & 0 deletions ckanext/dcor_schemas/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from email.utils import parseaddr

import ckan.authz as authz
from ckan.common import asbool, config
from ckan import logic
Expand Down Expand Up @@ -297,3 +299,41 @@ def resource_update_check(context, new_dict):
'msg': f'Editing not allowed: {", ".join(invalid)}'}

return {'success': True}


def user_create(context, data_dict=None):
"""Measure against automated registration from gmail addresses
This function is the first escalation of many more possible
ways to restrict user registration via bots, e.g.
- https://github.com/DCOR-dev/ckanext-dcor_schemas/issues/1
- https://github.com/DCOR-dev/ckanext-dcor_schemas/issues/4
- https://github.com/DCOR-dev/ckanext-dcor_schemas/issues/14
"""
# original auth function
ao = logic.auth.create.user_create(context, data_dict)
if not ao["success"]:
return ao

if data_dict is None:
data_dict = {}

email = data_dict.get("email", "").strip()
if not email:
return {'success': False,
'msg': 'No email address provided!'}
else:
email = parseaddr(email)[1]
if (not email
or "@" not in email
or "." not in email.split("@")[1]):
# not a valid email address
return {'success': False,
'msg': 'Invalid email address provided!'}
domain = email.split("@")
if domain in ["gmail.com"]:
return {'success': False,
'msg': f'Email domain not allowed due to spam: {domain}!'}

return {'success': True}
1 change: 1 addition & 0 deletions ckanext/dcor_schemas/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def get_auth_functions(self):
'resource_create': dcor_auth.resource_create,
'resource_delete': dcor_auth.deny,
'resource_update': dcor_auth.resource_update,
'user_create': dcor_auth.user_create,
}

# IClick
Expand Down

0 comments on commit aa955bc

Please sign in to comment.