Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2213 from matrix-org/luke/username-availability-qp
Browse files Browse the repository at this point in the history
Modify register/available to be GET with query param
  • Loading branch information
lukebarnard1 authored May 11, 2017
2 parents a3648f8 + ccad2ed commit c1935f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 7 additions & 0 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def check_username(self, localpart, guest_access_token=None,
Codes.INVALID_USERNAME
)

if not localpart:
raise SynapseError(
400,
"User ID cannot be empty",
Codes.INVALID_USERNAME
)

if localpart[0] == '_':
raise SynapseError(
400,
Expand Down
9 changes: 4 additions & 5 deletions synapse/rest/client/v2_alpha/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from synapse.api.constants import LoginType
from synapse.api.errors import SynapseError, Codes, UnrecognizedRequestError
from synapse.http.servlet import (
RestServlet, parse_json_object_from_request, assert_params_in_request
RestServlet, parse_json_object_from_request, assert_params_in_request, parse_string
)
from synapse.util.msisdn import phone_number_to_msisdn

Expand Down Expand Up @@ -142,15 +142,14 @@ def __init__(self, hs):
)

@defer.inlineCallbacks
def on_POST(self, request):
def on_GET(self, request):
ip = self.hs.get_ip_from_request(request)
with self.ratelimiter.ratelimit(ip) as wait_deferred:
yield wait_deferred

body = parse_json_object_from_request(request)
assert_params_in_request(body, ['username'])
username = parse_string(request, "username", required=True)

yield self.registration_handler.check_username(body['username'])
yield self.registration_handler.check_username(username)

defer.returnValue((200, {"available": True}))

Expand Down

0 comments on commit c1935f0

Please sign in to comment.