You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by GitBox <gi...@apache.org> on 2021/02/05 13:51:47 UTC

[GitHub] [ofbiz-framework] james-yong opened a new pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

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:
users@infra.apache.org



[GitHub] [ofbiz-framework] james-yong commented on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] sonarcloud[bot] removed a comment on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] removed a comment on pull request #266:
URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774050121


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo.png' alt='No Coverage information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_ofbiz-framework&pullRequest=266) No Coverage information  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/NoDuplicationInfo.png' alt='No Duplication information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_ofbiz-framework&pullRequest=266&metric=duplicated_lines_density&view=list) No Duplication information
   
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] sonarcloud[bot] commented on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #266:
URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774050121


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo.png' alt='No Coverage information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_ofbiz-framework&pullRequest=266) No Coverage information  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/NoDuplicationInfo.png' alt='No Duplication information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_ofbiz-framework&pullRequest=266&metric=duplicated_lines_density&view=list) No Duplication information
   
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] james-yong commented on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] JacquesLeRoux edited a comment on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] JacquesLeRoux commented on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] james-yong commented on a change in pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] james-yong merged pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] mbrohl commented on a change in pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] JacquesLeRoux commented on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] james-yong commented on a change in pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] sonarcloud[bot] commented on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #266:
URL: https://github.com/apache/ofbiz-framework/pull/266#issuecomment-774482558


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=VULNERABILITY)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=SECURITY_HOTSPOT)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=apache_ofbiz-framework&pullRequest=266&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo.png' alt='No Coverage information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_ofbiz-framework&pullRequest=266) No Coverage information  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/NoDuplicationInfo.png' alt='No Duplication information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_ofbiz-framework&pullRequest=266&metric=duplicated_lines_density&view=list) No Duplication information
   
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] james-yong commented on a change in pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ofbiz-framework] james-yong commented on pull request #266: Improved: Display last-visited-time popup after login (OFBIZ-12148)

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org