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
3320aaab
Commit
3320aaab
authored
5 years ago
by
Half-Shot
Browse files
Options
Downloads
Patches
Plain Diff
Add "require_consent" parameter for registration
parent
1b09cf86
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/handlers/register.py
+12
-2
12 additions, 2 deletions
synapse/handlers/register.py
synapse/replication/http/register.py
+2
-0
2 additions, 0 deletions
synapse/replication/http/register.py
synapse/rest/client/v2_alpha/register.py
+4
-1
4 additions, 1 deletion
synapse/rest/client/v2_alpha/register.py
with
18 additions
and
3 deletions
synapse/handlers/register.py
+
12
−
2
View file @
3320aaab
...
@@ -150,6 +150,7 @@ class RegistrationHandler(BaseHandler):
...
@@ -150,6 +150,7 @@ class RegistrationHandler(BaseHandler):
threepid
=
None
,
threepid
=
None
,
user_type
=
None
,
user_type
=
None
,
default_display_name
=
None
,
default_display_name
=
None
,
require_consent
=
True
,
address
=
None
,
address
=
None
,
bind_emails
=
[],
bind_emails
=
[],
):
):
...
@@ -167,6 +168,7 @@ class RegistrationHandler(BaseHandler):
...
@@ -167,6 +168,7 @@ class RegistrationHandler(BaseHandler):
will be set to this. Defaults to
'
localpart
'
.
will be set to this. Defaults to
'
localpart
'
.
address (str|None): the IP address used to perform the registration.
address (str|None): the IP address used to perform the registration.
bind_emails (List[str]): list of emails to bind to this account.
bind_emails (List[str]): list of emails to bind to this account.
require_consent (bool): Should the user be required to give consent.
Returns:
Returns:
Deferred[str]: user_id
Deferred[str]: user_id
Raises:
Raises:
...
@@ -211,6 +213,7 @@ class RegistrationHandler(BaseHandler):
...
@@ -211,6 +213,7 @@ class RegistrationHandler(BaseHandler):
admin
=
admin
,
admin
=
admin
,
user_type
=
user_type
,
user_type
=
user_type
,
address
=
address
,
address
=
address
,
require_consent
=
require_consent
,
)
)
if
self
.
hs
.
config
.
user_directory_search_all_users
:
if
self
.
hs
.
config
.
user_directory_search_all_users
:
...
@@ -244,7 +247,7 @@ class RegistrationHandler(BaseHandler):
...
@@ -244,7 +247,7 @@ class RegistrationHandler(BaseHandler):
user_id
=
None
user_id
=
None
attempts
+=
1
attempts
+=
1
if
not
self
.
hs
.
config
.
user_consent_at_registration
:
if
not
self
.
hs
.
config
.
user_consent_at_registration
and
require_consent
:
yield
self
.
_auto_join_rooms
(
user_id
)
yield
self
.
_auto_join_rooms
(
user_id
)
else
:
else
:
logger
.
info
(
logger
.
info
(
...
@@ -525,6 +528,7 @@ class RegistrationHandler(BaseHandler):
...
@@ -525,6 +528,7 @@ class RegistrationHandler(BaseHandler):
ratelimit
=
False
,
ratelimit
=
False
,
)
)
@defer.inlineCallbacks
def
register_with_store
(
def
register_with_store
(
self
,
self
,
user_id
,
user_id
,
...
@@ -536,6 +540,7 @@ class RegistrationHandler(BaseHandler):
...
@@ -536,6 +540,7 @@ class RegistrationHandler(BaseHandler):
admin
=
False
,
admin
=
False
,
user_type
=
None
,
user_type
=
None
,
address
=
None
,
address
=
None
,
require_consent
=
True
,
):
):
"""
Register user in the datastore.
"""
Register user in the datastore.
...
@@ -553,7 +558,7 @@ class RegistrationHandler(BaseHandler):
...
@@ -553,7 +558,7 @@ class RegistrationHandler(BaseHandler):
user_type (str|None): type of user. One of the values from
user_type (str|None): type of user. One of the values from
api.constants.UserTypes, or None for a normal user.
api.constants.UserTypes, or None for a normal user.
address (str|None): the IP address used to perform the registration.
address (str|None): the IP address used to perform the registration.
require_consent (bool): Should the user be required to give consent.
Returns:
Returns:
Deferred
Deferred
"""
"""
...
@@ -584,8 +589,12 @@ class RegistrationHandler(BaseHandler):
...
@@ -584,8 +589,12 @@ class RegistrationHandler(BaseHandler):
admin
=
admin
,
admin
=
admin
,
user_type
=
user_type
,
user_type
=
user_type
,
address
=
address
,
address
=
address
,
require_consent
=
require_consent
,
)
)
else
:
else
:
if
require_consent
is
False
:
yield
self
.
store
.
user_set_consent_version
(
user_id
,
"
no-consent-required
"
)
return
self
.
store
.
register_user
(
return
self
.
store
.
register_user
(
user_id
=
user_id
,
user_id
=
user_id
,
password_hash
=
password_hash
,
password_hash
=
password_hash
,
...
@@ -597,6 +606,7 @@ class RegistrationHandler(BaseHandler):
...
@@ -597,6 +606,7 @@ class RegistrationHandler(BaseHandler):
user_type
=
user_type
,
user_type
=
user_type
,
)
)
@defer.inlineCallbacks
@defer.inlineCallbacks
def
register_device
(
self
,
user_id
,
device_id
,
initial_display_name
,
is_guest
=
False
):
def
register_device
(
self
,
user_id
,
device_id
,
initial_display_name
,
is_guest
=
False
):
"""
Register a device for a user and generate an access token.
"""
Register a device for a user and generate an access token.
...
...
This diff is collapsed.
Click to expand it.
synapse/replication/http/register.py
+
2
−
0
View file @
3320aaab
...
@@ -72,6 +72,7 @@ class ReplicationRegisterServlet(ReplicationEndpoint):
...
@@ -72,6 +72,7 @@ class ReplicationRegisterServlet(ReplicationEndpoint):
"
admin
"
:
admin
,
"
admin
"
:
admin
,
"
user_type
"
:
user_type
,
"
user_type
"
:
user_type
,
"
address
"
:
address
,
"
address
"
:
address
,
"
require_consent
"
:
require_consent
,
}
}
@defer.inlineCallbacks
@defer.inlineCallbacks
...
@@ -88,6 +89,7 @@ class ReplicationRegisterServlet(ReplicationEndpoint):
...
@@ -88,6 +89,7 @@ class ReplicationRegisterServlet(ReplicationEndpoint):
admin
=
content
[
"
admin
"
],
admin
=
content
[
"
admin
"
],
user_type
=
content
[
"
user_type
"
],
user_type
=
content
[
"
user_type
"
],
address
=
content
[
"
address
"
],
address
=
content
[
"
address
"
],
require_consent
=
content
[
"
require_consent
"
],
)
)
return
(
200
,
{})
return
(
200
,
{})
...
...
This diff is collapsed.
Click to expand it.
synapse/rest/client/v2_alpha/register.py
+
4
−
1
View file @
3320aaab
...
@@ -525,6 +525,9 @@ class RegisterRestServlet(RestServlet):
...
@@ -525,6 +525,9 @@ class RegisterRestServlet(RestServlet):
# downcased one in `username` for the mac calculation
# downcased one in `username` for the mac calculation
user
=
body
[
"
username
"
].
encode
(
"
utf-8
"
)
user
=
body
[
"
username
"
].
encode
(
"
utf-8
"
)
# do not require consent for this user (for example, bots)
require_consent
=
body
.
get
(
"
require_consent
"
,
True
)
# str() because otherwise hmac complains that 'unicode' does not
# str() because otherwise hmac complains that 'unicode' does not
# have the buffer interface
# have the buffer interface
got_mac
=
str
(
body
[
"
mac
"
])
got_mac
=
str
(
body
[
"
mac
"
])
...
@@ -542,7 +545,7 @@ class RegisterRestServlet(RestServlet):
...
@@ -542,7 +545,7 @@ class RegisterRestServlet(RestServlet):
raise
SynapseError
(
403
,
"
HMAC incorrect
"
)
raise
SynapseError
(
403
,
"
HMAC incorrect
"
)
user_id
=
yield
self
.
registration_handler
.
register_user
(
user_id
=
yield
self
.
registration_handler
.
register_user
(
localpart
=
username
,
password
=
password
localpart
=
username
,
password
=
password
,
require_consent
=
require_consent
,
)
)
result
=
yield
self
.
_create_registration_details
(
user_id
,
body
)
result
=
yield
self
.
_create_registration_details
(
user_id
,
body
)
...
...
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