|
|
|
@ -24,13 +24,11 @@ from synapse.api.errors import ( |
|
|
|
|
AuthError, |
|
|
|
|
Codes, |
|
|
|
|
ConsentNotGivenError, |
|
|
|
|
InvalidCaptchaError, |
|
|
|
|
LimitExceededError, |
|
|
|
|
RegistrationError, |
|
|
|
|
SynapseError, |
|
|
|
|
) |
|
|
|
|
from synapse.config.server import is_threepid_reserved |
|
|
|
|
from synapse.http.client import CaptchaServerHttpClient |
|
|
|
|
from synapse.http.servlet import assert_params_in_dict |
|
|
|
|
from synapse.replication.http.login import RegisterDeviceReplicationServlet |
|
|
|
|
from synapse.replication.http.register import ( |
|
|
|
@ -39,7 +37,6 @@ from synapse.replication.http.register import ( |
|
|
|
|
) |
|
|
|
|
from synapse.types import RoomAlias, RoomID, UserID, create_requester |
|
|
|
|
from synapse.util.async_helpers import Linearizer |
|
|
|
|
from synapse.util.threepids import check_3pid_allowed |
|
|
|
|
|
|
|
|
|
from ._base import BaseHandler |
|
|
|
|
|
|
|
|
@ -59,7 +56,6 @@ class RegistrationHandler(BaseHandler): |
|
|
|
|
self._auth_handler = hs.get_auth_handler() |
|
|
|
|
self.profile_handler = hs.get_profile_handler() |
|
|
|
|
self.user_directory_handler = hs.get_user_directory_handler() |
|
|
|
|
self.captcha_client = CaptchaServerHttpClient(hs) |
|
|
|
|
self.identity_handler = self.hs.get_handlers().identity_handler |
|
|
|
|
self.ratelimiter = hs.get_registration_ratelimiter() |
|
|
|
|
|
|
|
|
@ -362,70 +358,6 @@ class RegistrationHandler(BaseHandler): |
|
|
|
|
) |
|
|
|
|
return user_id |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def check_recaptcha(self, ip, private_key, challenge, response): |
|
|
|
|
""" |
|
|
|
|
Checks a recaptcha is correct. |
|
|
|
|
|
|
|
|
|
Used only by c/s api v1 |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
captcha_response = yield self._validate_captcha( |
|
|
|
|
ip, private_key, challenge, response |
|
|
|
|
) |
|
|
|
|
if not captcha_response["valid"]: |
|
|
|
|
logger.info( |
|
|
|
|
"Invalid captcha entered from %s. Error: %s", |
|
|
|
|
ip, |
|
|
|
|
captcha_response["error_url"], |
|
|
|
|
) |
|
|
|
|
raise InvalidCaptchaError(error_url=captcha_response["error_url"]) |
|
|
|
|
else: |
|
|
|
|
logger.info("Valid captcha entered from %s", ip) |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def register_email(self, threepidCreds): |
|
|
|
|
""" |
|
|
|
|
Registers emails with an identity server. |
|
|
|
|
|
|
|
|
|
Used only by c/s api v1 |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
for c in threepidCreds: |
|
|
|
|
logger.info( |
|
|
|
|
"validating threepidcred sid %s on id server %s", |
|
|
|
|
c["sid"], |
|
|
|
|
c["idServer"], |
|
|
|
|
) |
|
|
|
|
try: |
|
|
|
|
threepid = yield self.identity_handler.threepid_from_creds(c) |
|
|
|
|
except Exception: |
|
|
|
|
logger.exception("Couldn't validate 3pid") |
|
|
|
|
raise RegistrationError(400, "Couldn't validate 3pid") |
|
|
|
|
|
|
|
|
|
if not threepid: |
|
|
|
|
raise RegistrationError(400, "Couldn't validate 3pid") |
|
|
|
|
logger.info( |
|
|
|
|
"got threepid with medium '%s' and address '%s'", |
|
|
|
|
threepid["medium"], |
|
|
|
|
threepid["address"], |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if not check_3pid_allowed(self.hs, threepid["medium"], threepid["address"]): |
|
|
|
|
raise RegistrationError(403, "Third party identifier is not allowed") |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def bind_emails(self, user_id, threepidCreds): |
|
|
|
|
"""Links emails with a user ID and informs an identity server. |
|
|
|
|
|
|
|
|
|
Used only by c/s api v1 |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
# Now we have a matrix ID, bind it to the threepids we were given |
|
|
|
|
for c in threepidCreds: |
|
|
|
|
# XXX: This should be a deferred list, shouldn't it? |
|
|
|
|
yield self.identity_handler.bind_threepid(c, user_id) |
|
|
|
|
|
|
|
|
|
def check_user_id_not_appservice_exclusive(self, user_id, allowed_appservice=None): |
|
|
|
|
# don't allow people to register the server notices mxid |
|
|
|
|
if self._server_notices_mxid is not None: |
|
|
|
@ -463,42 +395,6 @@ class RegistrationHandler(BaseHandler): |
|
|
|
|
self._next_generated_user_id += 1 |
|
|
|
|
return str(id) |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def _validate_captcha(self, ip_addr, private_key, challenge, response): |
|
|
|
|
"""Validates the captcha provided. |
|
|
|
|
|
|
|
|
|
Used only by c/s api v1 |
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
|
dict: Containing 'valid'(bool) and 'error_url'(str) if invalid. |
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
response = yield self._submit_captcha(ip_addr, private_key, challenge, response) |
|
|
|
|
# parse Google's response. Lovely format.. |
|
|
|
|
lines = response.split("\n") |
|
|
|
|
json = { |
|
|
|
|
"valid": lines[0] == "true", |
|
|
|
|
"error_url": "http://www.recaptcha.net/recaptcha/api/challenge?" |
|
|
|
|
+ "error=%s" % lines[1], |
|
|
|
|
} |
|
|
|
|
return json |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def _submit_captcha(self, ip_addr, private_key, challenge, response): |
|
|
|
|
""" |
|
|
|
|
Used only by c/s api v1 |
|
|
|
|
""" |
|
|
|
|
data = yield self.captcha_client.post_urlencoded_get_raw( |
|
|
|
|
"http://www.recaptcha.net:80/recaptcha/api/verify", |
|
|
|
|
args={ |
|
|
|
|
"privatekey": private_key, |
|
|
|
|
"remoteip": ip_addr, |
|
|
|
|
"challenge": challenge, |
|
|
|
|
"response": response, |
|
|
|
|
}, |
|
|
|
|
) |
|
|
|
|
return data |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def _join_user_to_room(self, requester, room_identifier): |
|
|
|
|
room_id = None |
|
|
|
|