2016-10-11 20:04:55 +03:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-02-13 19:15:00 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2016-10-11 20:04:55 +03:00
|
|
|
|
|
|
|
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';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2016-10-11 20:04:55 +03:00
|
|
|
|
|
|
|
import sdk from '../../../index';
|
2017-05-25 20:20:48 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2016-10-11 20:04:55 +03:00
|
|
|
|
2017-02-13 19:03:21 +03:00
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
2016-10-11 20:04:55 +03:00
|
|
|
|
|
|
|
export default React.createClass({
|
|
|
|
displayName: 'InteractiveAuthDialog',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-02-24 14:41:23 +03:00
|
|
|
// matrix client to use for UI auth requests
|
2017-12-26 04:03:18 +03:00
|
|
|
matrixClient: PropTypes.object.isRequired,
|
2017-02-24 14:41:23 +03:00
|
|
|
|
2016-10-11 20:04:55 +03:00
|
|
|
// response from initial request. If not supplied, will do a request on
|
|
|
|
// mount.
|
2017-12-26 04:03:18 +03:00
|
|
|
authData: PropTypes.shape({
|
|
|
|
flows: PropTypes.array,
|
|
|
|
params: PropTypes.object,
|
|
|
|
session: PropTypes.string,
|
2016-10-11 20:04:55 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
// callback
|
2017-12-26 04:03:18 +03:00
|
|
|
makeRequest: PropTypes.func.isRequired,
|
2016-10-11 20:04:55 +03:00
|
|
|
|
2017-12-26 04:03:18 +03:00
|
|
|
onFinished: PropTypes.func.isRequired,
|
2016-10-11 20:04:55 +03:00
|
|
|
|
2017-12-26 04:03:18 +03:00
|
|
|
title: PropTypes.string,
|
2016-10-11 20:04:55 +03:00
|
|
|
},
|
|
|
|
|
2017-03-03 15:08:26 +03:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
authError: null,
|
2017-10-11 19:56:17 +03:00
|
|
|
};
|
2017-03-03 15:08:26 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_onAuthFinished: function(success, result) {
|
|
|
|
if (success) {
|
2017-03-03 17:31:52 +03:00
|
|
|
this.props.onFinished(true, result);
|
2017-03-03 15:08:26 +03:00
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
authError: result,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDismissClick: function() {
|
|
|
|
this.props.onFinished(false);
|
|
|
|
},
|
|
|
|
|
2016-10-11 20:04:55 +03:00
|
|
|
render: function() {
|
2017-02-13 19:03:21 +03:00
|
|
|
const InteractiveAuth = sdk.getComponent("structures.InteractiveAuth");
|
2017-01-24 18:54:05 +03:00
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
2016-10-11 20:04:55 +03:00
|
|
|
|
2017-03-03 15:08:26 +03:00
|
|
|
let content;
|
|
|
|
if (this.state.authError) {
|
|
|
|
content = (
|
2017-12-05 15:52:20 +03:00
|
|
|
<div id='mx_Dialog_content'>
|
2017-12-14 12:31:28 +03:00
|
|
|
<div role="alert">{ this.state.authError.message || this.state.authError.toString() }</div>
|
2017-03-03 15:08:26 +03:00
|
|
|
<br />
|
|
|
|
<AccessibleButton onClick={this._onDismissClick}
|
2019-02-04 23:25:26 +03:00
|
|
|
className="mx_GeneralButton"
|
2017-12-05 15:52:20 +03:00
|
|
|
autoFocus="true"
|
2017-03-03 15:08:26 +03:00
|
|
|
>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Dismiss") }
|
2017-03-03 15:08:26 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
content = (
|
2017-12-05 15:52:20 +03:00
|
|
|
<div id='mx_Dialog_content'>
|
2017-02-13 19:03:21 +03:00
|
|
|
<InteractiveAuth ref={this._collectInteractiveAuth}
|
2017-02-24 14:41:23 +03:00
|
|
|
matrixClient={this.props.matrixClient}
|
2017-02-13 19:03:21 +03:00
|
|
|
authData={this.props.authData}
|
|
|
|
makeRequest={this.props.makeRequest}
|
2017-03-03 15:08:26 +03:00
|
|
|
onAuthFinished={this._onAuthFinished}
|
2017-02-13 19:03:21 +03:00
|
|
|
/>
|
2016-10-11 20:04:55 +03:00
|
|
|
</div>
|
2017-03-03 15:08:26 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BaseDialog className="mx_InteractiveAuthDialog"
|
|
|
|
onFinished={this.props.onFinished}
|
2017-05-25 20:20:48 +03:00
|
|
|
title={this.state.authError ? 'Error' : (this.props.title || _t('Authentication'))}
|
2017-12-05 15:52:20 +03:00
|
|
|
contentId='mx_Dialog_content'
|
2017-03-03 15:08:26 +03:00
|
|
|
>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ content }
|
2017-01-24 18:54:05 +03:00
|
|
|
</BaseDialog>
|
2016-10-11 20:04:55 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|