Files
ThreadNet-Web/src/Registration.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.9 KiB
TypeScript
Raw Normal View History

/*
2024-09-09 14:57:16 +01:00
Copyright 2018-2024 New Vector Ltd.
2024-09-09 14:57:16 +01:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/
/**
* Utility code for registering with a homeserver
* Note that this is currently *not* used by the actual
* registration code.
*/
2021-09-27 12:47:47 +02:00
import React from "react";
2021-10-22 17:23:32 -05:00
2020-05-13 20:41:41 -06:00
import dis from "./dispatcher/dispatcher";
import Modal from "./Modal";
import { _t } from "./languageHandler";
2021-09-27 12:47:47 +02:00
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
2022-02-22 11:04:27 +01:00
import { Action } from "./dispatcher/actions";
import SettingsStore from "./settings/SettingsStore";
import { UIFeature } from "./settings/UIFeature";
// Regex for what a "safe" or "Matrix-looking" localpart would be.
// TODO: Update as needed for https://github.com/matrix-org/matrix-doc/issues/1514
2018-12-13 22:00:06 -07:00
export const SAFE_LOCALPART_REGEX = /^[a-z0-9=_\-./]+$/;
/**
* Starts either the ILAG or full registration flow, depending
* on what the HS supports
2018-09-05 20:34:03 +01:00
*
* @param {object} options
2019-02-08 12:12:43 +00:00
* @param {bool} options.go_home_on_cancel
* If true, goes to the home page if the user cancels the action
* @param {bool} options.go_welcome_on_cancel
* If true, goes to the welcome page if the user cancels the action
* @param {bool} options.screen_after
2020-02-05 15:36:00 +00:00
* If present the screen to redirect to after a successful login or register.
*/
2021-09-27 12:47:47 +02:00
export async function startAnyRegistrationFlow(
// eslint-disable-next-line camelcase
options: { go_home_on_cancel?: boolean; go_welcome_on_cancel?: boolean; screen_after?: boolean } = {},
2021-09-27 12:47:47 +02:00
): Promise<void> {
2022-06-14 17:51:51 +01:00
const modal = Modal.createDialog(QuestionDialog, {
2020-10-07 12:49:29 +01:00
hasCancelButton: true,
quitOnly: true,
title: SettingsStore.getValue(UIFeature.Registration) ? _t("auth|sign_in_or_register") : _t("action|sign_in"),
description: SettingsStore.getValue(UIFeature.Registration)
? _t("auth|sign_in_or_register_description")
: _t("auth|sign_in_description"),
button: _t("action|sign_in"),
extraButtons: SettingsStore.getValue(UIFeature.Registration)
? [
<button
key="register"
onClick={() => {
modal.close();
dis.dispatch({ action: "start_registration", screenAfterLogin: options.screen_after });
}}
>
{_t("auth|register_action")}
</button>,
]
: [],
2020-10-07 12:49:29 +01:00
onFinished: (proceed) => {
if (proceed) {
dis.dispatch({ action: "start_login", screenAfterLogin: options.screen_after });
2020-10-07 12:49:29 +01:00
} else if (options.go_home_on_cancel) {
2022-02-22 11:04:27 +01:00
dis.dispatch({ action: Action.ViewHomePage });
2020-10-07 12:49:29 +01:00
} else if (options.go_welcome_on_cancel) {
2021-06-29 13:11:58 +01:00
dis.dispatch({ action: "view_welcome_page" });
2020-10-07 12:49:29 +01:00
}
},
});
}