Open Dialog from Login Screen

Hi ,

Today i’m trying to open Dialog from login window
Login window is overridden , why trying to create reset password dialog

I’m getting Access Denied

With Exception
22:23:52.319 [http-nio-8080-exec-42] ERROR com.haulmont.cuba.web.log.AppLog - Exception in com.haulmont.cuba.web.widgets.CubaButton: com.haulmont.cuba.core.global.AccessDeniedException: SCREEN inputDialog

How i make it works

Controller


@UiController("VTowerLogin")
@UiDescriptor("vtower-login.xml")
public class VTowerLogin extends LoginScreen {

    @Inject
    private UserService userService;

    @Inject
    private Dialogs dialogs;
    @Inject
    private Notifications notifications;

    @Inject
    private MessageBundle messageBundle;

    @Subscribe("resetPasswordBtn")
    public void onCustomActionsBtnClick(Button.ClickEvent event) {
        dialogs.createInputDialog(this)
                .withCaption("Enter values")
                .withParameters(
                        InputParameter.stringParameter("email").withCaption(messageBundle.getMessage("reset-pass-email-field-caption"))
                )
                .withActions(
                        InputDialogAction.action("confirm")
                                .withCaption("Confirm")
                                .withPrimary(true)
                                .withHandler(actionEvent -> {
                                    InputDialog dialog = actionEvent.getInputDialog();
                                    String email = dialog.getValue("email");
                                    userService.resetPassword(email);
                                    notifications.create()
                                            .withCaption(messageBundle.getMessage("reset-password-success"))
                                            .withDescription(messageBundle.getMessage("new-password-sent-mail"))
                                            .withPosition(Notifications.Position.TOP_RIGHT)
                                            .withType(Notifications.NotificationType.HUMANIZED)
                                            .show();
                                    dialog.closeWithDefaultAction();
                                }),
                        InputDialogAction.action("refuse")
                                .withCaption("Refuse")
                                .withValidationRequired(false)
                                .withHandler(actionEvent ->
                                        actionEvent.getInputDialog().closeWithDefaultAction())
                )
                .show();
    }

}

XML

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
        caption="msg://caption"
        messagesPack="com.vtss.vtower.web.screens.login">

    <actions>
        <action id="submit"
                caption="mainMsg://loginWindow.okButton"
                icon="app/images/login-button.png"
                invoke="login" shortcut="ENTER"/>
    </actions>

    <layout stylename="c-login-main-layout" expand="loginWrapper">
        <vbox id="loginWrapper">
            <vbox id="loginMainBox"
                  align="MIDDLE_CENTER"
                  stylename="c-login-panel"
                  width="AUTO">
                <hbox id="loginTitleBox"
                      align="MIDDLE_CENTER"
                      stylename="c-login-title">
                    <image id="logoImage"
                           align="MIDDLE_LEFT"
                           height="AUTO"
                           scaleMode="SCALE_DOWN"
                           stylename="c-login-icon"
                           width="AUTO"/>

                    <label id="welcomeLabel"
                           align="MIDDLE_LEFT"
                           stylename="c-login-caption"
                           value="mainMsg://loginWindow.welcomeLabel"/>
                </hbox>

                <capsLockIndicator id="capsLockIndicator"
                                   align="MIDDLE_CENTER"
                                   stylename="c-login-capslockindicator"/>

                <vbox id="loginForm"
                      spacing="true"
                      stylename="c-login-form">
                    <cssLayout id="loginCredentials"
                               stylename="c-login-credentials">
                        <textField id="loginField"
                                   htmlName="loginField"
                                   inputPrompt="mainMsg://loginWindow.loginPlaceholder"
                                   stylename="c-login-username"/>
                        <passwordField id="passwordField"
                                       autocomplete="true"
                                       htmlName="passwordField"
                                       inputPrompt="mainMsg://loginWindow.passwordPlaceholder"
                                       capsLockIndicator="capsLockIndicator"
                                       stylename="c-login-password"/>
                    </cssLayout>
                    <hbox id="rememberLocalesBox"
                          stylename="c-login-remember-locales">
                        <checkBox id="rememberMeCheckBox"
                                  caption="mainMsg://loginWindow.rememberMe"
                                  stylename="c-login-remember-me"/>
                        <lookupField id="localesSelect"
                                     nullOptionVisible="false"
                                     stylename="c-login-locale"
                                     textInputAllowed="false"/>
                    </hbox>
                    <label id="spacer"/>
                    <hbox spacing="true">
                        <linkButton id="resetPasswordBtn"
                                    align="MIDDLE_LEFT"
                                    caption="mainMsg://action.reset.password"
                                    description="msg://press-me-for-reset-password"/>
                        <button id="loginButton"
                                align="MIDDLE_RIGHT"
                                action="submit"
                                stylename="c-login-submit-button"/>
                    </hbox>
                </vbox>
            </vbox>
        </vbox>

        <label id="poweredByLink"
               align="MIDDLE_CENTER"
               htmlEnabled="true"
               stylename="c-powered-by"
               value="mainMsg://vtower.poweredBy"/>
    </layout>
</window>

Hi @abd.ibrahim.allam,
Your problem seems to be the same as in the topic below:

Regards,
Peterson.

Hi @peterson.br,

Thanks for you replay ,
But if you noticed that the other post was speaking about creating screen and open it in dialog mode not **Dialog **

Even i tried to create the same scenario on the other post , but i faced another thing ,

Their is no anonymous role found on the ‘Roles’ screen

image

Where can i found it or even how to enable it.

Hi @abd.ibrahim.allam,
You can use the existing system-minimal or create a new anonymous role. Just rembember to assign the chosen role to the Anonymous user.

When creating a new screen (vtower-login), it is necessary to allow access to that screen in the role so that users belonging to that role can access that screen.

If you inspect system-minimal role, you’ll notice that default login screens are allowed:
image

Regards,
Peterson

Hi @peterson.br,

Thanks for your response , that one fixed my issue ,

But i’m also wondering regarding Dialogs we can’t open them from anonymous pages like Login Page without having reported Exception

Hi @abd.ibrahim.allam,

I haven’t done anything like you are describing before, so I don’t know how to help you. But as a general guideline, I suggest that whenever you are having a problem, you try to debug the code (cuba is an open platform - you have access to the code).

I’ve been using this approach myself and I personaly like the quality of the platform code (it is well written, documented and commented). After some time you’ll be learning the platform even if some feature is not completely documented.

In this case, run the app in debug mode, add breakpoints in the Exception constructors and then inspect the code just before the exception is thrown.
image

Hope it helps.

Regards,
Peterson.

Hi @peterson.br ,

Thanks for your explanation, and me to doing the same as usual , but some time the stack trace is not actually showing the actual root cause . as such situations i’m reporting it here

Thanks