2019-01-29 02:32:56 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2019-01-29 02:32:56 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-05-03 07:57:49 +03:00
|
|
|
import {ValidatedServerConfig} from "../../../utils/AutoDiscoveryUtils";
|
|
|
|
import SdkConfig from "../../../SdkConfig";
|
|
|
|
import AutoDiscoveryUtils from "../../../utils/AutoDiscoveryUtils";
|
|
|
|
import * as ServerType from '../../views/auth/ServerTypeSelector';
|
2019-08-11 05:34:12 +03:00
|
|
|
import ServerConfig from "./ServerConfig";
|
2019-01-29 02:32:56 +03:00
|
|
|
|
|
|
|
const MODULAR_URL = 'https://modular.im/?utm_source=riot-web&utm_medium=web&utm_campaign=riot-web-authentication';
|
|
|
|
|
2019-05-03 07:57:49 +03:00
|
|
|
// TODO: TravisR - Can this extend ServerConfig for most things?
|
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
/*
|
2019-01-29 02:32:56 +03:00
|
|
|
* Configure the Modular server name.
|
|
|
|
*
|
|
|
|
* This is a variant of ServerConfig with only the HS field and different body
|
|
|
|
* text that is specific to the Modular case.
|
|
|
|
*/
|
2019-08-11 05:34:12 +03:00
|
|
|
export default class ModularServerConfig extends ServerConfig {
|
|
|
|
static propTypes = ServerConfig.propTypes;
|
2019-05-03 07:57:49 +03:00
|
|
|
|
|
|
|
async validateAndApplyServer(hsUrl, isUrl) {
|
|
|
|
// Always try and use the defaults first
|
|
|
|
const defaultConfig: ValidatedServerConfig = SdkConfig.get()["validated_server_config"];
|
|
|
|
if (defaultConfig.hsUrl === hsUrl && defaultConfig.isUrl === isUrl) {
|
|
|
|
this.setState({busy: false, errorText: ""});
|
|
|
|
this.props.onServerConfigChange(defaultConfig);
|
|
|
|
return defaultConfig;
|
|
|
|
}
|
2019-01-29 02:32:56 +03:00
|
|
|
|
|
|
|
this.setState({
|
2019-05-03 07:57:49 +03:00
|
|
|
hsUrl,
|
|
|
|
isUrl,
|
|
|
|
busy: true,
|
|
|
|
errorText: "",
|
2019-01-29 02:32:56 +03:00
|
|
|
});
|
2019-05-03 07:57:49 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
const result = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl, isUrl);
|
|
|
|
this.setState({busy: false, errorText: ""});
|
|
|
|
this.props.onServerConfigChange(result);
|
|
|
|
return result;
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
let message = _t("Unable to validate homeserver/identity server");
|
|
|
|
if (e.translatedMessage) {
|
|
|
|
message = e.translatedMessage;
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
busy: false,
|
|
|
|
errorText: message,
|
|
|
|
});
|
2019-06-05 08:41:59 +03:00
|
|
|
|
|
|
|
return null;
|
2019-05-03 07:57:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async validateServer() {
|
|
|
|
// TODO: Do we want to support .well-known lookups here?
|
|
|
|
// If for some reason someone enters "matrix.org" for a URL, we could do a lookup to
|
|
|
|
// find their homeserver without demanding they use "https://matrix.org"
|
|
|
|
return this.validateAndApplyServer(this.state.hsUrl, ServerType.TYPES.PREMIUM.identityServerUrl);
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
2019-01-29 02:32:56 +03:00
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
render() {
|
2019-01-29 02:32:56 +03:00
|
|
|
const Field = sdk.getComponent('elements.Field');
|
2019-05-14 01:30:34 +03:00
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
|
|
|
|
|
|
|
const submitButton = this.props.submitText
|
|
|
|
? <AccessibleButton
|
|
|
|
element="button"
|
|
|
|
type="submit"
|
|
|
|
className={this.props.submitClass}
|
|
|
|
onClick={this.onSubmit}
|
|
|
|
disabled={this.state.busy}>{this.props.submitText}</AccessibleButton>
|
|
|
|
: null;
|
2019-01-29 02:32:56 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mx_ServerConfig">
|
|
|
|
<h3>{_t("Your Modular server")}</h3>
|
|
|
|
{_t(
|
|
|
|
"Enter the location of your Modular homeserver. It may use your own " +
|
|
|
|
"domain name or be a subdomain of <a>modular.im</a>.",
|
|
|
|
{}, {
|
2020-02-24 01:14:29 +03:00
|
|
|
a: sub => <a href={MODULAR_URL} target="_blank" rel="noreferrer noopener">
|
2019-01-29 02:32:56 +03:00
|
|
|
{sub}
|
|
|
|
</a>,
|
|
|
|
},
|
|
|
|
)}
|
2019-10-03 23:47:19 +03:00
|
|
|
<form onSubmit={this.onSubmit} autoComplete="off" action={null}>
|
2019-05-14 01:30:34 +03:00
|
|
|
<div className="mx_ServerConfig_fields">
|
|
|
|
<Field id="mx_ServerConfig_hsUrl"
|
|
|
|
label={_t("Server Name")}
|
|
|
|
placeholder={this.props.serverConfig.hsUrl}
|
|
|
|
value={this.state.hsUrl}
|
|
|
|
onBlur={this.onHomeserverBlur}
|
|
|
|
onChange={this.onHomeserverChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{submitButton}
|
|
|
|
</form>
|
2019-01-29 02:32:56 +03:00
|
|
|
</div>
|
|
|
|
);
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
|
|
|
}
|