mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 04:21:57 +03:00
Remember password for e2e bootstrapping
Fixes https://github.com/vector-im/riot-web/issues/12046
This commit is contained in:
parent
988ae14d35
commit
437b45f8a6
5 changed files with 36 additions and 8 deletions
|
@ -55,6 +55,7 @@ function selectText(target) {
|
|||
export default class CreateSecretStorageDialog extends React.PureComponent {
|
||||
static propTypes = {
|
||||
hasCancel: PropTypes.bool,
|
||||
accountPassword: PropTypes.string,
|
||||
};
|
||||
|
||||
defaultProps = {
|
||||
|
@ -82,7 +83,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
|
|||
// does the server offer a UI auth flow with just m.login.password
|
||||
// for /keys/device_signing/upload?
|
||||
canUploadKeysWithPasswordOnly: null,
|
||||
accountPassword: '',
|
||||
accountPassword: props.accountPassword,
|
||||
accountPasswordCorrect: null,
|
||||
// set if we are 'upgrading' encryption (making an SSSS store from
|
||||
// an existing key backup secret).
|
||||
|
|
|
@ -256,6 +256,9 @@ export default createReactClass({
|
|||
// logout page.
|
||||
Lifecycle.loadSession({});
|
||||
}
|
||||
|
||||
this._accountPassword = null;
|
||||
this._accountPasswordTimer = null;
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
|
@ -352,6 +355,8 @@ export default createReactClass({
|
|||
window.removeEventListener("focus", this.onFocus);
|
||||
window.removeEventListener('resize', this.handleResize);
|
||||
this.state.resizeNotifier.removeListener("middlePanelResized", this._dispatchTimelineResize);
|
||||
|
||||
if (this._accountPasswordTimer !== null) clearTimeout(this._accountPasswordTimer);
|
||||
},
|
||||
|
||||
componentWillUpdate: function(props, state) {
|
||||
|
@ -1729,9 +1734,8 @@ export default createReactClass({
|
|||
this.showScreen("forgot_password");
|
||||
},
|
||||
|
||||
onRegisterFlowComplete: function(credentials) {
|
||||
this.onUserCompletedLoginFlow();
|
||||
return this.onRegistered(credentials);
|
||||
onRegisterFlowComplete: function(credentials, password) {
|
||||
return this.onUserCompletedLoginFlow(credentials, password);
|
||||
},
|
||||
|
||||
// returns a promise which resolves to the new MatrixClient
|
||||
|
@ -1822,7 +1826,14 @@ export default createReactClass({
|
|||
this._loggedInView = ref;
|
||||
},
|
||||
|
||||
async onUserCompletedLoginFlow(credentials) {
|
||||
async onUserCompletedLoginFlow(credentials, password) {
|
||||
this._accountPassword = password;
|
||||
// self-destruct the password after 5mins
|
||||
if (this._accountPasswordTimer !== null) clearTimeout(this._accountPasswordTimer);
|
||||
this._accountPasswordTimer = setTimeout(() => {
|
||||
this._accountPassword = null;
|
||||
this._accountPasswordTimer = null;
|
||||
}, 60 * 5 * 1000);
|
||||
// Wait for the client to be logged in (but not started)
|
||||
// which is enough to ask the server about account data.
|
||||
const loggedIn = new Promise(resolve => {
|
||||
|
@ -1836,7 +1847,7 @@ export default createReactClass({
|
|||
});
|
||||
|
||||
// Create and start the client in the background
|
||||
Lifecycle.setLoggedIn(credentials);
|
||||
const setLoggedInPromise = Lifecycle.setLoggedIn(credentials);
|
||||
await loggedIn;
|
||||
|
||||
const cli = MatrixClientPeg.get();
|
||||
|
@ -1865,6 +1876,8 @@ export default createReactClass({
|
|||
} else {
|
||||
this._onLoggedIn();
|
||||
}
|
||||
|
||||
return setLoggedInPromise;
|
||||
},
|
||||
|
||||
// complete security / e2e setup has finished
|
||||
|
@ -1896,6 +1909,7 @@ export default createReactClass({
|
|||
view = (
|
||||
<E2eSetup
|
||||
onFinished={this.onCompleteSecurityE2eSetupFinished}
|
||||
accountPassword={this._accountPassword}
|
||||
/>
|
||||
);
|
||||
} else if (this.state.view === VIEWS.POST_REGISTRATION) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import * as sdk from '../../../index';
|
|||
export default class E2eSetup extends React.Component {
|
||||
static propTypes = {
|
||||
onFinished: PropTypes.func.isRequired,
|
||||
accountPassword: PropTypes.string,
|
||||
};
|
||||
|
||||
constructor() {
|
||||
|
@ -40,6 +41,7 @@ export default class E2eSetup extends React.Component {
|
|||
<AsyncWrapper prom={this._createStorageDialogPromise}
|
||||
hasCancel={false}
|
||||
onFinished={this.props.onFinished}
|
||||
accountPassword={this.props.accountPassword}
|
||||
/>
|
||||
</AuthBody>
|
||||
</AuthPage>
|
||||
|
|
|
@ -58,6 +58,11 @@ export default createReactClass({
|
|||
displayName: 'Login',
|
||||
|
||||
propTypes: {
|
||||
// Called when the user has logged in. Params:
|
||||
// - The object returned by the login API
|
||||
// - The user's password, if applicable, (may be cached in memory for a
|
||||
// short time so the user is not required to re-enter their password
|
||||
// for operations like uploading cross-signing keys).
|
||||
onLoggedIn: PropTypes.func.isRequired,
|
||||
|
||||
// If true, the component will consider itself busy.
|
||||
|
@ -181,7 +186,7 @@ export default createReactClass({
|
|||
username, phoneCountry, phoneNumber, password,
|
||||
).then((data) => {
|
||||
this.setState({serverIsAlive: true}); // it must be, we logged in.
|
||||
this.props.onLoggedIn(data);
|
||||
this.props.onLoggedIn(data, password);
|
||||
}, (error) => {
|
||||
if (this._unmounted) {
|
||||
return;
|
||||
|
|
|
@ -45,7 +45,13 @@ export default createReactClass({
|
|||
displayName: 'Registration',
|
||||
|
||||
propTypes: {
|
||||
// Called when the user has logged in. Params:
|
||||
// - object with userId, deviceId, homeserverUrl, identityServerUrl, accessToken
|
||||
// - The user's password, if available and applicable (may be cached in memory
|
||||
// for a short time so the user is not required to re-enter their password
|
||||
// for operations like uploading cross-signing keys).
|
||||
onLoggedIn: PropTypes.func.isRequired,
|
||||
|
||||
clientSecret: PropTypes.string,
|
||||
sessionId: PropTypes.string,
|
||||
makeRegistrationUrl: PropTypes.func.isRequired,
|
||||
|
@ -348,7 +354,7 @@ export default createReactClass({
|
|||
homeserverUrl: this.state.matrixClient.getHomeserverUrl(),
|
||||
identityServerUrl: this.state.matrixClient.getIdentityServerUrl(),
|
||||
accessToken: response.access_token,
|
||||
});
|
||||
}, this.state.formVals.password);
|
||||
|
||||
this._setupPushers(cli);
|
||||
// we're still busy until we get unmounted: don't show the registration form again
|
||||
|
|
Loading…
Reference in a new issue