Skip to content

Commit 0e787a0

Browse files
author
Luke Barnard
committed
Implement dialog to set password
Until matrix-org/matrix-react-sdk#881, ChangePassword will not know about the cached password (so it won't hide "Current Password" yet). There's also a bit of work left - informing the SessionStore that the password has changed (marked with a TODO)
1 parent 607ba57 commit 0e787a0

4 files changed

Lines changed: 130 additions & 6 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
Copyright 2016 OpenMarket Ltd
3+
Copyright 2017 Vector Creations Ltd
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import q from 'q';
19+
import React from 'react';
20+
import sdk from 'matrix-react-sdk';
21+
import {MatrixClientPeg} from 'matrix-react-sdk';
22+
import classnames from 'classnames';
23+
24+
/**
25+
* Prompt the user to set a password
26+
*
27+
* On success, `onFinished()` when finished
28+
*/
29+
export default React.createClass({
30+
displayName: 'SetPasswordDialog',
31+
propTypes: {
32+
onFinished: React.PropTypes.func.isRequired,
33+
},
34+
35+
getInitialState: function() {
36+
return {
37+
error: null,
38+
};
39+
},
40+
41+
_onPasswordChanged: function() {
42+
this.props.onFinished();
43+
},
44+
45+
_onPasswordChangeError: function(err) {
46+
let errMsg = err.error || "";
47+
if (err.httpStatus === 403) {
48+
errMsg = "Failed to change password. Is your password correct?";
49+
} else if (err.httpStatus) {
50+
errMsg += ` (HTTP status ${err.httpStatus})`;
51+
}
52+
this.setState({
53+
error: errMsg,
54+
});
55+
},
56+
57+
render: function() {
58+
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
59+
const ChangePassword = sdk.getComponent('views.settings.ChangePassword');
60+
const Spinner = sdk.getComponent('elements.Spinner');
61+
62+
return (
63+
<BaseDialog className="mx_SetPasswordDialog"
64+
onFinished={this.props.onFinished}
65+
title="Please set a new password!"
66+
>
67+
<div className="mx_Dialog_content">
68+
<p>
69+
This will allow you to return to your account after signing out,
70+
and sign in on other devices.
71+
</p>
72+
<ChangePassword
73+
className="mx_SetPasswordDialog_change_password"
74+
rowClassName=""
75+
rowLabelClassName=""
76+
rowInputClassName=""
77+
buttonClassName="mx_Dialog_primary mx_SetPasswordDialog_change_password_button"
78+
disableConfirmation={true}
79+
onError={this._onPasswordChangeError}
80+
onFinished={this._onPasswordChanged} />
81+
<div className="error">
82+
{ this.state.error }
83+
</div>
84+
</div>
85+
</BaseDialog>
86+
);
87+
},
88+
});

‎src/components/views/globals/PasswordNagBar.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import Modal from 'matrix-react-sdk/lib/Modal';
2222

2323
export default React.createClass({
2424
onUpdateClicked: function() {
25-
// TODO: Implement dialog to set password
26-
// const SetPasswordDialog = sdk.getComponent('dialogs.SetPasswordDialog');
27-
// Modal.createDialog(SetPasswordDialog, {
28-
// onFinished: () => {
29-
// }
30-
// });
25+
const SetPasswordDialog = sdk.getComponent('dialogs.SetPasswordDialog');
26+
Modal.createDialog(SetPasswordDialog, {
27+
onFinished: () => {
28+
//TODO: Notify SessionStore of changed password: dispatch password_changed
29+
}
30+
});
3131
},
3232

3333
render: function() {

‎src/skins/vector/css/_components.scss‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
@import "./vector-web/views/context_menus/_MessageContextMenu.scss";
7070
@import "./vector-web/views/context_menus/_RoomTileContextMenu.scss";
7171
@import "./vector-web/views/dialogs/_ChangelogDialog.scss";
72+
@import "./vector-web/views/dialogs/_SetPasswordDialog.scss";
7273
@import "./vector-web/views/directory/_NetworkDropdown.scss";
7374
@import "./vector-web/views/elements/_ImageView.scss";
7475
@import "./vector-web/views/elements/_Spinner.scss";
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2017 Vector Creations Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_SetPasswordDialog_change_password input {
18+
border-radius: 3px;
19+
border: 1px solid $input-border-color;
20+
padding: 9px;
21+
color: $primary-fg-color;
22+
background-color: $primary-bg-color;
23+
font-size: 15px;
24+
width: 100%;
25+
max-width: 280px;
26+
margin-bottom: 10px;
27+
}
28+
29+
.mx_SetPasswordDialog_change_password_button {
30+
margin-top: 68px;
31+
}
32+
33+
.mx_SetPasswordDialog .mx_Dialog_content {
34+
margin-bottom: 0px;
35+
}

0 commit comments

Comments
 (0)