Make UIAuth Dialog show an error

when auth fails
pull/21833/head
David Baker 2017-03-03 12:08:26 +00:00
parent 8522231d4f
commit 977b8a7379
3 changed files with 52 additions and 12 deletions

View File

@ -41,11 +41,12 @@ export default React.createClass({
// callback // callback
makeRequest: React.PropTypes.func.isRequired, makeRequest: React.PropTypes.func.isRequired,
// callback called when the auth process has finished // callback called when the auth process has finished,
// successfully or unsuccessfully.
// @param {bool} status True if the operation requiring // @param {bool} status True if the operation requiring
// auth was completed sucessfully, false if canceled. // auth was completed sucessfully, false if canceled.
// @param result The result of the authenticated call // @param result The result of the authenticated call
onFinished: React.PropTypes.func.isRequired, onAuthFinished: React.PropTypes.func.isRequired,
// Inputs provided by the user to the auth process // Inputs provided by the user to the auth process
// and used by various stages. As passed to js-sdk // and used by various stages. As passed to js-sdk
@ -87,9 +88,9 @@ export default React.createClass({
}); });
this._authLogic.attemptAuth().then((result) => { this._authLogic.attemptAuth().then((result) => {
this.props.onFinished(true, result); this.props.onAuthFinished(true, result);
}).catch((error) => { }).catch((error) => {
this.props.onFinished(false, error); this.props.onAuthFinished(false, error);
console.error("Error during user-interactive auth:", error); console.error("Error during user-interactive auth:", error);
if (this._unmounted) { if (this._unmounted) {
return; return;
@ -179,7 +180,7 @@ export default React.createClass({
}, },
_onAuthStageFailed: function(e) { _onAuthStageFailed: function(e) {
this.props.onFinished(false, e); this.props.onAuthFinished(false, e);
}, },
_setEmailSid: function(sid) { _setEmailSid: function(sid) {
this._authLogic.setEmailSid(sid); this._authLogic.setEmailSid(sid);

View File

@ -338,7 +338,7 @@ module.exports = React.createClass({
<InteractiveAuth <InteractiveAuth
matrixClient={this._matrixClient} matrixClient={this._matrixClient}
makeRequest={this._makeRegisterRequest} makeRequest={this._makeRegisterRequest}
onFinished={this._onUIAuthFinished} onAuthFinished={this._onUIAuthFinished}
inputs={this._getUIAuthInputs()} inputs={this._getUIAuthInputs()}
makeRegistrationUrl={this.props.makeRegistrationUrl} makeRegistrationUrl={this.props.makeRegistrationUrl}
sessionId={this.props.sessionId} sessionId={this.props.sessionId}

View File

@ -52,23 +52,62 @@ export default React.createClass({
}; };
}, },
getInitialState: function() {
return {
authError: null,
}
},
_onAuthFinished: function(success, result) {
if (success) {
this.props.onFinished(true);
} else {
this.setState({
authError: result,
});
}
},
_onDismissClick: function() {
this.props.onFinished(false);
},
render: function() { render: function() {
const InteractiveAuth = sdk.getComponent("structures.InteractiveAuth"); const InteractiveAuth = sdk.getComponent("structures.InteractiveAuth");
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
return ( let content;
<BaseDialog className="mx_InteractiveAuthDialog" if (this.state.authError) {
onFinished={this.props.onFinished} content = (
title={this.props.title} <div>
> <div>{this.state.authError.message || this.state.authError.toString()}</div>
<br />
<AccessibleButton onClick={this._onDismissClick}
className="mx_UserSettings_button"
>
Dismiss
</AccessibleButton>
</div>
);
} else {
content = (
<div> <div>
<InteractiveAuth ref={this._collectInteractiveAuth} <InteractiveAuth ref={this._collectInteractiveAuth}
matrixClient={this.props.matrixClient} matrixClient={this.props.matrixClient}
authData={this.props.authData} authData={this.props.authData}
makeRequest={this.props.makeRequest} makeRequest={this.props.makeRequest}
onFinished={this.props.onFinished} onAuthFinished={this._onAuthFinished}
/> />
</div> </div>
);
}
return (
<BaseDialog className="mx_InteractiveAuthDialog"
onFinished={this.props.onFinished}
title={this.state.authError ? 'Error' : this.props.title}
>
{content}
</BaseDialog> </BaseDialog>
); );
}, },