2018-04-12 01:58:04 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-06-18 20:14:48 +03:00
|
|
|
Copyright 2018 New Vector Ltd
|
2019-07-31 14:19:29 +03:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2018-04-12 01:58:04 +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';
|
2019-08-24 13:59:46 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2019-07-31 14:19:29 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2018-04-13 02:43:44 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import Modal from '../../../Modal';
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
const WarmFuzzy = function(props) {
|
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
|
|
|
let title = _t('You have successfully set a password!');
|
|
|
|
if (props.didSetEmail) {
|
|
|
|
title = _t('You have successfully set a password and an email address!');
|
|
|
|
}
|
2020-01-29 18:48:25 +03:00
|
|
|
const advice = _t('You can now return to your account after signing out, and sign in on other sessions.');
|
2018-04-12 01:58:04 +03:00
|
|
|
let extraAdvice = null;
|
|
|
|
if (!props.didSetEmail) {
|
|
|
|
extraAdvice = _t('Remember, you can always set an email address in user settings if you change your mind.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return <BaseDialog className="mx_SetPasswordDialog"
|
|
|
|
onFinished={props.onFinished}
|
|
|
|
title={ title }
|
|
|
|
>
|
|
|
|
<div className="mx_Dialog_content">
|
|
|
|
<p>
|
|
|
|
{ advice }
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{ extraAdvice }
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="mx_Dialog_buttons">
|
|
|
|
<button
|
|
|
|
className="mx_Dialog_primary"
|
|
|
|
autoFocus={true}
|
|
|
|
onClick={props.onFinished}>
|
|
|
|
{ _t('Continue') }
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</BaseDialog>;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prompt the user to set a password
|
|
|
|
*
|
|
|
|
* On success, `onFinished()` when finished
|
|
|
|
*/
|
2019-08-24 13:59:46 +03:00
|
|
|
export default createReactClass({
|
2018-04-12 01:58:04 +03:00
|
|
|
displayName: 'SetPasswordDialog',
|
|
|
|
propTypes: {
|
2019-07-31 14:19:29 +03:00
|
|
|
onFinished: PropTypes.func.isRequired,
|
2018-04-12 01:58:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
error: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
console.info('SetPasswordDialog component will mount');
|
|
|
|
},
|
|
|
|
|
|
|
|
_onPasswordChanged: function(res) {
|
|
|
|
Modal.createDialog(WarmFuzzy, {
|
|
|
|
didSetEmail: res.didSetEmail,
|
|
|
|
onFinished: () => {
|
2018-06-18 20:14:48 +03:00
|
|
|
this.props.onFinished();
|
2018-04-12 01:58:04 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_onPasswordChangeError: function(err) {
|
|
|
|
let errMsg = err.error || "";
|
|
|
|
if (err.httpStatus === 403) {
|
|
|
|
errMsg = _t('Failed to change password. Is your password correct?');
|
|
|
|
} else if (err.httpStatus) {
|
|
|
|
errMsg += ' ' + _t(
|
|
|
|
'(HTTP status %(httpStatus)s)',
|
|
|
|
{ httpStatus: err.httpStatus },
|
|
|
|
);
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
error: errMsg,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
|
|
|
const ChangePassword = sdk.getComponent('views.settings.ChangePassword');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BaseDialog className="mx_SetPasswordDialog"
|
|
|
|
onFinished={this.props.onFinished}
|
|
|
|
title={ _t('Please set a password!') }
|
|
|
|
>
|
|
|
|
<div className="mx_Dialog_content">
|
|
|
|
<p>
|
2020-01-29 18:48:25 +03:00
|
|
|
{ _t('This will allow you to return to your account after signing out, and sign in on other sessions.') }
|
2018-04-12 01:58:04 +03:00
|
|
|
</p>
|
|
|
|
<ChangePassword
|
|
|
|
className="mx_SetPasswordDialog_change_password"
|
|
|
|
rowClassName=""
|
2019-01-22 23:09:40 +03:00
|
|
|
buttonClassNames="mx_Dialog_primary mx_SetPasswordDialog_change_password_button"
|
|
|
|
buttonKind="primary"
|
2018-04-12 01:58:04 +03:00
|
|
|
confirm={false}
|
|
|
|
autoFocusNewPasswordInput={true}
|
|
|
|
shouldAskForEmail={true}
|
|
|
|
onError={this._onPasswordChangeError}
|
|
|
|
onFinished={this._onPasswordChanged} />
|
|
|
|
<div className="error">
|
|
|
|
{ this.state.error }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</BaseDialog>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|