Skip to content

Commit

Permalink
Merge pull request #65 from gigya/develop
Browse files Browse the repository at this point in the history
v 5.3.5
  • Loading branch information
Ynhockey authored Jun 5, 2019
2 parents 2216ba9 + 046fa29 commit f6502bb
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 106 deletions.
6 changes: 1 addition & 5 deletions view/frontend/layout/customer_account_create.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Gigya\GigyaIM\Block\Form\GigyaRegister" name="gigya_customer_form_register" template="Gigya_GigyaIM::gigya_register.phtml" ifconfig="gigya_section/general/enable_gigya">
<!-- Verify that the block can be used as layout element in other places -->
<container name="form.additional.info" as="form_additional_info" />
<container name="customer.form.register.fields.before" as="form_fields_before" label="Form Fields Before" htmlTag="div" htmlClass="customer-form-before" />
</block>
<block class="Gigya\GigyaIM\Block\Form\GigyaRegister" name="gigya_customer_form_register" template="Gigya_GigyaIM::gigya_register.phtml" ifconfig="gigya_section/general/enable_gigya" />
</referenceContainer>
</body>
</page>
7 changes: 5 additions & 2 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var config = {
map: {
'*': {
gigya_script : 'Gigya_GigyaIM/js/gigya_script',
'Magento_Customer/js/model/authentication-popup' : 'Gigya_GigyaIM/js/model/authentication-popup'
'Magento_Customer/js/model/authentication-popup' : 'Gigya_GigyaIM/js/model/authentication-popup',
gigya_script : 'Gigya_GigyaIM/js/gigya_script'
}
},
shim: {
Expand All @@ -15,6 +15,9 @@ var config = {
'Magento_Customer/js/view/authentication-popup': {
'Gigya_GigyaIM/js/view/authentication-popup': true
},
'Magento_Customer/js/customer-data': {
'Gigya_GigyaIM/js/customer-data': true
},
'Magento_Checkout/js/view/authentication': {
'Gigya_GigyaIM/js/view/authentication': true
},
Expand Down
1 change: 1 addition & 0 deletions view/frontend/templates/gigya_script.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $scriptDomain = $this->helper('Gigya\GigyaIM\Helper\GigyaScriptHelper')->getGigy
var magento_user_logged_in = false;
var enable_login = true;
var gigya_enabled = <?php echo $block->isGigyaEnabled() ? 'true' : 'false'; ?>;
var gigya_login_in_progress = false;

var m;
</script>
Expand Down
16 changes: 16 additions & 0 deletions view/frontend/web/js/customer-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
define(function () {
'use strict';

return function (Component) {
Component.reloadOriginal = Component.reload;
Component.reload = function (sectionNames, updateSectionId) {
if (typeof gigya_enabled !== "undefined" && gigya_enabled && gigya_login_in_progress == true) {
return;
}

return this.reloadOriginal(sectionNames, updateSectionId);
}

return Component;
}
});
201 changes: 111 additions & 90 deletions view/frontend/web/js/gigya_script.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
define([
'jquery',
'Magento_Ui/js/modal/modal',
'Magento_Customer/js/customer-data'
], function($, modal, customerData){
"use strict";
var gigyaMage2 = {
Params : {},
Functions : {}
};

/**
* Load Gigya script
* Sync gigya-magento sessions
* Event handlers (login, update)
*/
gigyaMage2.Params.gigya_user_logged_in = false; // checked by methods: getAccountInfo & checkLoginStatus
gigyaMage2.Params.form_key = null;
var formKeyObj = $('input[name="form_key"]');
if ( formKeyObj.val().length ){
gigyaMage2.Params.form_key = formKeyObj.val();
}

gigyaMage2.Functions.loadGigyaScript = function(api_key, language, domain) {
if (!domain) {
domain = 'gigya.com';
}

var gig = document.createElement('script');
gig.type = 'text/javascript';
gig.async = false;
gig.src = 'https://cdns.' + domain +
'/js/gigya.js?apiKey=' + api_key + '&lang=' + language;
var gig_loaded = function () {
gigya.accounts.addEventHandlers(
{
onLogin: gigyaMage2.Functions.gigyaLoginEventHandler,
onLogout: gigyaMage2.Functions.gigyaLogoutEventHandler
}
);
};
gig.onreadystatechange = function () {
if (this.readyState === 'complete') gig_loaded();
};
gig.onload = gig_loaded;

document.getElementsByTagName('head')[0].appendChild(gig);

window.gigyaCMS = {authenticated: false};
};
'jquery',
'Magento_Ui/js/modal/modal',
'Magento_Customer/js/customer-data'
], function ($, modal, customerData) {
"use strict";
var gigyaMage2 = {
Params: {},
Functions: {}
};

/**
* Load Gigya script
* Sync gigya-magento sessions
* Event handlers (login, update)
*/
gigyaMage2.Params.gigya_user_logged_in = false; // checked by methods: getAccountInfo & checkLoginStatus
gigyaMage2.Params.form_key = null;
var formKeyObj = $('input[name="form_key"]');
if (formKeyObj.val().length) {
gigyaMage2.Params.form_key = formKeyObj.val();
}

gigyaMage2.Functions.loadGigyaScript = function (api_key, language, domain) {
if (!domain) {
domain = 'gigya.com';
}

var gig = document.createElement('script');
gig.type = 'text/javascript';
gig.async = false;
gig.src = 'https://cdns.' + domain +
'/js/gigya.js?apiKey=' + api_key + '&lang=' + language;
var gig_loaded = function () {
gigya.accounts.addEventHandlers(
{
onLogin: gigyaMage2.Functions.gigyaLoginEventHandler,
onLogout: gigyaMage2.Functions.gigyaLogoutEventHandler
}
);
};
gig.onreadystatechange = function () {
if (this.readyState === 'complete') gig_loaded();
};
gig.onload = gig_loaded;

document.getElementsByTagName('head')[0].appendChild(gig);

window.gigyaCMS = {authenticated: false};
};

/**
* sync Magento-Gigya sessions logic
Expand Down Expand Up @@ -115,15 +115,18 @@ define([
UID: eventObj.UID
};

if (typeof eventObj.expires_in !== 'undefined') {
loginData.expiresIn = eventObj.expires_in;
}
if (typeof eventObj.expires_in !== 'undefined') {
loginData.expiresIn = eventObj.expires_in;
}

var data = {
form_key: gigyaMage2.Params.form_key,
"login[]": "",
login_data: JSON.stringify(loginData)
};

gigya_login_in_progress = true;

gigyaMage2.Functions.gigyaAjaxSubmit(action, data, $('.gigya-loader-location'));
};

Expand Down Expand Up @@ -152,7 +155,7 @@ define([
showLoader: true,
context: loader_context,
data: data,
dataType: 'json'
dataType: 'json'
}).done(function (dataObj) {
if ((typeof dataObj.location !== 'undefined') && (typeof sendSetSSOToken !== 'undefined') && (sendSetSSOToken)) {
gigya.accounts.setSSOToken({redirectURL: dataObj.location});
Expand All @@ -166,50 +169,68 @@ define([
});
};

gigyaMage2.Functions.loginEncode = function(data)
{
return window.btoa(decodeURIComponent(encodeURIComponent( data )));
};
gigyaMage2.Functions.loginEncode = function (data) {
return window.btoa(decodeURIComponent(encodeURIComponent(data)));
};

gigyaMage2.Functions.gigyaLogoutEventHandler = function() {
gigyaMage2.Functions.logoutMagento();
};
gigyaMage2.Functions.gigyaLogoutEventHandler = function () {
gigyaMage2.Functions.logoutMagento();
};

gigyaMage2.Functions.performGigyaActions = function() {
if (window.gigyaInit) {
gigyaMage2.Functions.waitForElementToDisplay = function(selector, callable, params, time, ttl) {
if ($(selector).length < 1 && ttl > 0) {
setTimeout(function () {
gigyaMage2.Functions.waitForElementToDisplay(selector, callable, params, time, ttl - time);
}, time);
} else {
callable(params);
return;
}
};

// If this is the edit profile page, then add the update profile callback function.
gigyaMage2.Functions.performGigyaActions = function () {
if (window.gigyaInit) {

/* If this is the edit profile page, then add the update profile callback function */
if (window.gigyaInit[0]) {
if (window.gigyaInit[0].parameters.containerID === "gigya-edit-profile") {
window.gigyaInit[0].parameters.onAfterSubmit = gigyaMage2.Functions.gigyaAjaxUpdateProfile;
}
}

var length = window.gigyaInit.length,
element = null;
if (length > 0) {
for (var i = 0; i < length; i++) {
element = window.gigyaInit[i];
var func = element.function;
var parts = func.split("\.");
var f = gigya[parts[0]][parts[1]];
if (typeof f === "function") {
f(element.parameters);
}
}
}
window.gigyaInit = [];
}
};

/**
* Things to do when gigya script finishes loading
* init registered Gigya functions (e.g. showScreenSet from layout files)
* register event listeners
* @param serviceName
*/
window.onGigyaServiceReady = function (serviceName) {
gigyaMage2.Functions.performGigyaActions();
};
return gigyaMage2;
var length = window.gigyaInit.length,
element = null;
if (length > 0) {
for (var i = 0; i < length; i++) {
element = window.gigyaInit[i];
var func = element.function;
var parts = func.split("\.");
var f = gigya[parts[0]][parts[1]];

if (typeof f === "function") {
/* showScreenSet should always wait for the container DOM element. It usually loads on time, but not always. */
if (func === 'accounts.showScreenSet' && typeof element.parameters.containerID !== 'undefined') {
var containerIdSelector = '#' + element.parameters.containerID;
gigyaMage2.Functions.waitForElementToDisplay(containerIdSelector, f, element.parameters, 200, 5000);
}
else {
f(element.parameters);
}
}
}
}
window.gigyaInit = [];
}
};

/**
* Things to do when gigya script finishes loading
* init registered Gigya functions (e.g. showScreenSet from layout files)
* register event listeners
* @param serviceName
*/
window.onGigyaServiceReady = function (serviceName) {
gigyaMage2.Functions.performGigyaActions();
};
return gigyaMage2;
});
8 changes: 4 additions & 4 deletions view/frontend/web/js/view/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ define([], function () {
initConfig: function () {
this._super();

if (typeof gigya_enabled != "undefined" && gigya_enabled == true) {
if (typeof gigya_enabled !== "undefined" && gigya_enabled) {
this.template = 'Gigya_GigyaIM/authentication';
}

return this;
},

loadGigyaForm: function() {
if (typeof gigya != "undefined") {
if (typeof gigya !== "undefined") {
console.log('loadGigyaForm .. load');
window.gigyaInit.push(popupRaasLoginScreen);
requirejs('gigya_script').Functions.performGigyaActions();
}
},

login: function() {
if (typeof gigya_enabled != "undefined" && gigya_enabled == true) {
if (typeof gigya_enabled !== "undefined" && gigya_enabled) {
this.switchToScreen('gigya-login-screen');
}
},
Expand All @@ -37,7 +37,7 @@ define([], function () {
}
});

if (typeof gigya != "undefined") {
if (typeof gigya !== "undefined") {
requirejs('gigya_script').Functions.performGigyaActions();
}
}
Expand Down
9 changes: 4 additions & 5 deletions view/frontend/web/template/authentication-popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
-->

<div class="block-authentication"
data-bind="afterRender: setModalElement, blockLoader: isLoading"
style="display: none">
data-bind="afterRender: setModalElement, blockLoader: isLoading"
style="display: none">


<div id="gigya-login-popup" width="80%" class="gigya-login gigya-loader-location"></div>
</div>
<div id="gigya-login-popup" style="width: 80%" class="gigya-login gigya-loader-location"></div>
</div>

0 comments on commit f6502bb

Please sign in to comment.