24
24
AuthError ,
25
25
Codes ,
26
26
ConsentNotGivenError ,
27
- InvalidCaptchaError ,
28
27
LimitExceededError ,
29
28
RegistrationError ,
30
29
SynapseError ,
31
30
)
32
31
from synapse .config .server import is_threepid_reserved
33
- from synapse .http .client import CaptchaServerHttpClient
34
32
from synapse .http .servlet import assert_params_in_dict
35
33
from synapse .replication .http .login import RegisterDeviceReplicationServlet
36
34
from synapse .replication .http .register import (
39
37
)
40
38
from synapse .types import RoomAlias , RoomID , UserID , create_requester
41
39
from synapse .util .async_helpers import Linearizer
42
- from synapse .util .threepids import check_3pid_allowed
43
40
44
41
from ._base import BaseHandler
45
42
@@ -59,7 +56,6 @@ def __init__(self, hs):
59
56
self ._auth_handler = hs .get_auth_handler ()
60
57
self .profile_handler = hs .get_profile_handler ()
61
58
self .user_directory_handler = hs .get_user_directory_handler ()
62
- self .captcha_client = CaptchaServerHttpClient (hs )
63
59
self .identity_handler = self .hs .get_handlers ().identity_handler
64
60
self .ratelimiter = hs .get_registration_ratelimiter ()
65
61
@@ -362,70 +358,6 @@ def appservice_register(self, user_localpart, as_token):
362
358
)
363
359
return user_id
364
360
365
- @defer .inlineCallbacks
366
- def check_recaptcha (self , ip , private_key , challenge , response ):
367
- """
368
- Checks a recaptcha is correct.
369
-
370
- Used only by c/s api v1
371
- """
372
-
373
- captcha_response = yield self ._validate_captcha (
374
- ip , private_key , challenge , response
375
- )
376
- if not captcha_response ["valid" ]:
377
- logger .info (
378
- "Invalid captcha entered from %s. Error: %s" ,
379
- ip ,
380
- captcha_response ["error_url" ],
381
- )
382
- raise InvalidCaptchaError (error_url = captcha_response ["error_url" ])
383
- else :
384
- logger .info ("Valid captcha entered from %s" , ip )
385
-
386
- @defer .inlineCallbacks
387
- def register_email (self , threepidCreds ):
388
- """
389
- Registers emails with an identity server.
390
-
391
- Used only by c/s api v1
392
- """
393
-
394
- for c in threepidCreds :
395
- logger .info (
396
- "validating threepidcred sid %s on id server %s" ,
397
- c ["sid" ],
398
- c ["idServer" ],
399
- )
400
- try :
401
- threepid = yield self .identity_handler .threepid_from_creds (c )
402
- except Exception :
403
- logger .exception ("Couldn't validate 3pid" )
404
- raise RegistrationError (400 , "Couldn't validate 3pid" )
405
-
406
- if not threepid :
407
- raise RegistrationError (400 , "Couldn't validate 3pid" )
408
- logger .info (
409
- "got threepid with medium '%s' and address '%s'" ,
410
- threepid ["medium" ],
411
- threepid ["address" ],
412
- )
413
-
414
- if not check_3pid_allowed (self .hs , threepid ["medium" ], threepid ["address" ]):
415
- raise RegistrationError (403 , "Third party identifier is not allowed" )
416
-
417
- @defer .inlineCallbacks
418
- def bind_emails (self , user_id , threepidCreds ):
419
- """Links emails with a user ID and informs an identity server.
420
-
421
- Used only by c/s api v1
422
- """
423
-
424
- # Now we have a matrix ID, bind it to the threepids we were given
425
- for c in threepidCreds :
426
- # XXX: This should be a deferred list, shouldn't it?
427
- yield self .identity_handler .bind_threepid (c , user_id )
428
-
429
361
def check_user_id_not_appservice_exclusive (self , user_id , allowed_appservice = None ):
430
362
# don't allow people to register the server notices mxid
431
363
if self ._server_notices_mxid is not None :
@@ -463,42 +395,6 @@ def _generate_user_id(self, reseed=False):
463
395
self ._next_generated_user_id += 1
464
396
return str (id )
465
397
466
- @defer .inlineCallbacks
467
- def _validate_captcha (self , ip_addr , private_key , challenge , response ):
468
- """Validates the captcha provided.
469
-
470
- Used only by c/s api v1
471
-
472
- Returns:
473
- dict: Containing 'valid'(bool) and 'error_url'(str) if invalid.
474
-
475
- """
476
- response = yield self ._submit_captcha (ip_addr , private_key , challenge , response )
477
- # parse Google's response. Lovely format..
478
- lines = response .split ("\n " )
479
- json = {
480
- "valid" : lines [0 ] == "true" ,
481
- "error_url" : "http://www.recaptcha.net/recaptcha/api/challenge?"
482
- + "error=%s" % lines [1 ],
483
- }
484
- return json
485
-
486
- @defer .inlineCallbacks
487
- def _submit_captcha (self , ip_addr , private_key , challenge , response ):
488
- """
489
- Used only by c/s api v1
490
- """
491
- data = yield self .captcha_client .post_urlencoded_get_raw (
492
- "http://www.recaptcha.net:80/recaptcha/api/verify" ,
493
- args = {
494
- "privatekey" : private_key ,
495
- "remoteip" : ip_addr ,
496
- "challenge" : challenge ,
497
- "response" : response ,
498
- },
499
- )
500
- return data
501
-
502
398
@defer .inlineCallbacks
503
399
def _join_user_to_room (self , requester , room_identifier ):
504
400
room_id = None
0 commit comments