任何人都有自定义 ForgotPasswordAction 的解决方案吗?我的最终目标是允许用户输入用户名或电子邮件,以便能够找回他们忘记的密码。我已经覆盖了 ForgotPassword.java 中的 getUser(ActionRequest request) 方法,如下所示:
protected User getUser(ActionRequest actionRequest)
throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
WebKeys.THEME_DISPLAY);
//CUSTOM
String fgtPass = ParamUtil.getString(actionRequest, "fgtpass");
String authType = null;
if (Validator.isNull(authType)) {
Company company = PortalUtil.getCompany(actionRequest);
authType = company.getAuthType();
}
User user = null;
if ( fgtPass.indexOf("@") != -1 && fgtPass.indexOf(".") != -1 ) {
//If the login looks like an email, use the email authType constant.
authType = CompanyConstants.AUTH_TYPE_EA;
user = UserLocalServiceUtil.getUserByEmailAddress(
themeDisplay.getCompanyId(), fgtPass);
} else {
//If it doesn't look like an email, use the screen name authType constant.
authType = CompanyConstants.AUTH_TYPE_SN;
user = UserLocalServiceUtil.getUserByScreenName(
themeDisplay.getCompanyId(), fgtPass);
}
//End CUSTOM
return user;
}
}
这能够根据初始忘记密码屏幕上的屏幕名称或电子邮件对用户进行身份验证,但是一旦进入提醒查询页面,它就无法处理用户。我很确定我不能这样做,因为 fgtPass 字段仅存在于初始忘记密码屏幕上,而不存在于查询页面上。有什么办法可以保留这个用户吗?这是对应的.jsp:
<%
User user2 = (User)request.getAttribute(ForgotPasswordAction.class.getName());
if (Validator.isNull(authType)) {
authType = company.getAuthType();
System.out.println(authType);
}
if (user2 == null) {
System.out.println("User is null.");
} else {
System.out.println(user2.getScreenName());
}
%>
<portlet:actionURL var="forgotPasswordURL">
<portlet:param name="saveLastPath" value="0" />
<portlet:param name="struts_action" value="/login/forgot_password" />
</portlet:actionURL>
<aui:form action="<%= forgotPasswordURL %>" method="post" name="fm">
<portlet:renderURL var="redirectURL" />
<aui:input name="redirect" type="hidden" value="<%= redirectURL %>" />
<liferay-ui:error exception="<%= CaptchaTextException.class %>" message="text-verification-failed" />
<liferay-ui:error exception="<%= NoSuchUserException.class %>" message='<%= "the-" + TextFormatter.format(authType, TextFormatter.K) + "-you-requested-is-not-registered-in-our-database" %>' />
<liferay-ui:error exception="<%= RequiredReminderQueryException.class %>" message="you-have-not-configured-a-reminder-query" />
<liferay-ui:error exception="<%= SendPasswordException.class %>" message="your-password-can-only-be-sent-to-an-external-email-address" />
<liferay-ui:error exception="<%= UserEmailAddressException.class %>" message="please-enter-a-valid-email-address" />
<liferay-ui:error exception="<%= UserReminderQueryException.class %>" message="your-answer-does-not-match-what-is-in-our-database" />
<aui:fieldset>
<c:choose>
<c:when test="<%= user2 == null %>">
<% System.out.println("Enter Test"); %>
<%
String loginParameter = null;
if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
loginParameter = "emailAddress";
System.out.println(loginParameter);
}
else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
loginParameter = "screenName";
System.out.println(loginParameter);
}
else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
loginParameter = "userId";
System.out.println(loginParameter);
}
String loginValue = ParamUtil.getString(request, loginParameter);
%>
<aui:input name="step" type="hidden" value="1" />
<aui:input label="login-screen-name-or-email" name="fgtpass" size="30" type="text" value="<%= loginValue %>" />
<aui:button-row>
<aui:button type="submit" value='<%= PropsValues.USERS_REMINDER_QUERIES_ENABLED ? "next" : "send-new-password" %>' />
</aui:button-row>
<% System.out.println("The login value is: " + loginValue); %>
</c:when>
<c:when test="<%= (user2 != null) && Validator.isNotNull(user2.getEmailAddress()) %>">
<aui:input name="step" type="hidden" value="2" />
<%
if (user2!=null) {
System.out.println("Step 2 " + authType);
}
%>
<aui:input name="emailAddress" type="hidden" value="<%= user2.getEmailAddress() %>" />
<% System.out.println(user2.getEmailAddress()); %>
<c:if test="<%= Validator.isNotNull(user2.getReminderQueryQuestion()) && Validator.isNotNull(user2.getReminderQueryAnswer()) %>">
<div class="portlet-msg-info">
<%= LanguageUtil.format(pageContext, "a-new-password-will-be-sent-to-x-if-you-can-correctly-answer-the-following-question", user2.getEmailAddress()) %>
</div>
<% System.out.println(user2.getReminderQueryAnswer()); %>
<aui:input label="<%= user2.getReminderQueryQuestion() %>" name="answer" type="text" />
</c:if>
<c:choose>
<c:when test="<%= PropsValues.USERS_REMINDER_QUERIES_REQUIRED && !user2.hasReminderQuery() %>">
<div class="portlet-msg-info">
<liferay-ui:message key="the-password-cannot-be-reset-because-you-have-not-configured-a-reminder-query" />
</div>
</c:when>
<c:otherwise>
<c:if test="<%= PropsValues.CAPTCHA_CHECK_PORTAL_SEND_PASSWORD %>">
<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>" var="captchaURL">
<portlet:param name="struts_action" value="/login/captcha" />
</portlet:actionURL>
<liferay-ui:captcha url="<%= captchaURL %>" />
</c:if>
<aui:button-row>
<aui:button type="submit" value='<%= company.isSendPasswordResetLink() ? "send-password-reset-link" : "send-new-password" %>' />
</aui:button-row>
</c:otherwise>
</c:choose>
</c:when>
<c:otherwise>
<div class="portlet-msg-alert">
<liferay-ui:message key="the-system-cannot-send-you-a-new-password-because-you-have-not-provided-an-email-address" />
</div>
</c:otherwise>
</c:choose>
</aui:fieldset>
</aui:form>
<liferay-util:include page="/html/portlet/login/navigation.jsp" />
<aui:script>
Liferay.Util.focusFormField(document.<portlet:namespace />fm.<portlet:namespace /><%= (user2 == null) ? "emailAddress" : "answer" %>);
</aui:script>
有什么线索吗?