2017-05-31 110 views
0

我有一個主題,其中有一個彈出窗口來詢問登錄憑證。在liferay中自動登錄時處理身份驗證失敗

它有2個字段,登錄ID和密碼後跟一個提交按鈕。

<div class="x"> 
    <div class="y"> 
     <aui:input name="login" id="login" class="z" 
     type="text" placeholder="Email"            showRequiredLabel="<%=false%>" label="" value="<%=login%>"> 
     </aui:input> 
    </div> 
</div> 

<div class="x"> 
    <div class="y"> 
     <aui:input name="password" id="Password" 
     class="z" type="password" placeholder="Password" 
     showRequiredLabel="<%=false%>" label="" value="<%=password%>"> 
     </aui:input> 
    </div> 
</div> 

<div class="x"> 
    <div class="y"> 
     <aui:button-row> 
      <aui:button type="submit" class="btn z" 
      value="Log in" id=z/> 
      </aui:button-row> 
     </div> 
</div> 

<script> 
jQuery(document).ready(function($) { 


$('#z').click(function(){ 
var textBoxEmail= $('#login').val(); 
var textBoxPassword= $('#Password').val(); 
var redirecturl="/home"; 

var url = Liferay.ThemeDisplay.getPortalURL()+"/c/portal/login?login=" + textBoxEmail + "&password=" +textBoxPassword+"&rememberMe=false&redirect=" + redirecturl; 
$("#loginDetails").attr('action',url); 
document.getElementById('loginDetails').submit(); 

} 
}); 

</script> 

此登錄爲正的情況下,但如果輸入的密碼或電子郵件incorrecet它顯示

「此網頁無法使用

ERR_CONTENT_DECODING_FAILED」

我想在我發送登錄詳細信息的同一頁面中顯示失敗消息,或者我希望將它重定向到某些URL如果認證失敗。

我正在使用liferay-6.2-ce-ga3,主題是在速度中設計的。

回答

0

您可以重定向到/c/portal/login?redirect=currenturl,它將重定向到當前的URL。如果你想定製更多的話,編寫鉤子是另一種選擇。

0

所以在你開始之前,我會從架構的角度來質疑你的設計。在Liferay中,登錄功能實際上是它自己的portlet(稱爲登錄portlet)。修改登錄功能的正確方法是通過鉤子。但是,爲了更直接地回答您的問題,我會修改您的代碼(大部分內容來自Liferay的login.jsp)。

<portlet:actionURL secure="<%= PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS || request.isSecure() %>" var="loginURL"> 
    <portlet:param name="struts_action" value="/login/login" /> 
</portlet:actionURL> 

<aui:form action="<%= loginURL %>" autocomplete='<%= PropsValues.COMPANY_SECURITY_LOGIN_FORM_AUTOCOMPLETE ? "on" : "off" %>' cssClass="sign-in-form" method="post" name="fm"> 
    <aui:input name="saveLastPath" type="hidden" value="<%= false %>" /> 
    <aui:input name="redirect" type="hidden" value="<%= redirect %>" /> 
    <aui:input name="doActionAfterLogin" type="hidden" value="<%= portletName.equals(PortletKeys.FAST_LOGIN) ? true : false %>" /> 

    <% 
    String loginLabel = null; 
    String authType = portletPreferences.getValue("authType", StringPool.BLANK); 

    if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) { 
     loginLabel = "email-address"; 
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) { 
     loginLabel = "screen-name"; 
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) { 
     loginLabel = "id"; 
    } 
    %> 

    <aui:input autoFocus="<%= windowState.equals(LiferayWindowState.EXCLUSIVE) || windowState.equals(WindowState.MAXIMIZED) %>" cssClass="clearable" label="<%= loginLabel %>" name="login" showRequiredLabel="<%= false %>" type="text" value="<%= login %>"> 
     <aui:validator name="required" /> 
    </aui:input> 

    <aui:input name="password" showRequiredLabel="<%= false %>" type="password" value="<%= password %>"> 
     <aui:validator name="required" /> 
    </aui:input> 

    <span id="<portlet:namespace />passwordCapsLockSpan" style="display: none;"><liferay-ui:message key="caps-lock-is-on" /></span> 

    <aui:button-row> 
     <aui:button type="submit" value="sign-in" /> 
    </aui:button-row> 
</aui:form> 

<aui:script use="aui-base"> 
    var password = A.one('#<portlet:namespace />password'); 

    if (password) { 
     password.on('keypress', function(event) { 
      Liferay.Util.showCapsLock(event, '<portlet:namespace />passwordCapsLockSpan'); 
     }); 
    } 
</aui:script> 
0

我同意,使用登錄掛鉤或身份驗證管道使用前後登錄過濾器。重定向可以通過過濾器完成。