Skip to content

Commit 3524b47

Browse files
authored
Merge pull request ma1uta#8 from devplayer0/master
Fix for Synapse v1.19.0+
2 parents c782c84 + 893473b commit 3524b47

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

rest_auth_provider.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#
2121

2222
import logging
23-
from twisted.internet import defer
2423
import requests
2524
import json
2625
import time
@@ -43,8 +42,7 @@ def __init__(self, config, account_handler):
4342
logger.info('Endpoint: %s', self.endpoint)
4443
logger.info('Enforce lowercase username during registration: %s', self.regLower)
4544

46-
@defer.inlineCallbacks
47-
def check_password(self, user_id, password):
45+
async def check_password(self, user_id, password):
4846
logger.info("Got password check for " + user_id)
4947
data = {'user': {'id': user_id, 'password': password}}
5048
r = requests.post(self.endpoint + '/_matrix-internal/identity/v1/check_credentials', json=data)
@@ -58,20 +56,20 @@ def check_password(self, user_id, password):
5856
auth = r["auth"]
5957
if not auth["success"]:
6058
logger.info("User not authenticated")
61-
defer.returnValue(False)
59+
return False
6260

6361
localpart = user_id.split(":", 1)[0][1:]
6462
logger.info("User %s authenticated", user_id)
6563

6664
registration = False
67-
if not (yield self.account_handler.check_user_exists(user_id)):
65+
if not (await self.account_handler.check_user_exists(user_id)):
6866
logger.info("User %s does not exist yet, creating...", user_id)
6967

7068
if localpart != localpart.lower() and self.regLower:
7169
logger.info('User %s was cannot be created due to username lowercase policy', localpart)
72-
defer.returnValue(False)
70+
return False
7371

74-
user_id, access_token = (yield self.account_handler.register(localpart=localpart))
72+
user_id, access_token = (await self.account_handler.register(localpart=localpart))
7573
registration = True
7674
logger.info("Registration based on REST data was successful for %s", user_id)
7775
else:
@@ -81,16 +79,12 @@ def check_password(self, user_id, password):
8179
logger.info("Handling profile data")
8280
profile = auth["profile"]
8381

84-
# fixme: temporary fix
85-
try:
86-
store = yield self.account_handler._hs.get_profile_handler().store # for synapse >= 1.9.0
87-
except AttributeError:
88-
store = yield self.account_handler.hs.get_profile_handler().store # for synapse < 1.9.0
82+
store = self.account_handler._hs.get_profile_handler().store
8983

9084
if "display_name" in profile and ((registration and self.config.setNameOnRegister) or (self.config.setNameOnLogin)):
9185
display_name = profile["display_name"]
9286
logger.info("Setting display name to '%s' based on profile data", display_name)
93-
yield store.set_profile_displayname(localpart, display_name)
87+
await store.set_profile_displayname(localpart, display_name)
9488
else:
9589
logger.info("Display name was not set because it was not given or policy restricted it")
9690

@@ -106,9 +100,9 @@ def check_password(self, user_id, password):
106100
logger.info("Looking for 3PID %s:%s in user profile", medium, address)
107101

108102
validated_at = time_msec()
109-
if not (yield store.get_user_id_by_threepid(medium, address)):
103+
if not (await store.get_user_id_by_threepid(medium, address)):
110104
logger.info("3PID is not present, adding")
111-
yield store.user_add_threepid(
105+
await store.user_add_threepid(
112106
user_id,
113107
medium,
114108
address,
@@ -119,12 +113,12 @@ def check_password(self, user_id, password):
119113
logger.info("3PID is present, skipping")
120114

121115
if (self.config.replaceThreepid):
122-
for threepid in (yield store.user_get_threepids(user_id)):
116+
for threepid in (await store.user_get_threepids(user_id)):
123117
medium = threepid["medium"].lower()
124118
address = threepid["address"].lower()
125119
if {"medium": medium, "address": address} not in external_3pids:
126120
logger.info("3PID is not present in external datastore, deleting")
127-
yield store.user_delete_threepid(
121+
await store.user_delete_threepid(
128122
user_id,
129123
medium,
130124
address
@@ -135,7 +129,7 @@ def check_password(self, user_id, password):
135129
else:
136130
logger.info("No profile data")
137131

138-
defer.returnValue(True)
132+
return True
139133

140134
@staticmethod
141135
def parse_config(config):

0 commit comments

Comments
 (0)