This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
Initial implementation: SetDisplayName -> SetMxIdDialog #849
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8774100
Initial implementation: SetDisplayName -> SetMxIdDialog
6dff4a4
Return early after cancelled mxid dialog
d12b190
Fix defer promise logic
5a5768a
Try to fix tests
a887af9
copyright
4f71f4c
Store mx_pass at the same point as access_token
13d37e4
Mock isGuest
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
Copyright 2016 OpenMarket Ltd | ||
|
||
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 q from 'q'; | ||
import React from 'react'; | ||
import sdk from '../../../index'; | ||
import MatrixClientPeg from '../../../MatrixClientPeg'; | ||
|
||
/** | ||
* Prompt the user to set a display name. | ||
* | ||
* On success, `onFinished(true, newDisplayName)` is called. | ||
*/ | ||
export default React.createClass({ | ||
displayName: 'SetMxIdDialog', | ||
propTypes: { | ||
onFinished: React.PropTypes.func.isRequired, | ||
}, | ||
|
||
getInitialState: function() { | ||
return { | ||
username : '', | ||
doingUIAuth: false, | ||
} | ||
}, | ||
|
||
componentDidMount: function() { | ||
this.refs.input_value.select(); | ||
|
||
this._matrixClient = MatrixClientPeg.get(); | ||
}, | ||
|
||
onValueChange: function(ev) { | ||
this.setState({ | ||
username: ev.target.value | ||
}); | ||
}, | ||
|
||
onSubmit: function(ev) { | ||
this.setState({ | ||
doingUIAuth: true, | ||
}); | ||
}, | ||
|
||
_generateAndCachePassword: function() { | ||
const pass = Math.random().toString(36).slice(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I guess so! |
||
if (localStorage) { | ||
localStorage.setItem('mx_pass', pass); | ||
} | ||
return pass; | ||
}, | ||
|
||
_makeRegisterRequest: function(auth) { | ||
// Not upgrading - changing mxids | ||
const guestAccessToken = null; | ||
|
||
return this._matrixClient.register( | ||
this.state.username, | ||
this._generateAndCachePassword(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here you're setting the password before the account is registered (and overwriting it with a new one for each time we try to register). It feels like it really ought to be set along with the access token. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, agreed |
||
undefined, // session id: included in the auth dict already | ||
auth, | ||
{}, | ||
guestAccessToken, | ||
); | ||
}, | ||
|
||
_onUIAuthFinished: function(success, response) { | ||
this.setState({ | ||
doingUIAuth: false, | ||
}); | ||
console.info('Auth Finsihed', arguments); | ||
|
||
if (!success) { | ||
this.setState({ errorText : response.message }); | ||
return; | ||
} | ||
|
||
// XXX Implement RTS /register here | ||
const teamToken = null; | ||
|
||
this.props.onFinished(true, { | ||
userId: response.user_id, | ||
deviceId: response.device_id, | ||
homeserverUrl: this._matrixClient.getHomeserverUrl(), | ||
identityServerUrl: this._matrixClient.getIdentityServerUrl(), | ||
accessToken: response.access_token, | ||
teamToken: teamToken, | ||
}); | ||
}, | ||
|
||
render: function() { | ||
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); | ||
const InteractiveAuth = sdk.getComponent('structures.InteractiveAuth'); | ||
const Spinner = sdk.getComponent('elements.Spinner'); | ||
let auth; | ||
if (this.state.doingUIAuth) { | ||
auth = <InteractiveAuth | ||
matrixClient={this._matrixClient} | ||
makeRequest={this._makeRegisterRequest} | ||
onAuthFinished={this._onUIAuthFinished} | ||
inputs={{}} | ||
poll={true} | ||
/>; | ||
} | ||
return ( | ||
<BaseDialog className="mx_SetMxIdDialog" | ||
onFinished={this.props.onFinished} | ||
title="Choose a Username" | ||
> | ||
<div className="mx_Dialog_content"> | ||
<p> | ||
Beyond this point you're going to need to pick a username - your | ||
unique identifire in Riot. | ||
</p> | ||
<p> | ||
<small> | ||
You can't change your username, but you can always choose how you | ||
appear to other people in Riot by changing your display name. | ||
</small> | ||
</p> | ||
<input type="text" ref="input_value" value={this.state.username} | ||
autoFocus={true} onChange={this.onValueChange} size="30" | ||
className="mx_SetMxIdDialog_input" | ||
/> | ||
{ auth } | ||
<div> | ||
{ this.state.errorText } | ||
</div> | ||
</div> | ||
<div className="mx_Dialog_buttons"> | ||
<input className="mx_Dialog_primary" | ||
type="submit" | ||
value="Continue" | ||
onClick={this.onSubmit} | ||
/> | ||
</div> | ||
</BaseDialog> | ||
); | ||
}, | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyright