Skip to content

Commit c6ff452

Browse files
authored
Merge pull request element-hq#3921 from vector-im/luke/new-guest-access-set-pwd-dialog
Implement dialog to set password
2 parents e6f6b8c + 11d88aa commit c6ff452

4 files changed

Lines changed: 133 additions & 6 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
import q from 'q';
18+
import React from 'react';
19+
import sdk from 'matrix-react-sdk';
20+
import {MatrixClientPeg} from 'matrix-react-sdk';
21+
import classnames from 'classnames';
22+
23+
/**
24+
* Prompt the user to set a password
25+
*
26+
* On success, `onFinished()` when finished
27+
*/
28+
export default React.createClass({
29+
displayName: 'SetPasswordDialog',
30+
propTypes: {
31+
onFinished: React.PropTypes.func.isRequired,
32+
},
33+
34+
getInitialState: function() {
35+
return {
36+
error: null,
37+
};
38+
},
39+
40+
_onPasswordChanged: function() {
41+
this.props.onFinished();
42+
},
43+
44+
_onPasswordChangeError: function(err) {
45+
let errMsg = err.error || "";
46+
if (err.httpStatus === 403) {
47+
errMsg = "Failed to change password. Is your password correct?";
48+
} else if (err.httpStatus) {
49+
errMsg += ` (HTTP status ${err.httpStatus})`;
50+
}
51+
this.setState({
52+
error: errMsg,
53+
});
54+
},
55+
56+
render: function() {
57+
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
58+
const ChangePassword = sdk.getComponent('views.settings.ChangePassword');
59+
const Spinner = sdk.getComponent('elements.Spinner');
60+
61+
return (
62+
<BaseDialog className="mx_SetPasswordDialog"
63+
onFinished={this.props.onFinished}
64+
title="Please set a new password!"
65+
>
66+
<div className="mx_Dialog_content">
67+
<p>
68+
This will allow you to return to your account after signing out,
69+
and sign in on other devices.
70+
</p>
71+
<ChangePassword
72+
className="mx_SetPasswordDialog_change_password"
73+
rowClassName=""
74+
rowLabelClassName=""
75+
rowInputClassName=""
76+
buttonClassName="mx_Dialog_primary mx_SetPasswordDialog_change_password_button"
77+
confirm={false}
78+
onError={this._onPasswordChangeError}
79+
onFinished={this._onPasswordChanged} />
80+
<div className="error">
81+
{ this.state.error }
82+
</div>
83+
</div>
84+
</BaseDialog>
85+
);
86+
},
87+
});

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ limitations under the License.
1919
import React from 'react';
2020
import sdk from 'matrix-react-sdk';
2121
import Modal from 'matrix-react-sdk/lib/Modal';
22+
import dis from 'matrix-react-sdk/lib/dispatcher';
2223

2324
export default React.createClass({
2425
onUpdateClicked: function() {
25-
// TODO: Implement dialog to set password
26-
// const SetPasswordDialog = sdk.getComponent('dialogs.SetPasswordDialog');
27-
// Modal.createDialog(SetPasswordDialog, {
28-
// onFinished: () => {
29-
// }
30-
// });
26+
const SetPasswordDialog = sdk.getComponent('dialogs.SetPasswordDialog');
27+
Modal.createDialog(SetPasswordDialog, {
28+
onFinished: () => {
29+
// Notify SessionStore that the user's password was changed
30+
dis.dispatch({
31+
action: 'password_changed',
32+
});
33+
}
34+
});
3135
},
3236

3337
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)