You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/02/05 10:28:57 UTC
[ofbiz-framework] 02/02: Fixed: setUserTimeZone should ran only
once based on error (OFBIZ-11329)
This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch release17.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 6ce10278a391a5c588d7a97f6e779c4e4256f5d2
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Wed Feb 5 09:30:55 2020 +0100
Fixed: setUserTimeZone should ran only once based on error
(OFBIZ-11329)
This will be notably useful when committing CSRF solution as explained in
OFBIZ-11306:
SetTimeZoneFromBrowser when starting gives a RequestHandlerException:
Invalid or missing CSRF token for AJAX call to path '/SetTimeZoneFromBrowser'.
Also not only when starting.
Thanks: James Yong for review
(cherry picked from commit 350c71f4df45cbe5671b54e61f74f9a352d78e05)
# Conflicts:
# framework/common/groovyScripts/SetLocaleFromBrowser.groovy
# themes/common-theme/webapp/common/js/util/setUserTimeZone.js replaced
by setUserLocale.js modified by hand
I can compile locally but I can see a reason why and certainly not related to
these changes
---
.../groovyScripts/SetLocaleFromBrowser.groovy | 5 +++--
.../common/webapp/common/js/util/setUserLocale.js | 25 ++++++++++++----------
2 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/framework/common/groovyScripts/SetLocaleFromBrowser.groovy b/framework/common/groovyScripts/SetLocaleFromBrowser.groovy
index 9e00511..690d06b 100644
--- a/framework/common/groovyScripts/SetLocaleFromBrowser.groovy
+++ b/framework/common/groovyScripts/SetLocaleFromBrowser.groovy
@@ -20,13 +20,14 @@
import org.apache.ofbiz.service.ServiceUtil
public Map setLocaleFromBrowser() {
- Map results = ServiceUtil.returnSuccess()
userLogin = from("UserLogin").where("userLoginId", parameters.userLogin.userLoginId).queryFirst();
if (userLogin) {
if (!userLogin.lastTimeZone || "null".equals(userLogin.lastTimeZone)) {
userLogin.lastTimeZone = parameters.localeName
userLogin.store()
+ return ServiceUtil.returnSuccess()
}
+ } else {
+ return ServiceUtil.returnError()
}
- return results
}
diff --git a/themes/common/webapp/common/js/util/setUserLocale.js b/themes/common/webapp/common/js/util/setUserLocale.js
index 4d0676c..0f32dba 100644
--- a/themes/common/webapp/common/js/util/setUserLocale.js
+++ b/themes/common/webapp/common/js/util/setUserLocale.js
@@ -17,15 +17,18 @@ specific language governing permissions and limitations
under the License.
*/
-var timezone = moment.tz.guess();
-$.ajax({
- url: "setLocaleFromBrowser",
- type: "POST",
- async: false,
- data: "localeName=" + timezone,
- error: function(error) {
- if (error != "") {
- console.error("Error while setting user locale: ", error);
+// Only once by session (ref https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)
+if (sessionStorage.getItem("setLocaleFromBrowser") === null || sessionStorage.getItem("setLocaleFromBrowser") !== "done") {
+ var timezone = moment.tz.guess();
+ $.ajax({
+ url: "setLocaleFromBrowser",
+ type: "POST",
+ async: false,
+ data: "localeName=" + timezone,
+ success: function(success) {
+ if (success._ERROR_MESSAGE_ === undefined && success._ERROR_MESSAGE_LIST_ === undefined) {
+ sessionStorage.setItem("setLocaleFromBrowser", "done");
+ }
}
- }
-});
+ });
+}