summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2019-04-03 10:57:20 +0100
committerGitHub <noreply@github.com>2019-04-03 10:57:20 +0100
commitd94873d525ec1db0a0f84ce75c6b3155521f5839 (patch)
tree34390aceb6f15f06665243d916ffbd4469dc08ed
parentMerge pull request #4910 from matrix-org/erikj/third_party_invite_create_spam (diff)
parentSample config (diff)
downloadsynapse-d94873d525ec1db0a0f84ce75c6b3155521f5839.tar.xz
Merge pull request #4997 from matrix-org/erikj/dinsic_email_display_name
Add config option to use email as display name for new users
-rw-r--r--docs/sample_config.yaml5
-rw-r--r--synapse/config/registration.py8
-rw-r--r--synapse/rest/client/v2_alpha/register.py31
3 files changed, 30 insertions, 14 deletions
diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml
index 73d02a63fc..b48a63e5f8 100644
--- a/docs/sample_config.yaml
+++ b/docs/sample_config.yaml
@@ -661,6 +661,11 @@ uploads_path: "DATADIR/uploads"
 #
 #register_mxid_from_3pid: email
 
+# Uncomment to set the display name of new users to their email address,
+# rather than using the default heuristic.
+#
+#register_just_use_email_for_display_name: true
+
 # Mandate that users are only allowed to associate certain formats of
 # 3PIDs with accounts on this server.
 #
diff --git a/synapse/config/registration.py b/synapse/config/registration.py
index 503fe6f922..e5c0ccb2af 100644
--- a/synapse/config/registration.py
+++ b/synapse/config/registration.py
@@ -42,6 +42,9 @@ class RegistrationConfig(Config):
 
         self.registration_shared_secret = config.get("registration_shared_secret")
         self.register_mxid_from_3pid = config.get("register_mxid_from_3pid")
+        self.register_just_use_email_for_display_name = config.get(
+            "register_just_use_email_for_display_name", False,
+        )
 
         self.bcrypt_rounds = config.get("bcrypt_rounds", 12)
         self.trusted_third_party_id_servers = config.get(
@@ -111,6 +114,11 @@ class RegistrationConfig(Config):
         #
         #register_mxid_from_3pid: email
 
+        # Uncomment to set the display name of new users to their email address,
+        # rather than using the default heuristic.
+        #
+        #register_just_use_email_for_display_name: true
+
         # Mandate that users are only allowed to associate certain formats of
         # 3PIDs with accounts on this server.
         #
diff --git a/synapse/rest/client/v2_alpha/register.py b/synapse/rest/client/v2_alpha/register.py
index 741c12e43a..1740947e27 100644
--- a/synapse/rest/client/v2_alpha/register.py
+++ b/synapse/rest/client/v2_alpha/register.py
@@ -454,21 +454,24 @@ class RegisterRestServlet(RestServlet):
                                 # something else went wrong.
                                 break
 
-                    # XXX: a nasty heuristic to turn an email address into
-                    # a displayname, as part of register_mxid_from_3pid
-                    parts = address.replace('.', ' ').split('@')
-                    org_parts = parts[1].split(' ')
-
-                    if org_parts[-2] == "matrix" and org_parts[-1] == "org":
-                        org = "Tchap Admin"
-                    elif org_parts[-2] == "gouv" and org_parts[-1] == "fr":
-                        org = org_parts[-3] if len(org_parts) > 2 else org_parts[-2]
+                    if self.config.register_just_use_email_for_display_name:
+                        desired_display_name = address
                     else:
-                        org = org_parts[-2]
-
-                    desired_display_name = (
-                        capwords(parts[0]) + " [" + capwords(org) + "]"
-                    )
+                        # XXX: a nasty heuristic to turn an email address into
+                        # a displayname, as part of register_mxid_from_3pid
+                        parts = address.replace('.', ' ').split('@')
+                        org_parts = parts[1].split(' ')
+
+                        if org_parts[-2] == "matrix" and org_parts[-1] == "org":
+                            org = "Tchap Admin"
+                        elif org_parts[-2] == "gouv" and org_parts[-1] == "fr":
+                            org = org_parts[-3] if len(org_parts) > 2 else org_parts[-2]
+                        else:
+                            org = org_parts[-2]
+
+                        desired_display_name = (
+                            capwords(parts[0]) + " [" + capwords(org) + "]"
+                        )
                 elif (
                     self.hs.config.register_mxid_from_3pid == 'msisdn' and
                     LoginType.MSISDN in auth_result