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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import dis from './dispatcher';
|
2019-12-20 02:19:56 +01:00
|
|
|
import * as sdk from './index';
|
2018-09-05 18:07:39 +02:00
|
|
|
import Modal from './Modal';
|
|
|
|
import { _t } from './languageHandler';
|
2019-01-30 18:30:01 +01:00
|
|
|
// import MatrixClientPeg from './MatrixClientPeg';
|
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
|
2018-09-05 18:07:39 +02:00
|
|
|
*/
|
|
|
|
export async function startAnyRegistrationFlow(options) {
|
|
|
|
if (options === undefined) options = {};
|
|
|
|
// look for an ILAG compatible flow. We define this as one
|
|
|
|
// which has only dummy or recaptcha flows. In practice it
|
|
|
|
// would support any stage InteractiveAuth supports, just not
|
|
|
|
// ones like email & msisdn which require the user to supply
|
|
|
|
// the relevant details in advance. We err on the side of
|
|
|
|
// caution though.
|
2018-09-06 16:50:41 +02:00
|
|
|
|
2019-01-30 13:13:09 +01:00
|
|
|
// XXX: ILAG is disabled for now,
|
|
|
|
// see https://github.com/vector-im/riot-web/issues/8222
|
|
|
|
|
|
|
|
// const flows = await _getRegistrationFlows();
|
|
|
|
// const hasIlagFlow = flows.some((flow) => {
|
|
|
|
// return flow.stages.every((stage) => {
|
|
|
|
// return ['m.login.dummy', 'm.login.recaptcha', 'm.login.terms'].includes(stage);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
// if (hasIlagFlow) {
|
|
|
|
// dis.dispatch({
|
|
|
|
// action: 'view_set_mxid',
|
|
|
|
// go_home_on_cancel: options.go_home_on_cancel,
|
|
|
|
// });
|
|
|
|
//} else {
|
2018-09-05 18:07:39 +02:00
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
Modal.createTrackedDialog('Registration required', '', QuestionDialog, {
|
|
|
|
title: _t("Registration Required"),
|
|
|
|
description: _t("You need to register to do this. Would you like to register now?"),
|
|
|
|
button: _t("Register"),
|
|
|
|
onFinished: (proceed) => {
|
|
|
|
if (proceed) {
|
|
|
|
dis.dispatch({action: 'start_registration'});
|
|
|
|
} else if (options.go_home_on_cancel) {
|
|
|
|
dis.dispatch({action: 'view_home_page'});
|
2019-02-08 13:12:43 +01:00
|
|
|
} else if (options.go_welcome_on_cancel) {
|
|
|
|
dis.dispatch({action: 'view_welcome_page'});
|
2018-09-05 18:07:39 +02:00
|
|
|
}
|
2018-09-05 21:34:03 +02:00
|
|
|
},
|
2018-09-05 18:07:39 +02:00
|
|
|
});
|
2019-01-30 13:13:09 +01:00
|
|
|
//}
|
2018-09-05 18:07:39 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 17:08:34 +01:00
|
|
|
// async function _getRegistrationFlows() {
|
|
|
|
// try {
|
|
|
|
// await MatrixClientPeg.get().register(
|
|
|
|
// null,
|
|
|
|
// null,
|
|
|
|
// undefined,
|
|
|
|
// {},
|
|
|
|
// {},
|
|
|
|
// );
|
|
|
|
// console.log("Register request succeeded when it should have returned 401!");
|
|
|
|
// } catch (e) {
|
|
|
|
// if (e.httpStatus === 401) {
|
|
|
|
// return e.data.flows;
|
|
|
|
// }
|
|
|
|
// throw e;
|
|
|
|
// }
|
|
|
|
// throw new Error("Register request succeeded when it should have returned 401!");
|
|
|
|
// }
|
2018-09-05 18:07:39 +02:00
|
|
|
|