Search in sources :

Example 1 with BootstrapErrorBox

use of com.helger.photon.bootstrap4.alert.BootstrapErrorBox in project phoss-directory by phax.

the class AjaxExecutorPublicLogin method handleRequest.

public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
    final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
    final String sLoginName = aRequestScope.params().getAsString(CLogin.REQUEST_ATTR_USERID);
    final String sPassword = aRequestScope.params().getAsString(CLogin.REQUEST_ATTR_PASSWORD);
    // Main login
    final ELoginResult eLoginResult = LoggedInUserManager.getInstance().loginUser(sLoginName, sPassword, AppSecurity.REQUIRED_ROLE_IDS_VIEW);
    if (eLoginResult.isSuccess()) {
        aAjaxResponse.json(new JsonObject().add(JSON_LOGGEDIN, true));
    } else {
        // Get the rendered content of the menu area
        if (GlobalDebug.isDebugMode())
            LOGGER.warn("Login of '" + sLoginName + "' failed because " + eLoginResult);
        final Locale aDisplayLocale = aLEC.getDisplayLocale();
        final IHCNode aRoot = new BootstrapErrorBox().addChild(EPhotonCoreText.LOGIN_ERROR_MSG.getDisplayText(aDisplayLocale) + " " + eLoginResult.getDisplayText(aDisplayLocale));
        // Set as result property
        aAjaxResponse.json(new JsonObject().add(JSON_LOGGEDIN, false).add(JSON_HTML, HCRenderer.getAsHTMLStringWithoutNamespaces(aRoot)));
    }
}
Also used : Locale(java.util.Locale) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) ELoginResult(com.helger.photon.security.login.ELoginResult) BootstrapErrorBox(com.helger.photon.bootstrap4.alert.BootstrapErrorBox) JsonObject(com.helger.json.JsonObject) IHCNode(com.helger.html.hc.IHCNode)

Aggregations

IHCNode (com.helger.html.hc.IHCNode)1 JsonObject (com.helger.json.JsonObject)1 BootstrapErrorBox (com.helger.photon.bootstrap4.alert.BootstrapErrorBox)1 LayoutExecutionContext (com.helger.photon.core.execcontext.LayoutExecutionContext)1 ELoginResult (com.helger.photon.security.login.ELoginResult)1 Locale (java.util.Locale)1