mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
Updated members sdks for third party use (#25)
* Pass container from layer2 for iframes to be attached * Updated layer2 to resolve with success for auth page methods * Updated theme dropin to reload when auth method succeeds
This commit is contained in:
parent
b990761136
commit
51be84182d
@ -3,12 +3,14 @@ var layer1 = require('@tryghost/members-layer1');
|
|||||||
module.exports = function layer2(options) {
|
module.exports = function layer2(options) {
|
||||||
var authUrl = `${options.membersUrl}/auth`;
|
var authUrl = `${options.membersUrl}/auth`;
|
||||||
var gatewayUrl = `${options.membersUrl}/gateway`;
|
var gatewayUrl = `${options.membersUrl}/gateway`;
|
||||||
|
var container = options.container;
|
||||||
|
|
||||||
var members = layer1({
|
var members = layer1({
|
||||||
gatewayUrl
|
gatewayUrl,
|
||||||
|
container
|
||||||
});
|
});
|
||||||
|
|
||||||
var loadAuth = loadFrame(authUrl).then(function (frame) {
|
var loadAuth = loadFrame(authUrl, container).then(function (frame) {
|
||||||
frame.style.position = 'fixed';
|
frame.style.position = 'fixed';
|
||||||
frame.style.width = '100%';
|
frame.style.width = '100%';
|
||||||
frame.style.height = '100%';
|
frame.style.height = '100%';
|
||||||
@ -27,43 +29,36 @@ module.exports = function layer2(options) {
|
|||||||
|
|
||||||
function openAuth(hash, query = '') {
|
function openAuth(hash, query = '') {
|
||||||
return loadAuth.then(function (frame) {
|
return loadAuth.then(function (frame) {
|
||||||
frame.src = `${authUrl}#${hash}?${query}`;
|
return new Promise(function (resolve) {
|
||||||
frame.style.display = 'block';
|
frame.src = `${authUrl}#${hash}?${query}`;
|
||||||
window.addEventListener('message', function self(event) {
|
frame.style.display = 'block';
|
||||||
if (event.source !== frame.contentWindow) {
|
window.addEventListener('message', function messageListener(event) {
|
||||||
return;
|
if (event.source !== frame.contentWindow) {
|
||||||
}
|
return;
|
||||||
if (event.data !== 'pls-close-auth-popup') {
|
}
|
||||||
return;
|
if (event.data !== 'pls-close-auth-popup') {
|
||||||
}
|
return;
|
||||||
window.removeEventListener('message', self);
|
}
|
||||||
frame.style.display = 'none';
|
window.removeEventListener('message', messageListener);
|
||||||
})
|
frame.style.display = 'none';
|
||||||
return frame;
|
resolve(false);
|
||||||
|
})
|
||||||
|
members.bus.on('signedin', function signedinListener() {
|
||||||
|
members.bus.off('signedin', signedinListener);
|
||||||
|
frame.style.display = 'none';
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetPassword({token}) {
|
function resetPassword({token}) {
|
||||||
const query = `token=${token}`;
|
const query = `token=${token}`;
|
||||||
return openAuth('reset-password', query).then(function () {
|
return openAuth('reset-password', query);
|
||||||
return new Promise(function (resolve) {
|
|
||||||
members.bus.on('signedin', function self() {
|
|
||||||
members.bus.off('signedin', self);
|
|
||||||
resolve(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function signin() {
|
function signin() {
|
||||||
return openAuth('signin').then(function () {
|
return openAuth('signin');
|
||||||
return new Promise(function (resolve) {
|
|
||||||
members.bus.on('signedin', function self() {
|
|
||||||
members.bus.off('signedin', self);
|
|
||||||
resolve(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToken({audience}) {
|
function getToken({audience}) {
|
||||||
|
@ -2,8 +2,10 @@ const DomReady = require('domready');
|
|||||||
const GhostContentApi = require('@tryghost/content-api');
|
const GhostContentApi = require('@tryghost/content-api');
|
||||||
const layer2 = require('@tryghost/members-layer2');
|
const layer2 = require('@tryghost/members-layer2');
|
||||||
|
|
||||||
function reload() {
|
function reload(success) {
|
||||||
window.location.reload();
|
if (success) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function show (el) {
|
function show (el) {
|
||||||
@ -24,8 +26,9 @@ DomReady(function () {
|
|||||||
const [tokenMatch, token] = query.match(/token=([a-zA-Z0-9-_]+.[a-zA-Z0-9-_]+.[a-zA-Z0-9-_]+)/) || [];
|
const [tokenMatch, token] = query.match(/token=([a-zA-Z0-9-_]+.[a-zA-Z0-9-_]+.[a-zA-Z0-9-_]+)/) || [];
|
||||||
if (tokenMatch) {
|
if (tokenMatch) {
|
||||||
return members.resetPassword({token})
|
return members.resetPassword({token})
|
||||||
.then(() => {
|
.then((success) => {
|
||||||
window.location.hash = '';
|
window.location.hash = '';
|
||||||
|
return success;
|
||||||
})
|
})
|
||||||
.then(reload);
|
.then(reload);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user