From 5eafdf5c0b2f2781833279d294cdec967e4d8a39 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 10 May 2017 11:51:32 +0100 Subject: [PATCH 1/2] Implement API for username availability Requires synapse with https://github.com/matrix-org/synapse/pull/2183 --- src/base-apis.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/base-apis.js b/src/base-apis.js index 6752ad1c5e2..2a320104365 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -120,6 +120,20 @@ MatrixBaseApis.prototype.makeTxnId = function() { // Registration/Login operations // ============================= +/** + * Check whether a username is available prior to registration. An error response + * indicates an invalid/unavailable username. + * @param {string} username The username to check the availability of. + * @return {module:client.Promise} Resolves: to `true`. + */ +MatrixBaseApis.prototype.isUsernameAvailable = function(username) { + return this._http.authedRequest( + undefined, "POST", '/register/available', null, { username: username }, + ).then((response) => { + return response.available; + }); +}; + /** * @param {string} username * @param {string} password From d920e0f97c54e60406dcdbf505b0c9972282aff6 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 10 May 2017 17:35:54 +0100 Subject: [PATCH 2/2] Update to reflect https://github.com/matrix-org/synapse/pull/2213 --- src/base-apis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base-apis.js b/src/base-apis.js index 2a320104365..671ddcb01fe 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -128,7 +128,7 @@ MatrixBaseApis.prototype.makeTxnId = function() { */ MatrixBaseApis.prototype.isUsernameAvailable = function(username) { return this._http.authedRequest( - undefined, "POST", '/register/available', null, { username: username }, + undefined, "GET", '/register/available', { username: username }, ).then((response) => { return response.available; });