|
|
@ -19,7 +19,7 @@ from twisted.internet import defer |
|
|
|
|
|
|
|
|
|
|
|
from synapse.api.auth import has_access_token |
|
|
|
from synapse.api.auth import has_access_token |
|
|
|
from synapse.api.constants import LoginType |
|
|
|
from synapse.api.constants import LoginType |
|
|
|
from synapse.api.errors import Codes, LoginError, SynapseError |
|
|
|
from synapse.api.errors import Codes, SynapseError |
|
|
|
from synapse.http.servlet import ( |
|
|
|
from synapse.http.servlet import ( |
|
|
|
RestServlet, assert_params_in_request, |
|
|
|
RestServlet, assert_params_in_request, |
|
|
|
parse_json_object_from_request, |
|
|
|
parse_json_object_from_request, |
|
|
@ -103,26 +103,32 @@ class PasswordRestServlet(RestServlet): |
|
|
|
@interactive_auth_handler |
|
|
|
@interactive_auth_handler |
|
|
|
@defer.inlineCallbacks |
|
|
|
@defer.inlineCallbacks |
|
|
|
def on_POST(self, request): |
|
|
|
def on_POST(self, request): |
|
|
|
yield run_on_reactor() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body = parse_json_object_from_request(request) |
|
|
|
body = parse_json_object_from_request(request) |
|
|
|
|
|
|
|
|
|
|
|
result, params, _ = yield self.auth_handler.check_auth([ |
|
|
|
# there are two possibilities here. Either the user does not have an |
|
|
|
[LoginType.PASSWORD], |
|
|
|
# access token, and needs to do a password reset; or they have one and |
|
|
|
[LoginType.EMAIL_IDENTITY], |
|
|
|
# need to validate their identity. |
|
|
|
[LoginType.MSISDN], |
|
|
|
# |
|
|
|
], body, self.hs.get_ip_from_request(request)) |
|
|
|
# In the first case, we offer a couple of means of identifying |
|
|
|
|
|
|
|
# themselves (email and msisdn, though it's unclear if msisdn actually |
|
|
|
user_id = None |
|
|
|
# works). |
|
|
|
requester = None |
|
|
|
# |
|
|
|
|
|
|
|
# In the second case, we require a password to confirm their identity. |
|
|
|
|
|
|
|
|
|
|
|
if LoginType.PASSWORD in result: |
|
|
|
if has_access_token(request): |
|
|
|
# if using password, they should also be logged in |
|
|
|
|
|
|
|
requester = yield self.auth.get_user_by_req(request) |
|
|
|
requester = yield self.auth.get_user_by_req(request) |
|
|
|
|
|
|
|
params = yield self.auth_handler.validate_user_via_ui_auth( |
|
|
|
|
|
|
|
requester, body, self.hs.get_ip_from_request(request), |
|
|
|
|
|
|
|
) |
|
|
|
user_id = requester.user.to_string() |
|
|
|
user_id = requester.user.to_string() |
|
|
|
if user_id != result[LoginType.PASSWORD]: |
|
|
|
else: |
|
|
|
raise LoginError(400, "", Codes.UNKNOWN) |
|
|
|
requester = None |
|
|
|
elif LoginType.EMAIL_IDENTITY in result: |
|
|
|
result, params, _ = yield self.auth_handler.check_auth( |
|
|
|
|
|
|
|
[[LoginType.EMAIL_IDENTITY], [LoginType.MSISDN]], |
|
|
|
|
|
|
|
body, self.hs.get_ip_from_request(request), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if LoginType.EMAIL_IDENTITY in result: |
|
|
|
threepid = result[LoginType.EMAIL_IDENTITY] |
|
|
|
threepid = result[LoginType.EMAIL_IDENTITY] |
|
|
|
if 'medium' not in threepid or 'address' not in threepid: |
|
|
|
if 'medium' not in threepid or 'address' not in threepid: |
|
|
|
raise SynapseError(500, "Malformed threepid") |
|
|
|
raise SynapseError(500, "Malformed threepid") |
|
|
@ -171,40 +177,21 @@ class DeactivateAccountRestServlet(RestServlet): |
|
|
|
def on_POST(self, request): |
|
|
|
def on_POST(self, request): |
|
|
|
body = parse_json_object_from_request(request) |
|
|
|
body = parse_json_object_from_request(request) |
|
|
|
|
|
|
|
|
|
|
|
# if the caller provides an access token, it ought to be valid. |
|
|
|
requester = yield self.auth.get_user_by_req(request) |
|
|
|
requester = None |
|
|
|
|
|
|
|
if has_access_token(request): |
|
|
|
|
|
|
|
requester = yield self.auth.get_user_by_req( |
|
|
|
|
|
|
|
request, |
|
|
|
|
|
|
|
) # type: synapse.types.Requester |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# allow ASes to dectivate their own users |
|
|
|
# allow ASes to dectivate their own users |
|
|
|
if requester and requester.app_service: |
|
|
|
if requester.app_service: |
|
|
|
yield self._deactivate_account_handler.deactivate_account( |
|
|
|
yield self._deactivate_account_handler.deactivate_account( |
|
|
|
requester.user.to_string() |
|
|
|
requester.user.to_string() |
|
|
|
) |
|
|
|
) |
|
|
|
defer.returnValue((200, {})) |
|
|
|
defer.returnValue((200, {})) |
|
|
|
|
|
|
|
|
|
|
|
result, params, _ = yield self.auth_handler.check_auth([ |
|
|
|
yield self.auth_handler.validate_user_via_ui_auth( |
|
|
|
[LoginType.PASSWORD], |
|
|
|
requester, body, self.hs.get_ip_from_request(request), |
|
|
|
], body, self.hs.get_ip_from_request(request)) |
|
|
|
) |
|
|
|
|
|
|
|
yield self._deactivate_account_handler.deactivate_account( |
|
|
|
if LoginType.PASSWORD in result: |
|
|
|
requester.user.to_string(), |
|
|
|
user_id = result[LoginType.PASSWORD] |
|
|
|
|
|
|
|
# if using password, they should also be logged in |
|
|
|
|
|
|
|
if requester is None: |
|
|
|
|
|
|
|
raise SynapseError( |
|
|
|
|
|
|
|
400, |
|
|
|
|
|
|
|
"Deactivate account requires an access_token", |
|
|
|
|
|
|
|
errcode=Codes.MISSING_TOKEN |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
if requester.user.to_string() != user_id: |
|
|
|
|
|
|
|
raise LoginError(400, "", Codes.UNKNOWN) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
logger.error("Auth succeeded but no known type!", result.keys()) |
|
|
|
|
|
|
|
raise SynapseError(500, "", Codes.UNKNOWN) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yield self._deactivate_account_handler.deactivate_account(user_id) |
|
|
|
|
|
|
|
defer.returnValue((200, {})) |
|
|
|
defer.returnValue((200, {})) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|