Refactor get_or_register_3pid_guest
This commit is contained in:
parent
d65ceb4b48
commit
8b3573a8b2
|
@ -446,16 +446,34 @@ class RegistrationHandler(BaseHandler):
|
||||||
return self.hs.get_auth_handler()
|
return self.hs.get_auth_handler()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def guest_access_token_for(self, medium, address, inviter_user_id):
|
def get_or_register_3pid_guest(self, medium, address, inviter_user_id):
|
||||||
|
"""Get a guest access token for a 3PID, creating a guest account if
|
||||||
|
one doesn't already exist.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
medium (str)
|
||||||
|
address (str)
|
||||||
|
inviter_user_id (str): The user ID who is trying to invite the
|
||||||
|
3PID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Deferred[(str, str)]: A 2-tuple of `(user_id, access_token)` of the
|
||||||
|
3PID guest account.
|
||||||
|
"""
|
||||||
access_token = yield self.store.get_3pid_guest_access_token(medium, address)
|
access_token = yield self.store.get_3pid_guest_access_token(medium, address)
|
||||||
if access_token:
|
if access_token:
|
||||||
defer.returnValue(access_token)
|
user_info = yield self.auth.get_user_by_access_token(
|
||||||
|
access_token
|
||||||
|
)
|
||||||
|
|
||||||
_, access_token = yield self.register(
|
defer.returnValue((user_info["user"].to_string(), access_token))
|
||||||
|
|
||||||
|
user_id, access_token = yield self.register(
|
||||||
generate_token=True,
|
generate_token=True,
|
||||||
make_guest=True
|
make_guest=True
|
||||||
)
|
)
|
||||||
access_token = yield self.store.save_or_get_3pid_guest_access_token(
|
access_token = yield self.store.save_or_get_3pid_guest_access_token(
|
||||||
medium, address, access_token, inviter_user_id
|
medium, address, access_token, inviter_user_id
|
||||||
)
|
)
|
||||||
defer.returnValue(access_token)
|
|
||||||
|
defer.returnValue((user_id, access_token))
|
||||||
|
|
|
@ -735,20 +735,16 @@ class RoomMemberHandler(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.config.invite_3pid_guest:
|
if self.config.invite_3pid_guest:
|
||||||
registration_handler = self.registration_handler
|
rh = self.registration_handler
|
||||||
guest_access_token = yield registration_handler.guest_access_token_for(
|
guest_user_id, guest_access_token = yield rh.get_or_register_3pid_guest(
|
||||||
medium=medium,
|
medium=medium,
|
||||||
address=address,
|
address=address,
|
||||||
inviter_user_id=inviter_user_id,
|
inviter_user_id=inviter_user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
guest_user_info = yield self.auth.get_user_by_access_token(
|
|
||||||
guest_access_token
|
|
||||||
)
|
|
||||||
|
|
||||||
invite_config.update({
|
invite_config.update({
|
||||||
"guest_access_token": guest_access_token,
|
"guest_access_token": guest_access_token,
|
||||||
"guest_user_id": guest_user_info["user"].to_string(),
|
"guest_user_id": guest_user_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
data = yield self.simple_http_client.post_urlencoded_get_json(
|
data = yield self.simple_http_client.post_urlencoded_get_json(
|
||||||
|
|
Loading…
Reference in New Issue