Get as far as requesting a token

pull/1/head
David Baker 2015-07-14 19:39:18 +01:00
parent aacc31b2ce
commit 03d048c06f
4 changed files with 28 additions and 9 deletions

View File

@ -24,11 +24,13 @@ var matrixClient = null;
var localStorage = window.localStorage; var localStorage = window.localStorage;
if (localStorage) { if (localStorage) {
var hs_url = localStorage.getItem("mx_hs_url"); var hs_url = localStorage.getItem("mx_hs_url");
var is_url = localStorage.getItem("mx_is_url") || 'https://matrix.org';
var access_token = localStorage.getItem("mx_access_token"); var access_token = localStorage.getItem("mx_access_token");
var user_id = localStorage.getItem("mx_user_id"); var user_id = localStorage.getItem("mx_user_id");
if (access_token && user_id && hs_url) { if (access_token && user_id && hs_url) {
matrixClient = Matrix.createClient({ matrixClient = Matrix.createClient({
baseUrl: hs_url, baseUrl: hs_url,
idBaseUrl: is_url,
accessToken: access_token, accessToken: access_token,
userId: user_id userId: user_id
}); });
@ -44,8 +46,11 @@ module.exports = {
matrixClient = cli; matrixClient = cli;
}, },
replaceUsingUrl: function(hs_url) { replaceUsingUrls: function(hs_url, is_url) {
matrixClient = Matrix.createClient(hs_url); matrixClient = Matrix.createClient({
baseUrl: hs_url,
idBaseUrl: is_url
});
} }
}; };

View File

@ -30,7 +30,7 @@ module.exports = {
return { return {
onHsUrlChanged: function() {}, onHsUrlChanged: function() {},
onIsUrlChanged: function() {}, onIsUrlChanged: function() {},
default_hs_url: 'https://matrix.org/', default_hs_url: 'http://localhost:8008',
default_is_url: 'https://matrix.org/' default_is_url: 'https://matrix.org/'
}; };
}, },

View File

@ -42,8 +42,14 @@ module.exports = {
onHSChosen: function(ev) { onHSChosen: function(ev) {
ev.preventDefault(); ev.preventDefault();
MatrixClientPeg.replaceUsingUrl(this.refs.serverConfig.getHsUrl()); MatrixClientPeg.replaceUsingUrls(
this.setState({hs_url: this.refs.serverConfig.getHsUrl()}); this.refs.serverConfig.getHsUrl(),
this.refs.serverConfig.getIsUrl()
);
this.setState({
hs_url: this.refs.serverConfig.getHsUrl(),
is_url: this.refs.serverConfig.getIsUrl()
});
this.setStep("fetch_stages"); this.setStep("fetch_stages");
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
this.setState({busy: true}); this.setState({busy: true});
@ -72,12 +78,14 @@ module.exports = {
// XXX: we assume this means we're logged in, but there could be a next stage // XXX: we assume this means we're logged in, but there could be a next stage
MatrixClientPeg.replace(Matrix.createClient({ MatrixClientPeg.replace(Matrix.createClient({
baseUrl: that.state.hs_url, baseUrl: that.state.hs_url,
idBaseUrl: that.state.is_url,
userId: data.user_id, userId: data.user_id,
accessToken: data.access_token accessToken: data.access_token
})); }));
var localStorage = window.localStorage; var localStorage = window.localStorage;
if (localStorage) { if (localStorage) {
localStorage.setItem("mx_hs_url", that.state.hs_url); localStorage.setItem("mx_hs_url", that.state.hs_url);
localStorage.setItem("mx_is_url", that.state.is_url);
localStorage.setItem("mx_user_id", data.user_id); localStorage.setItem("mx_user_id", data.user_id);
localStorage.setItem("mx_access_token", data.access_token); localStorage.setItem("mx_access_token", data.access_token);
} else { } else {

View File

@ -87,7 +87,6 @@ module.exports = {
if (this.savedParams.email != '') { if (this.savedParams.email != '') {
return emailFlow; return emailFlow;
t
} else { } else {
return otherFlow; return otherFlow;
} }
@ -95,8 +94,14 @@ t
onInitialStageSubmit: function(ev) { onInitialStageSubmit: function(ev) {
ev.preventDefault(); ev.preventDefault();
MatrixClientPeg.replaceUsingUrl(this.refs.serverConfig.getHsUrl()); MatrixClientPeg.replaceUsingUrls(
this.setState({hs_url: this.refs.serverConfig.getHsUrl()}); this.refs.serverConfig.getHsUrl(),
this.refs.serverConfig.getIsUrl()
);
this.setState({
hs_url: this.refs.serverConfig.getHsUrl(),
is_url: this.refs.serverConfig.getIsUrl()
});
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
this.setState({busy: true}); this.setState({busy: true});
var self = this; var self = this;
@ -119,7 +124,7 @@ t
busy: true busy: true
}); });
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
this.savedParams.client_secret = cli.generarteClientSecret(); this.savedParams.client_secret = cli.generateClientSecret();
this.savedParams.send_attempt = 1; this.savedParams.send_attempt = 1;
cli.requestEmailToken( cli.requestEmailToken(
this.savedParams.email, this.savedParams.email,
@ -150,6 +155,7 @@ t
onRegistered: function(user_id, access_token) { onRegistered: function(user_id, access_token) {
MatrixClientPeg.replace(Matrix.createClient({ MatrixClientPeg.replace(Matrix.createClient({
baseUrl: this.state.hs_url, baseUrl: this.state.hs_url,
idBaseUrl: this.state.is_url,
userId: user_id, userId: user_id,
accessToken: access_token accessToken: access_token
})); }));