Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
3ea6f01b
Commit
3ea6f01b
authored
10 years ago
by
Kegan Dougal
Browse files
Options
Downloads
Patches
Plain Diff
80 chars please
parent
37e53513
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/handlers/register.py
+19
-9
19 additions, 9 deletions
synapse/handlers/register.py
synapse/rest/register.py
+4
-2
4 additions, 2 deletions
synapse/rest/register.py
with
23 additions
and
11 deletions
synapse/handlers/register.py
+
19
−
9
View file @
3ea6f01b
...
...
@@ -17,7 +17,9 @@
from
twisted.internet
import
defer
from
synapse.types
import
UserID
from
synapse.api.errors
import
SynapseError
,
RegistrationError
,
InvalidCaptchaError
from
synapse.api.errors
import
(
SynapseError
,
RegistrationError
,
InvalidCaptchaError
)
from
._base
import
BaseHandler
import
synapse.util.stringutils
as
stringutils
from
synapse.http.client
import
PlainHttpClient
...
...
@@ -38,7 +40,8 @@ class RegistrationHandler(BaseHandler):
self
.
distributor
.
declare
(
"
registered_user
"
)
@defer.inlineCallbacks
def
register
(
self
,
localpart
=
None
,
password
=
None
,
threepidCreds
=
None
,
captcha_info
=
{}):
def
register
(
self
,
localpart
=
None
,
password
=
None
,
threepidCreds
=
None
,
captcha_info
=
{}):
"""
Registers a new client on the server.
Args:
...
...
@@ -59,7 +62,8 @@ class RegistrationHandler(BaseHandler):
captcha_info
[
"
response
"
]
)
if
not
captcha_response
[
"
valid
"
]:
logger
.
info
(
"
Invalid captcha entered from %s
"
,
captcha_info
[
"
ip
"
])
logger
.
info
(
"
Invalid captcha entered from %s
"
,
captcha_info
[
"
ip
"
])
raise
InvalidCaptchaError
(
error_url
=
captcha_response
[
"
error_url
"
]
)
...
...
@@ -68,7 +72,8 @@ class RegistrationHandler(BaseHandler):
if
threepidCreds
:
for
c
in
threepidCreds
:
logger
.
info
(
"
validating theeepidcred sid %s on id server %s
"
,
c
[
'
sid
'
],
c
[
'
idServer
'
])
logger
.
info
(
"
validating theeepidcred sid %s on id server %s
"
,
c
[
'
sid
'
],
c
[
'
idServer
'
])
try
:
threepid
=
yield
self
.
_threepid_from_creds
(
c
)
except
:
...
...
@@ -77,7 +82,8 @@ class RegistrationHandler(BaseHandler):
if
not
threepid
:
raise
RegistrationError
(
400
,
"
Couldn
'
t validate 3pid
"
)
logger
.
info
(
"
got threepid medium %s address %s
"
,
threepid
[
'
medium
'
],
threepid
[
'
address
'
])
logger
.
info
(
"
got threepid medium %s address %s
"
,
threepid
[
'
medium
'
],
threepid
[
'
address
'
])
password_hash
=
None
if
password
:
...
...
@@ -145,7 +151,8 @@ class RegistrationHandler(BaseHandler):
# XXX: make this configurable!
trustedIdServers
=
[
'
matrix.org:8090
'
]
if
not
creds
[
'
idServer
'
]
in
trustedIdServers
:
logger
.
warn
(
'
%s is not a trusted ID server: rejecting 3pid credentials
'
,
creds
[
'
idServer
'
])
logger
.
warn
(
'
%s is not a trusted ID server: rejecting 3pid
'
+
'
credentials
'
,
creds
[
'
idServer
'
])
defer
.
returnValue
(
None
)
data
=
yield
httpCli
.
get_json
(
creds
[
'
idServer
'
],
...
...
@@ -163,7 +170,8 @@ class RegistrationHandler(BaseHandler):
data
=
yield
httpCli
.
post_urlencoded_get_json
(
creds
[
'
idServer
'
],
"
/_matrix/identity/api/v1/3pid/bind
"
,
{
'
sid
'
:
creds
[
'
sid
'
],
'
clientSecret
'
:
creds
[
'
clientSecret
'
],
'
mxid
'
:
mxid
}
{
'
sid
'
:
creds
[
'
sid
'
],
'
clientSecret
'
:
creds
[
'
clientSecret
'
],
'
mxid
'
:
mxid
}
)
defer
.
returnValue
(
data
)
...
...
@@ -175,12 +183,14 @@ class RegistrationHandler(BaseHandler):
dict: Containing
'
valid
'
(bool) and
'
error_url
'
(str) if invalid.
"""
response
=
yield
self
.
_submit_captcha
(
ip_addr
,
private_key
,
challenge
,
response
)
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.google.com/recaptcha/api/challenge?error=%s
"
%
lines
[
1
]
"
error_url
"
:
"
http://www.google.com/recaptcha/api/challenge?
"
+
"
error=%s
"
%
lines
[
1
]
}
defer
.
returnValue
(
json
)
...
...
This diff is collapsed.
Click to expand it.
synapse/rest/register.py
+
4
−
2
View file @
3ea6f01b
...
...
@@ -58,11 +58,13 @@ class RegisterRestServlet(RestServlet):
try
:
captcha_type
=
register_json
[
"
captcha
"
][
"
type
"
]
if
captcha_type
!=
"
m.login.recaptcha
"
:
raise
SynapseError
(
400
,
"
Sorry, only m.login.recaptcha requests are supported.
"
)
raise
SynapseError
(
400
,
"
Sorry, only m.login.recaptcha
"
+
"
requests are supported.
"
)
challenge
=
register_json
[
"
captcha
"
][
"
challenge
"
]
user_response
=
register_json
[
"
captcha
"
][
"
response
"
]
except
KeyError
:
raise
SynapseError
(
400
,
"
Captcha response is required
"
,
errcode
=
Codes
.
CAPTCHA_NEEDED
)
raise
SynapseError
(
400
,
"
Captcha response is required
"
,
errcode
=
Codes
.
CAPTCHA_NEEDED
)
# TODO determine the source IP : May be an X-Forwarding-For header depending on config
ip_addr
=
request
.
getClientIP
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment