async/await check_password
Was introduced in Synapse v1.15.0. This may be related to: * https://github.com/ma1uta/matrix-synapse-rest-password-provider/issues/1
This commit is contained in:
parent
5d66d6972b
commit
8e4718ae72
@ -43,8 +43,7 @@ class RestAuthProvider(object):
|
|||||||
logger.info('Endpoint: %s', self.endpoint)
|
logger.info('Endpoint: %s', self.endpoint)
|
||||||
logger.info('Enforce lowercase username during registration: %s', self.regLower)
|
logger.info('Enforce lowercase username during registration: %s', self.regLower)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def check_password(self, user_id, password):
|
||||||
def check_password(self, user_id, password):
|
|
||||||
logger.info("Got password check for " + user_id)
|
logger.info("Got password check for " + user_id)
|
||||||
data = {'user': {'id': user_id, 'password': password}}
|
data = {'user': {'id': user_id, 'password': password}}
|
||||||
r = requests.post(self.endpoint + '/_matrix-internal/identity/v1/check_credentials', json=data)
|
r = requests.post(self.endpoint + '/_matrix-internal/identity/v1/check_credentials', json=data)
|
||||||
@ -64,14 +63,14 @@ class RestAuthProvider(object):
|
|||||||
logger.info("User %s authenticated", user_id)
|
logger.info("User %s authenticated", user_id)
|
||||||
|
|
||||||
registration = False
|
registration = False
|
||||||
if not (yield self.account_handler.check_user_exists(user_id)):
|
if not (await self.account_handler.check_user_exists(user_id)):
|
||||||
logger.info("User %s does not exist yet, creating...", user_id)
|
logger.info("User %s does not exist yet, creating...", user_id)
|
||||||
|
|
||||||
if localpart != localpart.lower() and self.regLower:
|
if localpart != localpart.lower() and self.regLower:
|
||||||
logger.info('User %s was cannot be created due to username lowercase policy', localpart)
|
logger.info('User %s was cannot be created due to username lowercase policy', localpart)
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
|
|
||||||
user_id, access_token = (yield self.account_handler.register(localpart=localpart))
|
user_id, access_token = (await self.account_handler.register(localpart=localpart))
|
||||||
registration = True
|
registration = True
|
||||||
logger.info("Registration based on REST data was successful for %s", user_id)
|
logger.info("Registration based on REST data was successful for %s", user_id)
|
||||||
else:
|
else:
|
||||||
@ -83,14 +82,14 @@ class RestAuthProvider(object):
|
|||||||
|
|
||||||
# fixme: temporary fix
|
# fixme: temporary fix
|
||||||
try:
|
try:
|
||||||
store = yield self.account_handler._hs.get_profile_handler().store # for synapse >= 1.9.0
|
store = await self.account_handler._hs.get_profile_handler().store # for synapse >= 1.9.0
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
store = yield self.account_handler.hs.get_profile_handler().store # for synapse < 1.9.0
|
store = await self.account_handler.hs.get_profile_handler().store # for synapse < 1.9.0
|
||||||
|
|
||||||
if "display_name" in profile and ((registration and self.config.setNameOnRegister) or (self.config.setNameOnLogin)):
|
if "display_name" in profile and ((registration and self.config.setNameOnRegister) or (self.config.setNameOnLogin)):
|
||||||
display_name = profile["display_name"]
|
display_name = profile["display_name"]
|
||||||
logger.info("Setting display name to '%s' based on profile data", display_name)
|
logger.info("Setting display name to '%s' based on profile data", display_name)
|
||||||
yield store.set_profile_displayname(localpart, display_name)
|
await store.set_profile_displayname(localpart, display_name)
|
||||||
else:
|
else:
|
||||||
logger.info("Display name was not set because it was not given or policy restricted it")
|
logger.info("Display name was not set because it was not given or policy restricted it")
|
||||||
|
|
||||||
@ -106,9 +105,9 @@ class RestAuthProvider(object):
|
|||||||
logger.info("Looking for 3PID %s:%s in user profile", medium, address)
|
logger.info("Looking for 3PID %s:%s in user profile", medium, address)
|
||||||
|
|
||||||
validated_at = time_msec()
|
validated_at = time_msec()
|
||||||
if not (yield store.get_user_id_by_threepid(medium, address)):
|
if not (await store.get_user_id_by_threepid(medium, address)):
|
||||||
logger.info("3PID is not present, adding")
|
logger.info("3PID is not present, adding")
|
||||||
yield store.user_add_threepid(
|
await store.user_add_threepid(
|
||||||
user_id,
|
user_id,
|
||||||
medium,
|
medium,
|
||||||
address,
|
address,
|
||||||
@ -119,12 +118,12 @@ class RestAuthProvider(object):
|
|||||||
logger.info("3PID is present, skipping")
|
logger.info("3PID is present, skipping")
|
||||||
|
|
||||||
if (self.config.replaceThreepid):
|
if (self.config.replaceThreepid):
|
||||||
for threepid in (yield store.user_get_threepids(user_id)):
|
for threepid in (await store.user_get_threepids(user_id)):
|
||||||
medium = threepid["medium"].lower()
|
medium = threepid["medium"].lower()
|
||||||
address = threepid["address"].lower()
|
address = threepid["address"].lower()
|
||||||
if {"medium": medium, "address": address} not in external_3pids:
|
if {"medium": medium, "address": address} not in external_3pids:
|
||||||
logger.info("3PID is not present in external datastore, deleting")
|
logger.info("3PID is not present in external datastore, deleting")
|
||||||
yield store.user_delete_threepid(
|
await store.user_delete_threepid(
|
||||||
user_id,
|
user_id,
|
||||||
medium,
|
medium,
|
||||||
address
|
address
|
||||||
|
Loading…
Reference in New Issue
Block a user