mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +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) {
|
||||
var authUrl = `${options.membersUrl}/auth`;
|
||||
var gatewayUrl = `${options.membersUrl}/gateway`;
|
||||
var container = options.container;
|
||||
|
||||
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.width = '100%';
|
||||
frame.style.height = '100%';
|
||||
@ -27,43 +29,36 @@ module.exports = function layer2(options) {
|
||||
|
||||
function openAuth(hash, query = '') {
|
||||
return loadAuth.then(function (frame) {
|
||||
frame.src = `${authUrl}#${hash}?${query}`;
|
||||
frame.style.display = 'block';
|
||||
window.addEventListener('message', function self(event) {
|
||||
if (event.source !== frame.contentWindow) {
|
||||
return;
|
||||
}
|
||||
if (event.data !== 'pls-close-auth-popup') {
|
||||
return;
|
||||
}
|
||||
window.removeEventListener('message', self);
|
||||
frame.style.display = 'none';
|
||||
})
|
||||
return frame;
|
||||
return new Promise(function (resolve) {
|
||||
frame.src = `${authUrl}#${hash}?${query}`;
|
||||
frame.style.display = 'block';
|
||||
window.addEventListener('message', function messageListener(event) {
|
||||
if (event.source !== frame.contentWindow) {
|
||||
return;
|
||||
}
|
||||
if (event.data !== 'pls-close-auth-popup') {
|
||||
return;
|
||||
}
|
||||
window.removeEventListener('message', messageListener);
|
||||
frame.style.display = 'none';
|
||||
resolve(false);
|
||||
})
|
||||
members.bus.on('signedin', function signedinListener() {
|
||||
members.bus.off('signedin', signedinListener);
|
||||
frame.style.display = 'none';
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function resetPassword({token}) {
|
||||
const query = `token=${token}`;
|
||||
return openAuth('reset-password', query).then(function () {
|
||||
return new Promise(function (resolve) {
|
||||
members.bus.on('signedin', function self() {
|
||||
members.bus.off('signedin', self);
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
return openAuth('reset-password', query);
|
||||
}
|
||||
|
||||
function signin() {
|
||||
return openAuth('signin').then(function () {
|
||||
return new Promise(function (resolve) {
|
||||
members.bus.on('signedin', function self() {
|
||||
members.bus.off('signedin', self);
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
return openAuth('signin');
|
||||
}
|
||||
|
||||
function getToken({audience}) {
|
||||
|
@ -2,8 +2,10 @@ const DomReady = require('domready');
|
||||
const GhostContentApi = require('@tryghost/content-api');
|
||||
const layer2 = require('@tryghost/members-layer2');
|
||||
|
||||
function reload() {
|
||||
window.location.reload();
|
||||
function reload(success) {
|
||||
if (success) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
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-_]+)/) || [];
|
||||
if (tokenMatch) {
|
||||
return members.resetPassword({token})
|
||||
.then(() => {
|
||||
.then((success) => {
|
||||
window.location.hash = '';
|
||||
return success;
|
||||
})
|
||||
.then(reload);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user