2018-09-05 18:07:39 +02:00
|
|
|
/*
|
|
|
|
Copyright 2018 New Vector Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-23 00:23:32 +02:00
|
|
|
|
2022-12-12 12:24:14 +01: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";
|
2023-03-14 16:20:38 +01:00
|
|
|
import SettingsStore from "./settings/SettingsStore";
|
|
|
|
import { UIFeature } from "./settings/UIFeature";
|
2018-09-05 18:07:39 +02:00
|
|
|
|
2018-12-14 00:05:34 +01:00
|
|
|
// 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-14 06:00:06 +01:00
|
|
|
export const SAFE_LOCALPART_REGEX = /^[a-z0-9=_\-./]+$/;
|
2018-12-14 00:05:34 +01:00
|
|
|
|
2018-09-05 18:07:39 +02:00
|
|
|
/**
|
|
|
|
* Starts either the ILAG or full registration flow, depending
|
|
|
|
* on what the HS supports
|
2018-09-05 21:34:03 +02:00
|
|
|
*
|
|
|
|
* @param {object} options
|
2019-02-08 13:12:43 +01: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
|
2020-01-12 18:15:19 +01:00
|
|
|
* @param {bool} options.screen_after
|
2020-02-05 16:36:00 +01:00
|
|
|
* If present the screen to redirect to after a successful login or register.
|
2018-09-05 18:07:39 +02:00
|
|
|
*/
|
2021-09-27 12:47:47 +02:00
|
|
|
export async function startAnyRegistrationFlow(
|
|
|
|
// eslint-disable-next-line camelcase
|
2023-03-14 16:20:38 +01:00
|
|
|
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 18:51:51 +02:00
|
|
|
const modal = Modal.createDialog(QuestionDialog, {
|
2020-10-07 13:49:29 +02:00
|
|
|
hasCancelButton: true,
|
|
|
|
quitOnly: true,
|
2023-09-19 08:17:31 +02:00
|
|
|
title: SettingsStore.getValue(UIFeature.Registration) ? _t("auth|sign_in_or_register") : _t("action|sign_in"),
|
2023-03-14 16:20:38 +01:00
|
|
|
description: SettingsStore.getValue(UIFeature.Registration)
|
2023-09-19 08:17:31 +02:00
|
|
|
? _t("auth|sign_in_or_register_description")
|
|
|
|
: _t("auth|sign_in_description"),
|
2023-08-23 12:57:22 +02:00
|
|
|
button: _t("action|sign_in"),
|
2023-03-14 16:20:38 +01:00
|
|
|
extraButtons: SettingsStore.getValue(UIFeature.Registration)
|
|
|
|
? [
|
|
|
|
<button
|
|
|
|
key="register"
|
|
|
|
onClick={() => {
|
|
|
|
modal.close();
|
|
|
|
dis.dispatch({ action: "start_registration", screenAfterLogin: options.screen_after });
|
|
|
|
}}
|
|
|
|
>
|
2023-09-19 08:17:31 +02:00
|
|
|
{_t("auth|register_action")}
|
2023-03-14 16:20:38 +01:00
|
|
|
</button>,
|
|
|
|
]
|
|
|
|
: [],
|
2020-10-07 13:49:29 +02:00
|
|
|
onFinished: (proceed) => {
|
|
|
|
if (proceed) {
|
2023-03-14 16:20:38 +01:00
|
|
|
dis.dispatch({ action: "start_login", screenAfterLogin: options.screen_after });
|
2020-10-07 13:49:29 +02:00
|
|
|
} else if (options.go_home_on_cancel) {
|
2022-02-22 11:04:27 +01:00
|
|
|
dis.dispatch({ action: Action.ViewHomePage });
|
2020-10-07 13:49:29 +02:00
|
|
|
} else if (options.go_welcome_on_cancel) {
|
2022-12-12 12:24:14 +01:00
|
|
|
dis.dispatch({ action: "view_welcome_page" });
|
2020-10-07 13:49:29 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2018-09-05 18:07:39 +02:00
|
|
|
}
|