From eb146830ba51757901469e4bb8e442deacc3ec50 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Sun, 26 Dec 2021 17:57:27 +0530 Subject: [PATCH] Implement registration endpoint --- src/matrix/net/HomeServerApi.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/matrix/net/HomeServerApi.ts b/src/matrix/net/HomeServerApi.ts index 4a84adf0..606514ae 100644 --- a/src/matrix/net/HomeServerApi.ts +++ b/src/matrix/net/HomeServerApi.ts @@ -85,7 +85,8 @@ export class HomeServerApi { body: encodedBody, timeout: options?.timeout, uploadProgress: options?.uploadProgress, - format: "json" // response format + format: "json", // response format + cache: options?.cache ?? false }); const hsRequest = new HomeServerRequest(method, url, requestResult, log); @@ -164,8 +165,25 @@ export class HomeServerApi { return this._unauthedRequest("GET", this._url("/login")); } - getRegistrationFlows(): IHomeServerRequest { - return this._unauthedRequest("POST", this._url("/register", CS_V3_PREFIX), undefined, { auth: {} }); + register(username: string, password: string, initialDeviceDisplayName: string, auth?: Record, inhibitLogin?: boolean , options?: IRequestOptions): IHomeServerRequest { + // todo: This is so that we disable cache-buster because it would cause the hs to respond with error + // see https://github.com/matrix-org/synapse/issues/7722 + // need to this about the implications of this later + const _options = options ?? {}; + Object.assign(_options, { cache: true }); + return this._unauthedRequest( + "POST", + this._url("/register", CS_V3_PREFIX), + undefined, + { + auth, + username, + password, + initial_device_displayname: initialDeviceDisplayName, + inhibit_login: inhibitLogin ?? false, + }, + _options + ); } passwordLogin(username: string, password: string, initialDeviceDisplayName: string, options?: IRequestOptions): IHomeServerRequest {