diff --git a/bases/rsptx/web2py_server/applications/runestone/models/db.py b/bases/rsptx/web2py_server/applications/runestone/models/db.py index 66e467bb9..e2b82db91 100644 --- a/bases/rsptx/web2py_server/applications/runestone/models/db.py +++ b/bases/rsptx/web2py_server/applications/runestone/models/db.py @@ -386,6 +386,7 @@ def formatter(self, value): db.auth_user.username.requires = ( HAS_NO_DOTS(), IS_NOT_IN_DB(db, db.auth_user.username), + IS_NOT_EMOJI(db.auth_user.username,f"Username cannot contain emojis") ) db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id) db.auth_user.email.requires = ( diff --git a/bases/rsptx/web2py_server/gluon/packages/dal/pydal/validators.py b/bases/rsptx/web2py_server/gluon/packages/dal/pydal/validators.py index 343a98d5b..6d0c9b83a 100644 --- a/bases/rsptx/web2py_server/gluon/packages/dal/pydal/validators.py +++ b/bases/rsptx/web2py_server/gluon/packages/dal/pydal/validators.py @@ -73,6 +73,7 @@ "IS_UPPER", "IS_URL", "IS_JSON", + "IS_NOT_EMOJI", ] @@ -157,6 +158,19 @@ def validator_caller(func, value, record_id=None): raise ValidationError(error) return value +class IS_NOT_EMOJI(Validator): + """ + """ + def __init__(self,expression, error_message="Contains Emojis"): + + self.expression = expression + self.error_message = error_message + def validate(self, value, record_id=None): + emoji_pattern = re.compile(r'[\U0001F600-\U0001F64F\U0001F300-\U0001F5FF\U0001F680-\U0001F6FF\U0001F700-\U0001F77F\U0001F780-\U0001F7FF\U0001F800-\U0001F8FF\U0001F900-\U0001F9FF\U0001FA00-\U0001FA6F\U0001FA70-\U0001FAFF]') + + if emoji_pattern.search(value): + raise ValidationError(self.translator(self.error_message)) + return value class IS_MATCH(Validator): """ @@ -202,7 +216,7 @@ def __init__( extract=False, is_unicode=False, ): - + if strict or not search: if not expression.startswith("^"): expression = "^(%s)" % expression