2018-09-05 19:07:39 +03: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 13:47:47 +03:00
|
|
|
import React from "react";
|
2021-10-23 01:23:32 +03:00
|
|
|
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from "./dispatcher/dispatcher";
|
2018-09-05 19:07:39 +03:00
|
|
|
import Modal from "./Modal";
|
|
|
|
import { _t } from "./languageHandler";
|
2021-09-27 13:47:47 +03:00
|
|
|
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
|
2022-02-22 13:04:27 +03:00
|
|
|
import { Action } from "./dispatcher/actions";
|
2018-09-05 19:07:39 +03:00
|
|
|
|
2018-12-14 02:05:34 +03: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 08:00:06 +03:00
|
|
|
export const SAFE_LOCALPART_REGEX = /^[a-z0-9=_\-./]+$/;
|
2018-12-14 02:05:34 +03:00
|
|
|
|
2018-09-05 19:07:39 +03:00
|
|
|
/**
|
|
|
|
* Starts either the ILAG or full registration flow, depending
|
|
|
|
* on what the HS supports
|
2018-09-05 22:34:03 +03:00
|
|
|
*
|
|
|
|
* @param {object} options
|
2019-02-08 15:12:43 +03: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 20:15:19 +03:00
|
|
|
* @param {bool} options.screen_after
|
2020-02-05 18:36:00 +03:00
|
|
|
* If present the screen to redirect to after a successful login or register.
|
2018-09-05 19:07:39 +03:00
|
|
|
*/
|
2021-09-27 13:47:47 +03:00
|
|
|
export async function startAnyRegistrationFlow(
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
options: { go_home_on_cancel?: boolean; go_welcome_on_cancel?: boolean; screen_after?: boolean },
|
|
|
|
): Promise<void> {
|
2018-09-05 19:07:39 +03:00
|
|
|
if (options === undefined) options = {};
|
2022-06-14 19:51:51 +03:00
|
|
|
const modal = Modal.createDialog(QuestionDialog, {
|
2020-10-07 14:49:29 +03:00
|
|
|
hasCancelButton: true,
|
|
|
|
quitOnly: true,
|
|
|
|
title: _t("Sign In or Create Account"),
|
|
|
|
description: _t("Use your account or create a new one to continue."),
|
|
|
|
button: _t("Create Account"),
|
|
|
|
extraButtons: [
|
2021-07-23 12:23:45 +03:00
|
|
|
<button
|
|
|
|
key="start_login"
|
|
|
|
onClick={() => {
|
|
|
|
modal.close();
|
|
|
|
dis.dispatch({ action: "start_login", screenAfterLogin: options.screen_after });
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{_t("Sign In")}
|
|
|
|
</button>,
|
2020-10-07 14:49:29 +03:00
|
|
|
],
|
|
|
|
onFinished: (proceed) => {
|
|
|
|
if (proceed) {
|
2021-06-29 15:11:58 +03:00
|
|
|
dis.dispatch({ action: "start_registration", screenAfterLogin: options.screen_after });
|
2020-10-07 14:49:29 +03:00
|
|
|
} else if (options.go_home_on_cancel) {
|
2022-02-22 13:04:27 +03:00
|
|
|
dis.dispatch({ action: Action.ViewHomePage });
|
2020-10-07 14:49:29 +03:00
|
|
|
} else if (options.go_welcome_on_cancel) {
|
2021-06-29 15:11:58 +03:00
|
|
|
dis.dispatch({ action: "view_welcome_page" });
|
2020-10-07 14:49:29 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2018-09-05 19:07:39 +03:00
|
|
|
}
|