Merge remote-tracking branch 'origin/develop' into dbkr/register_ui_auth
(This ended up mostly being merged by hand as git made a complete mess of the merge)
This commit is contained in:
commit
dd33624454
4 changed files with 86 additions and 70 deletions
|
@ -277,6 +277,9 @@ export function setLoggedIn(credentials) {
|
||||||
credentials.userId, credentials.guest,
|
credentials.userId, credentials.guest,
|
||||||
credentials.homeserverUrl);
|
credentials.homeserverUrl);
|
||||||
|
|
||||||
|
// Resolves by default
|
||||||
|
let teamPromise = Promise.resolve(null);
|
||||||
|
|
||||||
// persist the session
|
// persist the session
|
||||||
if (localStorage) {
|
if (localStorage) {
|
||||||
try {
|
try {
|
||||||
|
@ -300,16 +303,12 @@ export function setLoggedIn(credentials) {
|
||||||
console.warn("Error using local storage: can't persist session!", e);
|
console.warn("Error using local storage: can't persist session!", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtsClient) {
|
if (rtsClient && !credentials.guest) {
|
||||||
rtsClient.login(credentials.userId).then((body) => {
|
teamPromise = rtsClient.login(credentials.userId).then((body) => {
|
||||||
if (body.team_token) {
|
if (body.team_token) {
|
||||||
localStorage.setItem("mx_team_token", body.team_token);
|
localStorage.setItem("mx_team_token", body.team_token);
|
||||||
}
|
}
|
||||||
}, (err) =>{
|
return body.team_token;
|
||||||
console.error(
|
|
||||||
"Failed to get team token on login, not persisting to localStorage",
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -321,7 +320,12 @@ export function setLoggedIn(credentials) {
|
||||||
|
|
||||||
MatrixClientPeg.replaceUsingCreds(credentials);
|
MatrixClientPeg.replaceUsingCreds(credentials);
|
||||||
|
|
||||||
dis.dispatch({action: 'on_logged_in'});
|
teamPromise.then((teamToken) => {
|
||||||
|
dis.dispatch({action: 'on_logged_in', teamToken: teamToken});
|
||||||
|
}, (err) => {
|
||||||
|
console.warn("Failed to get team token on login", err);
|
||||||
|
dis.dispatch({action: 'on_logged_in', teamToken: null});
|
||||||
|
});
|
||||||
|
|
||||||
startMatrixClient();
|
startMatrixClient();
|
||||||
}
|
}
|
||||||
|
|
|
@ -524,7 +524,7 @@ module.exports = React.createClass({
|
||||||
this._onSetTheme(payload.value);
|
this._onSetTheme(payload.value);
|
||||||
break;
|
break;
|
||||||
case 'on_logged_in':
|
case 'on_logged_in':
|
||||||
this._onLoggedIn();
|
this._onLoggedIn(payload.teamToken);
|
||||||
break;
|
break;
|
||||||
case 'on_logged_out':
|
case 'on_logged_out':
|
||||||
this._onLoggedOut();
|
this._onLoggedOut();
|
||||||
|
@ -700,13 +700,20 @@ module.exports = React.createClass({
|
||||||
/**
|
/**
|
||||||
* Called when a new logged in session has started
|
* Called when a new logged in session has started
|
||||||
*/
|
*/
|
||||||
_onLoggedIn: function(credentials) {
|
_onLoggedIn: function(teamToken) {
|
||||||
this.guestCreds = null;
|
this.guestCreds = null;
|
||||||
this.notifyNewScreen('');
|
this.notifyNewScreen('');
|
||||||
this.setState({
|
this.setState({
|
||||||
screen: undefined,
|
screen: undefined,
|
||||||
logged_in: true,
|
logged_in: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (teamToken) {
|
||||||
|
this._teamToken = teamToken;
|
||||||
|
this._setPage(PageTypes.HomePage);
|
||||||
|
} else if (this._is_registered) {
|
||||||
|
this._setPage(PageTypes.UserSettings);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -723,6 +730,7 @@ module.exports = React.createClass({
|
||||||
currentRoomId: null,
|
currentRoomId: null,
|
||||||
page_type: PageTypes.RoomDirectory,
|
page_type: PageTypes.RoomDirectory,
|
||||||
});
|
});
|
||||||
|
this._teamToken = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -993,23 +1001,11 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onRegistered: function(credentials) {
|
onRegistered: function(credentials, teamToken) {
|
||||||
Lifecycle.setLoggedIn(credentials);
|
// teamToken may not be truthy
|
||||||
// do post-registration stuff
|
|
||||||
// This now goes straight to user settings
|
|
||||||
// We use _setPage since if we wait for
|
|
||||||
// showScreen to do the dispatch loop,
|
|
||||||
// the showScreen dispatch will race with the
|
|
||||||
// sdk sync finishing and we'll probably see
|
|
||||||
// the page type still unset when the MatrixClient
|
|
||||||
// is started and show the Room Directory instead.
|
|
||||||
//this.showScreen("view_user_settings");
|
|
||||||
this._setPage(PageTypes.UserSettings);
|
|
||||||
},
|
|
||||||
|
|
||||||
onTeamMemberRegistered: function(teamToken) {
|
|
||||||
this._teamToken = teamToken;
|
this._teamToken = teamToken;
|
||||||
this._setPage(PageTypes.HomePage);
|
this._is_registered = true;
|
||||||
|
Lifecycle.setLoggedIn(credentials);
|
||||||
},
|
},
|
||||||
|
|
||||||
onFinishPostRegistration: function() {
|
onFinishPostRegistration: function() {
|
||||||
|
@ -1146,7 +1142,6 @@ module.exports = React.createClass({
|
||||||
customIsUrl={this.getCurrentIsUrl()}
|
customIsUrl={this.getCurrentIsUrl()}
|
||||||
makeRegistrationUrl={this.props.makeRegistrationUrl}
|
makeRegistrationUrl={this.props.makeRegistrationUrl}
|
||||||
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
|
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
|
||||||
onTeamMemberRegistered={this.onTeamMemberRegistered}
|
|
||||||
onLoggedIn={this.onRegistered}
|
onLoggedIn={this.onRegistered}
|
||||||
onLoginClick={this.onLoginClick}
|
onLoginClick={this.onLoginClick}
|
||||||
onRegisterClick={this.onRegisterClick}
|
onRegisterClick={this.onRegisterClick}
|
||||||
|
|
|
@ -17,15 +17,19 @@ limitations under the License.
|
||||||
|
|
||||||
import Matrix from 'matrix-js-sdk';
|
import Matrix from 'matrix-js-sdk';
|
||||||
|
|
||||||
var React = require('react');
|
import q from 'q';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
var sdk = require('../../../index');
|
import sdk from '../../../index';
|
||||||
var MatrixClientPeg = require("../../../MatrixClientPeg");
|
import dis from '../../../dispatcher';
|
||||||
var RegistrationForm = require("../../views/login/RegistrationForm");
|
import Signup from '../../../Signup';
|
||||||
var CaptchaForm = require("../../views/login/CaptchaForm");
|
import ServerConfig from '../../views/login/ServerConfig';
|
||||||
var RtsClient = require("../../../RtsClient");
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
|
import RegistrationForm from '../../views/login/RegistrationForm';
|
||||||
|
import CaptchaForm from '../../views/login/CaptchaForm';
|
||||||
|
import RtsClient from '../../../RtsClient';
|
||||||
|
|
||||||
var MIN_PASSWORD_LENGTH = 6;
|
const MIN_PASSWORD_LENGTH = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: It would be nice to make use of the InteractiveAuthEntryComponents
|
* TODO: It would be nice to make use of the InteractiveAuthEntryComponents
|
||||||
|
@ -56,7 +60,6 @@ module.exports = React.createClass({
|
||||||
teamServerURL: React.PropTypes.string.isRequired,
|
teamServerURL: React.PropTypes.string.isRequired,
|
||||||
}),
|
}),
|
||||||
teamSelected: React.PropTypes.object,
|
teamSelected: React.PropTypes.object,
|
||||||
onTeamMemberRegistered: React.PropTypes.func.isRequired,
|
|
||||||
|
|
||||||
defaultDeviceDisplayName: React.PropTypes.string,
|
defaultDeviceDisplayName: React.PropTypes.string,
|
||||||
|
|
||||||
|
@ -182,20 +185,20 @@ module.exports = React.createClass({
|
||||||
// will just nop. The point of this being we might not have the email address
|
// will just nop. The point of this being we might not have the email address
|
||||||
// that the user registered with at this stage (depending on whether this
|
// that the user registered with at this stage (depending on whether this
|
||||||
// is the client they initiated registration).
|
// is the client they initiated registration).
|
||||||
if (self._rtsClient) {
|
if (this._rtsClient) {
|
||||||
// Track referral if self.props.referrer set, get team_token in order to
|
// Track referral if this.props.referrer set, get team_token in order to
|
||||||
// retrieve team config and see welcome page etc.
|
// retrieve team config and see welcome page etc.
|
||||||
self._rtsClient.trackReferral(
|
this._rtsClient.trackReferral(
|
||||||
self.props.referrer || '', // Default to empty string = not referred
|
this.props.referrer || '', // Default to empty string = not referred
|
||||||
self.registerLogic.params.idSid,
|
this.registerLogic.params.idSid,
|
||||||
self.registerLogic.params.clientSecret
|
this.registerLogic.params.clientSecret
|
||||||
).then((data) => {
|
).then((data) => {
|
||||||
const teamToken = data.team_token;
|
const teamToken = data.team_token;
|
||||||
// Store for use /w welcome pages
|
// Store for use /w welcome pages
|
||||||
window.localStorage.setItem('mx_team_token', teamToken);
|
window.localStorage.setItem('mx_team_token', teamToken);
|
||||||
self.props.onTeamMemberRegistered(teamToken);
|
this.props.onTeamMemberRegistered(teamToken);
|
||||||
|
|
||||||
self._rtsClient.getTeam(teamToken).then((team) => {
|
this._rtsClient.getTeam(teamToken).then((team) => {
|
||||||
console.log(
|
console.log(
|
||||||
`User successfully registered with team ${team.name}`
|
`User successfully registered with team ${team.name}`
|
||||||
);
|
);
|
||||||
|
@ -209,6 +212,8 @@ module.exports = React.createClass({
|
||||||
MatrixClientPeg.get().joinRoom(room.room_id);
|
MatrixClientPeg.get().joinRoom(room.room_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return teamToken;
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.error('Error getting team config', err);
|
console.error('Error getting team config', err);
|
||||||
});
|
});
|
||||||
|
@ -217,16 +222,32 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set approipriate branding on the email pusher
|
trackPromise.then((teamToken) => {
|
||||||
if (self.props.brand) {
|
console.info('Team token promise',teamToken);
|
||||||
MatrixClientPeg.get().getPushers().done((resp)=>{
|
this.props.onLoggedIn({
|
||||||
var pushers = resp.pushers;
|
userId: response.user_id,
|
||||||
for (var i = 0; i < pushers.length; ++i) {
|
deviceId: response.device_id,
|
||||||
|
homeserverUrl: this.registerLogic.getHomeserverUrl(),
|
||||||
|
identityServerUrl: this.registerLogic.getIdentityServerUrl(),
|
||||||
|
accessToken: response.access_token
|
||||||
|
}, teamToken);
|
||||||
|
}).then(() => {
|
||||||
|
return this._setupPushers();
|
||||||
|
}.done());
|
||||||
|
},
|
||||||
|
|
||||||
|
_setupPushers: function() {
|
||||||
|
if (!this.props.brand) {
|
||||||
|
return q();
|
||||||
|
}
|
||||||
|
return MatrixClientPeg.get().getPushers().then((resp)=>{
|
||||||
|
const pushers = resp.pushers;
|
||||||
|
for (let i = 0; i < pushers.length; ++i) {
|
||||||
if (pushers[i].kind == 'email') {
|
if (pushers[i].kind == 'email') {
|
||||||
var emailPusher = pushers[i];
|
const emailPusher = pushers[i];
|
||||||
emailPusher.data = { brand: self.props.brand };
|
emailPusher.data = { brand: this.props.brand };
|
||||||
MatrixClientPeg.get().setPusher(emailPusher).done(() => {
|
MatrixClientPeg.get().setPusher(emailPusher).done(() => {
|
||||||
console.log("Set email branding to " + self.props.brand);
|
console.log("Set email branding to " + this.props.brand);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
console.error("Couldn't set email branding: " + error);
|
console.error("Couldn't set email branding: " + error);
|
||||||
});
|
});
|
||||||
|
@ -235,7 +256,6 @@ module.exports = React.createClass({
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
console.error("Couldn't get pushers: " + error);
|
console.error("Couldn't get pushers: " + error);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onFormValidationFailed: function(errCode) {
|
onFormValidationFailed: function(errCode) {
|
||||||
|
|
|
@ -318,8 +318,12 @@ module.exports = WithMatrixClient(React.createClass({
|
||||||
this.props.readReceiptMap[userId] = readReceiptInfo;
|
this.props.readReceiptMap[userId] = readReceiptInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: we keep the extra read avatars in the dom to make animation simpler
|
||||||
|
// we could optimise this to reduce the dom size.
|
||||||
|
if (!hidden) {
|
||||||
|
left -= 15;
|
||||||
|
}
|
||||||
|
|
||||||
//console.log("i = " + i + ", MAX_READ_AVATARS = " + MAX_READ_AVATARS + ", allReadAvatars = " + this.state.allReadAvatars + " visibility = " + style.visibility);
|
|
||||||
// add to the start so the most recent is on the end (ie. ends up rightmost)
|
// add to the start so the most recent is on the end (ie. ends up rightmost)
|
||||||
avatars.unshift(
|
avatars.unshift(
|
||||||
<ReadReceiptMarker key={userId} member={receipt.roomMember}
|
<ReadReceiptMarker key={userId} member={receipt.roomMember}
|
||||||
|
@ -332,12 +336,6 @@ module.exports = WithMatrixClient(React.createClass({
|
||||||
showFullTimestamp={receipt.ts >= dayAfterEventTime}
|
showFullTimestamp={receipt.ts >= dayAfterEventTime}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: we keep the extra read avatars in the dom to make animation simpler
|
|
||||||
// we could optimise this to reduce the dom size.
|
|
||||||
if (!hidden) {
|
|
||||||
left -= 15;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var remText;
|
var remText;
|
||||||
if (!this.state.allReadAvatars) {
|
if (!this.state.allReadAvatars) {
|
||||||
|
@ -345,9 +343,8 @@ module.exports = WithMatrixClient(React.createClass({
|
||||||
if (remainder > 0) {
|
if (remainder > 0) {
|
||||||
remText = <span className="mx_EventTile_readAvatarRemainder"
|
remText = <span className="mx_EventTile_readAvatarRemainder"
|
||||||
onClick={this.toggleAllReadAvatars}
|
onClick={this.toggleAllReadAvatars}
|
||||||
style={{ left: left }}>{ remainder }+
|
style={{ right: -(left - 15) }}>{ remainder }+
|
||||||
</span>;
|
</span>;
|
||||||
left -= 15;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue