Skip to content
Snippets Groups Projects
Commit d87cae00 authored by Midhun Suresh's avatar Midhun Suresh
Browse files

Do not send username to /register endpoint

Let the homeserver choose a username for us.
This would mean:
- our random string generator does not need to take the grammar for
  mxid into account.
- we will never have a scenario in which a username is reused by
  chance.
parent f611ce8c
No related branches found
No related tags found
No related merge requests found
declare module "hydrogen-view-sdk";
...@@ -9,7 +9,6 @@ export class AccountSetupViewModel extends ViewModel { ...@@ -9,7 +9,6 @@ export class AccountSetupViewModel extends ViewModel {
private _client: Client; private _client: Client;
private _state: ObservableValue<string>; private _state: ObservableValue<string>;
private _termsStage?: any; private _termsStage?: any;
private _username: string;
private _password: string; private _password: string;
constructor(options) { constructor(options) {
...@@ -21,9 +20,8 @@ export class AccountSetupViewModel extends ViewModel { ...@@ -21,9 +20,8 @@ export class AccountSetupViewModel extends ViewModel {
} }
private async _startRegistration(): Promise<void> { private async _startRegistration(): Promise<void> {
this._username = generateRandomString(7);
this._password = generateRandomString(10); this._password = generateRandomString(10);
let stage = await this._client.startRegistration(this._homeserver, this._username, this._password, "Chatterbox"); let stage = await this._client.startRegistration(this._homeserver, null, this._password, "Chatterbox");
if (stage.type === "m.login.terms") { if (stage.type === "m.login.terms") {
this._termsStage = stage; this._termsStage = stage;
this.emitChange("termsStage"); this.emitChange("termsStage");
...@@ -32,10 +30,11 @@ export class AccountSetupViewModel extends ViewModel { ...@@ -32,10 +30,11 @@ export class AccountSetupViewModel extends ViewModel {
async completeRegistration() { async completeRegistration() {
let stage = this._termsStage; let stage = this._termsStage;
while (stage !== true) { while (typeof stage !== "string") {
stage = await stage.complete(); stage = await stage.complete();
} }
await this.login(this._username, this._password); // stage is username when registration is completed
await this.login(stage, this._password);
} }
async login(username: string, password: string): Promise<void> { async login(username: string, password: string): Promise<void> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment