Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
e059c5e6
Commit
e059c5e6
authored
5 years ago
by
Andrew Morgan
Browse files
Options
Downloads
Patches
Plain Diff
Move get_threepid_validation_session into RegistrationWorkerStore
parent
1ab1479a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/registration.py
+54
-54
54 additions, 54 deletions
synapse/storage/registration.py
with
54 additions
and
54 deletions
synapse/storage/registration.py
+
54
−
54
View file @
e059c5e6
...
...
@@ -614,6 +614,60 @@ class RegistrationWorkerStore(SQLBaseStore):
# Convert the integer into a boolean.
return
res
==
1
def
get_threepid_validation_session
(
self
,
medium
,
client_secret
,
address
=
None
,
sid
=
None
,
validated
=
True
):
"""
Gets a session_id and last_send_attempt (if available) for a
client_secret/medium/(address|session_id) combo
Args:
medium (str|None): The medium of the 3PID
address (str|None): The address of the 3PID
sid (str|None): The ID of the validation session
client_secret (str|None): A unique string provided by the client to
help identify this validation attempt
validated (bool|None): Whether sessions should be filtered by
whether they have been validated already or not. None to
perform no filtering
Returns:
deferred {str, int}|None: A dict containing the
latest session_id and send_attempt count for this 3PID.
Otherwise None if there hasn
'
t been a previous attempt
"""
keyvalues
=
{
"
medium
"
:
medium
,
"
client_secret
"
:
client_secret
}
if
address
:
keyvalues
[
"
address
"
]
=
address
if
sid
:
keyvalues
[
"
session_id
"
]
=
sid
assert
address
or
sid
def
get_threepid_validation_session_txn
(
txn
):
sql
=
"""
SELECT address, session_id, medium, client_secret,
last_send_attempt, validated_at
FROM threepid_validation_session WHERE %s
"""
%
(
"
AND
"
.
join
(
"
%s = ?
"
%
k
for
k
in
iterkeys
(
keyvalues
)),
)
if
validated
is
not
None
:
sql
+=
"
AND validated_at IS
"
+
(
"
NOT NULL
"
if
validated
else
"
NULL
"
)
sql
+=
"
LIMIT 1
"
txn
.
execute
(
sql
,
list
(
keyvalues
.
values
()))
rows
=
self
.
cursor_to_dict
(
txn
)
if
not
rows
:
return
None
return
rows
[
0
]
return
self
.
runInteraction
(
"
get_threepid_validation_session
"
,
get_threepid_validation_session_txn
)
class
RegistrationStore
(
RegistrationWorkerStore
,
background_updates
.
BackgroundUpdateStore
...
...
@@ -1082,60 +1136,6 @@ class RegistrationStore(
return
1
def
get_threepid_validation_session
(
self
,
medium
,
client_secret
,
address
=
None
,
sid
=
None
,
validated
=
True
):
"""
Gets a session_id and last_send_attempt (if available) for a
client_secret/medium/(address|session_id) combo
Args:
medium (str|None): The medium of the 3PID
address (str|None): The address of the 3PID
sid (str|None): The ID of the validation session
client_secret (str|None): A unique string provided by the client to
help identify this validation attempt
validated (bool|None): Whether sessions should be filtered by
whether they have been validated already or not. None to
perform no filtering
Returns:
deferred {str, int}|None: A dict containing the
latest session_id and send_attempt count for this 3PID.
Otherwise None if there hasn
'
t been a previous attempt
"""
keyvalues
=
{
"
medium
"
:
medium
,
"
client_secret
"
:
client_secret
}
if
address
:
keyvalues
[
"
address
"
]
=
address
if
sid
:
keyvalues
[
"
session_id
"
]
=
sid
assert
address
or
sid
def
get_threepid_validation_session_txn
(
txn
):
sql
=
"""
SELECT address, session_id, medium, client_secret,
last_send_attempt, validated_at
FROM threepid_validation_session WHERE %s
"""
%
(
"
AND
"
.
join
(
"
%s = ?
"
%
k
for
k
in
iterkeys
(
keyvalues
)),
)
if
validated
is
not
None
:
sql
+=
"
AND validated_at IS
"
+
(
"
NOT NULL
"
if
validated
else
"
NULL
"
)
sql
+=
"
LIMIT 1
"
txn
.
execute
(
sql
,
list
(
keyvalues
.
values
()))
rows
=
self
.
cursor_to_dict
(
txn
)
if
not
rows
:
return
None
return
rows
[
0
]
return
self
.
runInteraction
(
"
get_threepid_validation_session
"
,
get_threepid_validation_session_txn
)
def
validate_threepid_session
(
self
,
session_id
,
client_secret
,
token
,
current_ts
):
"""
Attempt to validate a threepid session using a token
...
...
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