Add argument specifying whether 3pid check is happening during registration
This commit is contained in:
@@ -117,7 +117,7 @@ class EmailRegisterRequestTokenRestServlet(RestServlet):
|
||||
send_attempt = body["send_attempt"]
|
||||
next_link = body.get("next_link") # Optional param
|
||||
|
||||
if not await check_3pid_allowed(self.hs, "email", email):
|
||||
if not await check_3pid_allowed(self.hs, "email", email, during_registration=True):
|
||||
raise SynapseError(
|
||||
403,
|
||||
"You currently can't create an account with this email address",
|
||||
@@ -192,7 +192,7 @@ class MsisdnRegisterRequestTokenRestServlet(RestServlet):
|
||||
|
||||
msisdn = phone_number_to_msisdn(country, phone_number)
|
||||
|
||||
if not await check_3pid_allowed(self.hs, "msisdn", msisdn):
|
||||
if not await check_3pid_allowed(self.hs, "msisdn", msisdn, during_registration=True):
|
||||
raise SynapseError(
|
||||
403,
|
||||
"Phone numbers are not authorized to register on this server",
|
||||
@@ -535,7 +535,9 @@ class RegisterRestServlet(RestServlet):
|
||||
medium = auth_result[login_type]["medium"]
|
||||
address = auth_result[login_type]["address"]
|
||||
|
||||
if not await check_3pid_allowed(self.hs, medium, address):
|
||||
if not await check_3pid_allowed(
|
||||
self.hs, medium, address, during_registration=True
|
||||
):
|
||||
raise SynapseError(
|
||||
403,
|
||||
"Third party identifiers (email/phone numbers)"
|
||||
|
||||
@@ -19,7 +19,7 @@ import re
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def check_3pid_allowed(hs, medium, address):
|
||||
async def check_3pid_allowed(hs, medium, address, during_registration: bool = False):
|
||||
"""Checks whether a given format of 3PID is allowed to be used on this HS
|
||||
|
||||
Args:
|
||||
@@ -27,6 +27,8 @@ async def check_3pid_allowed(hs, medium, address):
|
||||
medium (str): 3pid medium - e.g. email, msisdn
|
||||
address (str): address within that medium (e.g. "wotan@matrix.org")
|
||||
msisdns need to first have been canonicalised
|
||||
during_registration: Whether this request has been made while registering a new
|
||||
user.
|
||||
Returns:
|
||||
bool: whether the 3PID medium/address is allowed to be added to this HS
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user