james-yong opened a new pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266 Improved: Display last-visited-time popup after login (OFBIZ-12148) Popup last-visited time from database after user has logged in. So users can know of any unauthorised access to their accounts. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
mbrohl commented on a change in pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#discussion_r570988244 ########## File path: framework/webapp/src/main/java/org/apache/ofbiz/webapp/AfterLoginEvents.java ########## @@ -0,0 +1,93 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.ofbiz.webapp; + +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilHttp; +import org.apache.ofbiz.common.JsLanguageFilesMappingUtil; +import org.apache.ofbiz.entity.Delegator; +import org.apache.ofbiz.entity.GenericEntityException; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityListIterator; +import org.apache.ofbiz.entity.util.EntityQuery; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Locale; + +public class AfterLoginEvents { + + private static final String MODULE = AfterLoginEvents.class.getName(); + private static final String SCRIPT_SHOW_LAST_VISIT_DATE; + + static { + SCRIPT_SHOW_LAST_VISIT_DATE = "<span id='showLastLogin'></span><script>" + + "importLibrary(%s, function () {\n" + + "var dateFormat = Date.CultureInfo.formatPatterns.shortDate + ' ' + Date.CultureInfo.formatPatterns.longTime;\n" + + "var message = 'Your last visit was on '+new Date('%s').toString(dateFormat);\n" + + "$('#showLastLogin').replaceWith(message);\n" + + "});\n</script>"; + } + + public static String showLastVisit(HttpServletRequest request, HttpServletResponse response) { + + // guard against re-popup while moving to other web application when tomcat SSO is enabled + if (!"login".equals(request.getAttribute("thisRequestUri"))) { + return "success"; + } + + HttpSession session = request.getSession(); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); + + String userLoginId = (String) userLogin.get("userLoginId"); + + try (EntityListIterator eli = EntityQuery.use(delegator) + .from("Visit") + .where("userLoginId", userLoginId) + .orderBy("-fromDate") + .cursorScrollInsensitive() + .maxRows(2) + .queryIterator()) { + if (eli != null) { + GenericValue visit = null; + int count = 0; + while ((visit = eli.next()) != null) { + if (count == 1) { + Timestamp fromDate = visit.getTimestamp("fromDate"); + Locale locale = UtilHttp.getLocale(request); + String libJs = "['" + JsLanguageFilesMappingUtil.getFile("datejs", locale.toString()) + "']"; + SimpleDateFormat formatter = new SimpleDateFormat("EE MMM d y H:m:s ZZZ"); + String dateString = formatter.format(fromDate); + request.setAttribute("_UNSAFE_EVENT_MESSAGE_", String.format(SCRIPT_SHOW_LAST_VISIT_DATE, libJs, dateString)); + } + count++; + } + } + } catch (GenericEntityException e) { + Debug.logError(e, MODULE); + request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); Review comment: This should not be an error message, it's just an information. ########## File path: framework/webapp/src/main/java/org/apache/ofbiz/webapp/AfterLoginEvents.java ########## @@ -0,0 +1,93 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.ofbiz.webapp; + +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilHttp; +import org.apache.ofbiz.common.JsLanguageFilesMappingUtil; +import org.apache.ofbiz.entity.Delegator; +import org.apache.ofbiz.entity.GenericEntityException; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityListIterator; +import org.apache.ofbiz.entity.util.EntityQuery; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Locale; + +public class AfterLoginEvents { + + private static final String MODULE = AfterLoginEvents.class.getName(); + private static final String SCRIPT_SHOW_LAST_VISIT_DATE; + + static { + SCRIPT_SHOW_LAST_VISIT_DATE = "<span id='showLastLogin'></span><script>" + + "importLibrary(%s, function () {\n" Review comment: This prevents the ability to translate the UI, we should at least use ui labels here. ########## File path: framework/webapp/src/main/java/org/apache/ofbiz/webapp/AfterLoginEvents.java ########## @@ -0,0 +1,93 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.ofbiz.webapp; + +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilHttp; +import org.apache.ofbiz.common.JsLanguageFilesMappingUtil; +import org.apache.ofbiz.entity.Delegator; +import org.apache.ofbiz.entity.GenericEntityException; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityListIterator; +import org.apache.ofbiz.entity.util.EntityQuery; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Locale; + +public class AfterLoginEvents { + + private static final String MODULE = AfterLoginEvents.class.getName(); + private static final String SCRIPT_SHOW_LAST_VISIT_DATE; + + static { + SCRIPT_SHOW_LAST_VISIT_DATE = "<span id='showLastLogin'></span><script>" + + "importLibrary(%s, function () {\n" + + "var dateFormat = Date.CultureInfo.formatPatterns.shortDate + ' ' + Date.CultureInfo.formatPatterns.longTime;\n" + + "var message = 'Your last visit was on '+new Date('%s').toString(dateFormat);\n" + + "$('#showLastLogin').replaceWith(message);\n" + + "});\n</script>"; + } + + public static String showLastVisit(HttpServletRequest request, HttpServletResponse response) { + + // guard against re-popup while moving to other web application when tomcat SSO is enabled Review comment: We should also make the whole mechanism configurable (e.g. through a show.lastlogin.message = true|false configuration option). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
james-yong commented on a change in pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#discussion_r571442383 ########## File path: framework/webapp/src/main/java/org/apache/ofbiz/webapp/AfterLoginEvents.java ########## @@ -0,0 +1,93 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.ofbiz.webapp; + +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilHttp; +import org.apache.ofbiz.common.JsLanguageFilesMappingUtil; +import org.apache.ofbiz.entity.Delegator; +import org.apache.ofbiz.entity.GenericEntityException; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityListIterator; +import org.apache.ofbiz.entity.util.EntityQuery; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Locale; + +public class AfterLoginEvents { + + private static final String MODULE = AfterLoginEvents.class.getName(); + private static final String SCRIPT_SHOW_LAST_VISIT_DATE; + + static { + SCRIPT_SHOW_LAST_VISIT_DATE = "<span id='showLastLogin'></span><script>" + + "importLibrary(%s, function () {\n" Review comment: Ok. Amended the script and added an entry in SecurityUiLabels.xml ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
james-yong commented on a change in pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#discussion_r571442509 ########## File path: framework/webapp/src/main/java/org/apache/ofbiz/webapp/AfterLoginEvents.java ########## @@ -0,0 +1,93 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.ofbiz.webapp; + +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilHttp; +import org.apache.ofbiz.common.JsLanguageFilesMappingUtil; +import org.apache.ofbiz.entity.Delegator; +import org.apache.ofbiz.entity.GenericEntityException; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityListIterator; +import org.apache.ofbiz.entity.util.EntityQuery; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Locale; + +public class AfterLoginEvents { + + private static final String MODULE = AfterLoginEvents.class.getName(); + private static final String SCRIPT_SHOW_LAST_VISIT_DATE; + + static { + SCRIPT_SHOW_LAST_VISIT_DATE = "<span id='showLastLogin'></span><script>" + + "importLibrary(%s, function () {\n" + + "var dateFormat = Date.CultureInfo.formatPatterns.shortDate + ' ' + Date.CultureInfo.formatPatterns.longTime;\n" + + "var message = 'Your last visit was on '+new Date('%s').toString(dateFormat);\n" + + "$('#showLastLogin').replaceWith(message);\n" + + "});\n</script>"; + } + + public static String showLastVisit(HttpServletRequest request, HttpServletResponse response) { + + // guard against re-popup while moving to other web application when tomcat SSO is enabled + if (!"login".equals(request.getAttribute("thisRequestUri"))) { + return "success"; + } + + HttpSession session = request.getSession(); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); + + String userLoginId = (String) userLogin.get("userLoginId"); + + try (EntityListIterator eli = EntityQuery.use(delegator) + .from("Visit") + .where("userLoginId", userLoginId) + .orderBy("-fromDate") + .cursorScrollInsensitive() + .maxRows(2) + .queryIterator()) { + if (eli != null) { + GenericValue visit = null; + int count = 0; + while ((visit = eli.next()) != null) { + if (count == 1) { + Timestamp fromDate = visit.getTimestamp("fromDate"); + Locale locale = UtilHttp.getLocale(request); + String libJs = "['" + JsLanguageFilesMappingUtil.getFile("datejs", locale.toString()) + "']"; + SimpleDateFormat formatter = new SimpleDateFormat("EE MMM d y H:m:s ZZZ"); + String dateString = formatter.format(fromDate); + request.setAttribute("_UNSAFE_EVENT_MESSAGE_", String.format(SCRIPT_SHOW_LAST_VISIT_DATE, libJs, dateString)); + } + count++; + } + } + } catch (GenericEntityException e) { + Debug.logError(e, MODULE); + request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); Review comment: Removed the following: request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
james-yong commented on a change in pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#discussion_r571442746 ########## File path: framework/webapp/src/main/java/org/apache/ofbiz/webapp/AfterLoginEvents.java ########## @@ -0,0 +1,93 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.ofbiz.webapp; + +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilHttp; +import org.apache.ofbiz.common.JsLanguageFilesMappingUtil; +import org.apache.ofbiz.entity.Delegator; +import org.apache.ofbiz.entity.GenericEntityException; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityListIterator; +import org.apache.ofbiz.entity.util.EntityQuery; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Locale; + +public class AfterLoginEvents { + + private static final String MODULE = AfterLoginEvents.class.getName(); + private static final String SCRIPT_SHOW_LAST_VISIT_DATE; + + static { + SCRIPT_SHOW_LAST_VISIT_DATE = "<span id='showLastLogin'></span><script>" + + "importLibrary(%s, function () {\n" + + "var dateFormat = Date.CultureInfo.formatPatterns.shortDate + ' ' + Date.CultureInfo.formatPatterns.longTime;\n" + + "var message = 'Your last visit was on '+new Date('%s').toString(dateFormat);\n" + + "$('#showLastLogin').replaceWith(message);\n" + + "});\n</script>"; + } + + public static String showLastVisit(HttpServletRequest request, HttpServletResponse response) { + + // guard against re-popup while moving to other web application when tomcat SSO is enabled Review comment: Added "afterlogin.lastvisit.show" in security.properties ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
james-yong commented on pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774561622 Hi @mbrohl , Thanks for approval. Need your help to merge this pull request as I have no write access. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
JacquesLeRoux commented on pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774637227 Wait James, you should have write access, you are a committer. Can't you merge here (in this case "Squash and merge") ? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
james-yong commented on pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774655425 Hi Jacques, I see the following for this pull request: ![image](https://user-images.githubusercontent.com/28743891/107144626-64e9ca00-6977-11eb-917d-37e6f67443ce.png) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
JacquesLeRoux commented on pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774675491 James, I think you need to follow https://servicecomb.apache.org/developers/setup-committer-rights/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
JacquesLeRoux edited a comment on pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774675491 James, I think you need to follow https://servicecomb.apache.org/developers/setup-committer-rights/ Since above link is for Apache ServiceComb you may prefer to follow https://www.allengeorge.com/2018/12/17/write-access-as-an-apache-committer/ And we could have a page like ServiceComb has in OFBiz site, ie at https://ofbiz.apache.org/developers/setup-committer-rights/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
james-yong merged pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
In reply to this post by GitBox
james-yong commented on pull request #266: URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774701718 Thanks Jacques. Followed the steps from the 1st link and now has the write access. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] |
Free forum by Nabble | Edit this page |