Skip to content

Commit c68ef38

Browse files
committed
Use ChangeDisplayNname / ChangeAvatar widgets to prompt for display name & avatar at signup.
Fixes element-hq#7.
1 parent ccc5f30 commit c68ef38

4 files changed

Lines changed: 90 additions & 6 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2015 OpenMarket 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+
'use strict';
18+
19+
var extend = require('matrix-react-sdk/lib/extend');
20+
var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg');
21+
var BaseRegisterController = require('matrix-react-sdk/lib/controllers/templates/Register.js');
22+
23+
var RegisterController = {};
24+
extend(RegisterController, BaseRegisterController);
25+
26+
RegisterController.onRegistered = function(user_id, access_token) {
27+
MatrixClientPeg.replaceUsingAccessToken(
28+
this.state.hs_url, this.state.is_url, user_id, access_token
29+
);
30+
31+
this.setState({
32+
step: 'profile',
33+
busy: true
34+
});
35+
36+
var self = this;
37+
var cli = MatrixClientPeg.get();
38+
cli.getProfileInfo(cli.credentials.userId).done(function(result) {
39+
self.setState({
40+
avatarUrl: result.avatar_url,
41+
busy: false
42+
});
43+
},
44+
function(err) {
45+
console.err(err);
46+
self.setState({
47+
busy: false
48+
});
49+
});
50+
};
51+
52+
RegisterController.onAccountReady = function() {
53+
if (this.props.onLoggedIn) {
54+
this.props.onLoggedIn();
55+
}
56+
};
57+
58+
module.exports = RegisterController;

‎src/skins/vector/views/molecules/ChangeAvatar.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ module.exports = React.createClass({
5151
<input type="file" onChange={this.onFileSelected}/>
5252
{this.state.errorText}
5353
</div>
54-
<div className="mx_Dialog_buttons">
55-
<button onClick={this.props.onFinished}>Cancel</button>
56-
</div>
5754
</div>
5855
);
5956
case this.Phases.Uploading:

‎src/skins/vector/views/organisms/UserSettings.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ module.exports = React.createClass({
3030
editAvatar: function() {
3131
var url = MatrixClientPeg.get().mxcUrlToHttp(this.state.avatarUrl);
3232
var ChangeAvatar = sdk.getComponent('molecules.ChangeAvatar');
33-
Modal.createDialog(ChangeAvatar, {initialAvatarUrl: url});
33+
var avatarDialog = (
34+
<div>
35+
<ChangeAvatar initialAvatarUrl={url} />
36+
<div className="mx_Dialog_buttons">
37+
<button onClick={this.onAvatarDialogCancel}>Cancel</button>
38+
</div>
39+
</div>
40+
);
41+
this.avatarDialog = Modal.createDialogWithElement(avatarDialog);
3442
},
3543

3644
addEmail: function() {
@@ -55,6 +63,10 @@ module.exports = React.createClass({
5563
this.logoutModal.closeDialog();
5664
},
5765

66+
onAvatarDialogCancel: function() {
67+
this.avatarDialog.close();
68+
},
69+
5870
render: function() {
5971
switch (this.state.phase) {
6072
case this.Phases.Loading:
@@ -80,7 +92,7 @@ module.exports = React.createClass({
8092

8193
<div className="mx_UserSettings_3pids">
8294
{this.state.threepids.map(function(val) {
83-
return <div>{val.address}</div>;
95+
return <div key={val.address}>{val.address}</div>;
8496
})}
8597
</div>
8698

‎src/skins/vector/views/templates/Register.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ limitations under the License.
1919
var React = require('react');
2020

2121
var sdk = require('matrix-react-sdk')
22+
var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg')
2223

2324
var Loader = require("react-loader");
2425

25-
var RegisterController = require('matrix-react-sdk/lib/controllers/templates/Register')
26+
var RegisterController = require('../../../../controllers/templates/Register')
2627

2728
module.exports = React.createClass({
2829
DEFAULT_HS_URL: 'https://matrix.org',
@@ -79,6 +80,10 @@ module.exports = React.createClass({
7980
this.forceUpdate();
8081
},
8182

83+
onProfileContinueClicked: function() {
84+
this.onAccountReady();
85+
},
86+
8287
componentForStep: function(step) {
8388
switch (step) {
8489
case 'initial':
@@ -127,6 +132,18 @@ module.exports = React.createClass({
127132
return (
128133
<Loader />
129134
);
135+
} else if (this.state.step == 'profile') {
136+
var ChangeDisplayName = sdk.getComponent('molecules.ChangeDisplayName');
137+
var ChangeAvatar = sdk.getComponent('molecules.ChangeAvatar');
138+
return (
139+
<div className="mx_Login_profile">
140+
Set a display name:
141+
<ChangeDisplayName />
142+
Upload an avatar:
143+
<ChangeAvatar initialAvatarUrl={MatrixClientPeg.get().mxcUrlToHttp(this.state.avatarUrl)} />
144+
<button onClick={this.onProfileContinueClicked}>Continue</button>
145+
</div>
146+
);
130147
} else {
131148
return (
132149
<div>

0 commit comments

Comments
 (0)