Skip to content

Commit

Permalink
LPS-124814 Use the user's time zone when displaying the next time the…
Browse files Browse the repository at this point in the history
… user can change their password
  • Loading branch information
jonathanmccann committed Dec 11, 2020
1 parent 6265d79 commit f1c019f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Expand Up @@ -137,6 +137,7 @@ page import="com.liferay.portal.kernel.service.permission.UserPermissionUtil" %>
page import="com.liferay.portal.kernel.util.CalendarFactoryUtil" %><%@
page import="com.liferay.portal.kernel.util.CalendarUtil" %><%@
page import="com.liferay.portal.kernel.util.Constants" %><%@
page import="com.liferay.portal.kernel.util.FastDateFormatConstants" %><%@
page import="com.liferay.portal.kernel.util.FastDateFormatFactoryUtil" %><%@
page import="com.liferay.portal.kernel.util.GetterUtil" %><%@
page import="com.liferay.portal.kernel.util.HashMapBuilder" %><%@
Expand Down Expand Up @@ -199,7 +200,8 @@ page import="java.util.HashMap" %><%@
page import="java.util.LinkedHashMap" %><%@
page import="java.util.List" %><%@
page import="java.util.Map" %><%@
page import="java.util.Set" %>
page import="java.util.Set" %><%@
page import="java.util.TimeZone" %>

<%@ page import="javax.portlet.ActionRequest" %><%@
page import="javax.portlet.PortletURL" %><%@
Expand Down
Expand Up @@ -117,9 +117,11 @@ else {

<%
UserPasswordException.MustNotBeChangedYet upe = (UserPasswordException.MustNotBeChangedYet)errorException;
Format dateFormat = FastDateFormatFactoryUtil.getDateTime(FastDateFormatConstants.SHORT, FastDateFormatConstants.LONG, locale, TimeZone.getTimeZone(upe.timeZoneId));
%>

<liferay-ui:message arguments="<%= String.valueOf(upe.changeableDate) %>" key="you-cannot-change-your-password-yet" translateArguments="<%= false %>" />
<liferay-ui:message arguments="<%= dateFormat.format(upe.changeableDate) %>" key="you-cannot-change-your-password-yet" translateArguments="<%= false %>" />
</liferay-ui:error>

<liferay-ui:error exception="<%= UserPasswordException.MustNotBeEqualToCurrent.class %>" message="your-new-password-cannot-be-the-same-as-your-old-password-please-enter-a-different-password" />
Expand Down
Expand Up @@ -196,7 +196,7 @@ public void validate(
!user.isPasswordReset()) {

throw new UserPasswordException.MustNotBeChangedYet(
userId, new Date(passwordModifiedDate.getTime() + minAge));
user, new Date(passwordModifiedDate.getTime() + minAge));
}
}

Expand Down
Expand Up @@ -15,9 +15,12 @@
package com.liferay.portal.kernel.exception;

import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.util.TimeZoneUtil;

import java.util.Date;
import java.util.List;
import java.util.TimeZone;

/**
* @author Brian Wing Shun Chan
Expand Down Expand Up @@ -194,17 +197,39 @@ public MustNotBeChanged(long userId) {

public static class MustNotBeChangedYet extends UserPasswordException {

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link
* #MustNotBeChangedYet(User, Date)}
*/
@Deprecated
public MustNotBeChangedYet(long userId, Date changeableDate) {
super(
String.format(
"Password for user %s must not be changed until %s", userId,
changeableDate));

TimeZone timeZone = TimeZoneUtil.getDefault();

timeZoneId = timeZone.getID();

this.userId = userId;
this.changeableDate = changeableDate;
}

public MustNotBeChangedYet(User user, Date changeableDate) {
super(
String.format(
"Password for user %s must not be changed until %s",
user.getUserId(), changeableDate));

timeZoneId = user.getTimeZoneId();
userId = user.getUserId();

this.changeableDate = changeableDate;
}

public final Date changeableDate;
public String timeZoneId;
public long userId;

}
Expand Down

0 comments on commit f1c019f

Please sign in to comment.