matrix-bot/src/components/views/dialogs/SetPasswordDialog.js

119 lines
3.9 KiB
JavaScript
Raw Normal View History

/*
Copyright 2017 Vector Creations 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';
import sdk from 'matrix-react-sdk';
2017-06-05 17:13:44 +02:00
import { _t } from 'matrix-react-sdk/lib/languageHandler';
/**
* Prompt the user to set a password
*
* On success, `onFinished()` when finished
*/
export default React.createClass({
displayName: 'SetPasswordDialog',
propTypes: {
onFinished: React.PropTypes.func.isRequired,
},
getInitialState: function() {
return {
error: null,
success: false,
};
},
_onPasswordChanged: function() {
this.setState({
success: true,
});
},
_onContinueClicked: function() {
this.props.onFinished(true);
},
_onPasswordChangeError: function(err) {
let errMsg = err.error || "";
if (err.httpStatus === 403) {
2017-06-05 17:13:44 +02:00
errMsg = _t('Failed to change password. Is your password correct?');
} else if (err.httpStatus) {
2017-06-05 17:13:44 +02:00
errMsg += _t(
2017-06-08 23:48:00 +02:00
' (HTTP status %(httpStatus)s)',
2017-06-05 17:13:44 +02:00
{ httpStatus: err.httpStatus },
);
}
this.setState({
error: errMsg,
});
},
render: function() {
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
const ChangePassword = sdk.getComponent('views.settings.ChangePassword');
if (this.state.success) {
return (
<BaseDialog className="mx_SetPasswordDialog"
onFinished={this.props.onFinished}
2017-06-05 17:13:44 +02:00
title={ _t('You have successfully set a password!') }
>
<div className="mx_Dialog_content">
<p>
2017-06-05 17:13:44 +02:00
{ _t('You can now return to your account after signing out, and sign in on other devices.') }
</p>
</div>
<div className="mx_Dialog_buttons">
<button
className="mx_Dialog_primary"
autoFocus={true}
onClick={this._onContinueClicked}>
2017-06-05 17:13:44 +02:00
{ _t('Continue') }
</button>
</div>
</BaseDialog>
);
}
return (
<BaseDialog className="mx_SetPasswordDialog"
onFinished={this.props.onFinished}
2017-06-05 17:13:44 +02:00
title={ _t('Please set a password!') }
>
<div className="mx_Dialog_content">
<p>
2017-06-05 17:13:44 +02:00
{ _t('This will allow you to return to your account after signing out, and sign in on other devices.') }
</p>
<ChangePassword
className="mx_SetPasswordDialog_change_password"
rowClassName=""
rowLabelClassName=""
rowInputClassName=""
buttonClassName="mx_Dialog_primary mx_SetPasswordDialog_change_password_button"
2017-05-16 13:45:30 +02:00
confirm={false}
autoFocusNewPasswordInput={true}
onError={this._onPasswordChangeError}
onFinished={this._onPasswordChanged} />
<div className="error">
{ this.state.error }
</div>
</div>
</BaseDialog>
);
},
});