Improve registration so the container page can pick what URL it's going to route through to registration.
This commit is contained in:
parent
23d9cee299
commit
77114e0081
5 changed files with 66 additions and 35 deletions
|
@ -24,30 +24,52 @@ var React = require("react");
|
|||
// maps cannot pass through two stages).
|
||||
var MatrixReactSdk = require("../../src/index");
|
||||
|
||||
// Here, we do some crude URL analysis to allow
|
||||
// deep-linking. We only support registration
|
||||
// deep-links in this example.
|
||||
function routeUrl(location) {
|
||||
if (location.hash.indexOf('#/register') == 0) {
|
||||
var hashparts = location.hash.split('?');
|
||||
if (hashparts.length != 2) return;
|
||||
var pairs = hashparts[1].split('&');
|
||||
var params = {};
|
||||
for (var i = 0; i < pairs.length; ++i) {
|
||||
var parts = pairs[i].split('=');
|
||||
if (parts.length != 2) continue;
|
||||
params[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
|
||||
if (hashparts.length == 2) {
|
||||
var pairs = hashparts[1].split('&');
|
||||
for (var i = 0; i < pairs.length; ++i) {
|
||||
var parts = pairs[i].split('=');
|
||||
if (parts.length != 2) continue;
|
||||
params[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
|
||||
}
|
||||
}
|
||||
window.matrixChat.resumeRegistration(params);
|
||||
window.matrixChat.showScreen('register', params);
|
||||
}
|
||||
}
|
||||
|
||||
var loaded = false;
|
||||
|
||||
window.onload = function() {
|
||||
routeUrl(window.location);
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
// This will be called whenever the SDK changes screens,
|
||||
// so a web page can update the URL bar appropriately.
|
||||
var onNewScreen = function(screen) {
|
||||
if (!loaded) return;
|
||||
window.location.hash = '#/'+screen;
|
||||
}
|
||||
|
||||
// We use this to work out what URL the SDK should
|
||||
// pass through when registering to allow the user to
|
||||
// click back to the client having registered.
|
||||
// It's up to us to recognise if we're loaded with
|
||||
// this URL and tell MatrixClient to resume registration.
|
||||
var makeRegistrationUrl = function() {
|
||||
return window.location.protocol + '//' +
|
||||
window.location.host +
|
||||
window.location.pathname +
|
||||
'#/register';
|
||||
}
|
||||
|
||||
window.matrixChat = React.render(
|
||||
<MatrixReactSdk.MatrixChat onNewScreen={onNewScreen} />,
|
||||
<MatrixReactSdk.MatrixChat onNewScreen={onNewScreen} registrationUrl={makeRegistrationUrl()} />,
|
||||
document.getElementById('matrixchat')
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue