Search in sources :

Example 1 with ELoginResult

use of com.helger.photon.security.login.ELoginResult 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)

Example 2 with ELoginResult

use of com.helger.photon.security.login.ELoginResult in project phoss-smp by phax.

the class AjaxExecutorPublicLogin method mainHandleRequest.

@Override
protected void mainHandleRequest(@Nonnull final LayoutExecutionContext aLEC, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
    final String sLoginName = aLEC.params().getAsString(CLogin.REQUEST_ATTR_USERID);
    final String sPassword = aLEC.params().getAsString(CLogin.REQUEST_ATTR_PASSWORD);
    // Main login
    final ELoginResult eLoginResult = LoggedInUserManager.getInstance().loginUser(sLoginName, sPassword, CSMP.REQUIRED_ROLE_IDS_WRITABLERESTAPI);
    if (eLoginResult.isSuccess()) {
        aAjaxResponse.json(new JsonObject().add(JSON_LOGGEDIN, true));
        return;
    }
    // Get the rendered content of the menu area
    if (GlobalDebug.isDebugMode())
        if (LOGGER.isWarnEnabled())
            LOGGER.warn("Login of '" + sLoginName + "' failed because " + eLoginResult);
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final IHCNode aRoot = error(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) ELoginResult(com.helger.photon.security.login.ELoginResult) JsonObject(com.helger.json.JsonObject) IHCNode(com.helger.html.hc.IHCNode)

Aggregations

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