Get as far as requesting a token

This commit is contained in:
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;
if (localStorage) {
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 user_id = localStorage.getItem("mx_user_id");
if (access_token && user_id && hs_url) {
matrixClient = Matrix.createClient({
baseUrl: hs_url,
idBaseUrl: is_url,
accessToken: access_token,
userId: user_id
});
@ -44,8 +46,11 @@ module.exports = {
matrixClient = cli;
},
replaceUsingUrl: function(hs_url) {
matrixClient = Matrix.createClient(hs_url);
replaceUsingUrls: function(hs_url, is_url) {
matrixClient = Matrix.createClient({
baseUrl: hs_url,
idBaseUrl: is_url
});
}
};

View File

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

View File

@ -42,8 +42,14 @@ module.exports = {
onHSChosen: function(ev) {
ev.preventDefault();
MatrixClientPeg.replaceUsingUrl(this.refs.serverConfig.getHsUrl());
this.setState({hs_url: this.refs.serverConfig.getHsUrl()});
MatrixClientPeg.replaceUsingUrls(
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");
var cli = MatrixClientPeg.get();
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
MatrixClientPeg.replace(Matrix.createClient({
baseUrl: that.state.hs_url,
idBaseUrl: that.state.is_url,
userId: data.user_id,
accessToken: data.access_token
}));
var localStorage = window.localStorage;
if (localStorage) {
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_access_token", data.access_token);
} else {

View File

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