|
39 | 39 | </isif>
|
40 | 40 |
|
41 | 41 | <isif condition="${pdict.loadUISDK && pdict.reachFiveUiSdkUrl}">
|
42 |
| - <script src="${pdict.reachFiveUiSdkUrl}"></script> |
43 |
| - |
44 | 42 | <script>
|
| 43 | + function loadScript(url) { |
| 44 | + return new Promise(function(resolve, reject) { |
| 45 | + var script = document.createElement("script"); |
| 46 | + script.onload = resolve; |
| 47 | + script.onerror = reject; |
| 48 | + script.async = true; |
| 49 | + script.src = url; |
| 50 | + document.getElementsByTagName("head")[0].appendChild(script); |
| 51 | + }); |
| 52 | + } |
| 53 | + |
| 54 | + function loadSDKUI() { |
| 55 | + if (window.sdkUiClient) { |
| 56 | + // already loaded and ready to go |
| 57 | + return Promise.resolve(); |
| 58 | + } else { |
| 59 | + return loadScript('${pdict.reachFiveUiSdkUrl}'); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + loadSDKUI().then(function() { |
45 | 64 | window.sdkUiClient = reach5Widgets.createClient({
|
46 | 65 | // Required parameters
|
47 | 66 | domain: '${pdict.reachFiveDomain}',
|
|
50 | 69 | language: '${pdict.reachFiveLanguageCode}' || 'en',
|
51 | 70 | locale: '${pdict.reachFivelocaleCode}'
|
52 | 71 | });
|
53 |
| - </script> |
54 | 72 |
|
55 |
| - <script> |
56 | 73 | let allowForgotPassword = ${!pdict.isTransitionActive};
|
57 | 74 | let redirectUri = '${pdict.callbackUrl}';
|
58 | 75 | let origin ='${pdict.siteID}';
|
|
88 | 105 | if (document.getElementById("reset-password")) {
|
89 | 106 | <isprint value="${dw.system.Site.getCurrent().getCustomPreferenceValue('reset-password')}" encoding="off">
|
90 | 107 | }
|
91 |
| - </script> |
92 | 108 |
|
93 |
| - <isif condition="${!empty(pdict.reachFiveAccess_token)}"> |
94 |
| - <script> |
| 109 | + <isif condition="${!empty(pdict.reachFiveAccess_token)}"> |
95 | 110 | if(document.getElementById("password-editor")) {
|
96 | 111 | console.log('password-editor');
|
97 | 112 | <isprint value="${dw.system.Site.getCurrent().getCustomPreferenceValue('password-editor')}" encoding="off">
|
98 | 113 | }
|
99 | 114 |
|
100 |
| - // if(document.getElementById("profile-editor")) { |
101 |
| - // sdkUiClient.showProfileEditor({ |
102 |
| - // container: 'profile-editor', |
103 |
| - // accessToken: '${pdict.reachFiveAccess_token}', |
104 |
| - // fields: [ |
105 |
| - // 'given_name', |
106 |
| - // 'family_name', |
107 |
| - // 'birthdate', |
108 |
| - // 'consents.newsletter' |
109 |
| - // ], |
110 |
| - // onSuccess: function() { |
111 |
| - // var el = document.getElementsByTagName('body'); |
112 |
| - // var event = new CustomEvent('reachfive-profile-update', { |
113 |
| - // bubbles: true, |
114 |
| - // detail: { |
115 |
| - // source: 'profileEditor', |
116 |
| - // updateUrl: decodeURIComponent('${dw.crypto.Encoding.toURI(pdict.updateProfileUrl)}') |
117 |
| - // } |
118 |
| - // }); |
119 |
| - // el[0].dispatchEvent(event); |
120 |
| - // } |
121 |
| - // }); |
122 |
| - // } |
123 |
| - |
124 | 115 | if(document.getElementById("email-editor")) {
|
125 | 116 | <isprint value="${dw.system.Site.getCurrent().getCustomPreferenceValue('email-editor')}" encoding="off">
|
126 | 117 | }
|
|
133 | 124 | if (socialAccountsContainer) {
|
134 | 125 | <isprint value="${dw.system.Site.getCurrent().getCustomPreferenceValue('social-accounts-container')}" encoding="off">
|
135 | 126 | }
|
136 |
| - |
137 |
| - </script> |
138 |
| - |
139 |
| - <iscomment> |
140 |
| - TODO: This functionality related to "imlicid flow" |
141 |
| - and it is normally disabled becasue of security issues |
142 |
| - <script type="text/javascript"> |
143 |
| - var reAuthContainer = document.getElementById("re-auth-container"); |
144 |
| - var socialAccountsContainer = document.getElementById("social-accounts-container"); |
145 |
| - |
146 |
| - if(reAuthContainer && socialAccountsContainer) { |
147 |
| - var idToken = null; |
148 |
| - |
149 |
| - try{ |
150 |
| - idToken = '${pdict.CurrentSession.privacy.id_token}'; |
151 |
| - } catch(err) { |
152 |
| - console.log(err) |
153 |
| - } |
154 |
| - |
155 |
| - console.log('social-accounts-container'); |
156 |
| - <isprint value="${dw.system.Site.getCurrent().getCustomPreferenceValue('re-auth-container')}" encoding="off"> |
157 |
| - |
158 |
| - sdkCoreClient.on('authenticated', function(authResult) { |
159 |
| - let accessToken = authResult.accessToken; |
160 |
| - <isprint value="${dw.system.Site.getCurrent().getCustomPreferenceValue('authenticated')}" encoding="off"> |
161 |
| - }); |
162 |
| - } |
163 |
| - </script> |
164 |
| - </iscomment> |
165 |
| - </isif> |
| 127 | + </isif> |
| 128 | + }, function(e) { |
| 129 | + throw new Error('Unable to load ReachFive SDK Core Client'); |
| 130 | + }); |
| 131 | + </script> |
166 | 132 | </isif>
|
167 | 133 | </isif>
|
0 commit comments