Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Login Overlay - add new button

Kamil Seweryn
3 years ago Nov 11, 2019 7:00pm

Is there any possibility to add a new button to the login overlay? I need to add "Registration" button but when I do it, that button is "under" login form and when I start app then I don't see it... I don't have any ide how to add this button under "Log in" button. Can you help me?

My code:

@Tag("sa-login-view")
@Route(value = LibraryConst.ROUTE_LOGIN)
@PageTitle(LibraryConst.TITLE_LOGIN)
public class LoginView extends VerticalLayout {
    private LoginOverlay login = new LoginOverlay();

    @Autowired
    public LoginView(AuthenticationManager authenticationManager) {
        login.setOpened(true);
        login.setTitle(LibraryConst.TITLE_LOGIN);
        login.setVisible(false);

        Button button = new Button("Register");

        add(login, button);

        login.addLoginListener(e -> {
            try {
                final Authentication authentication = authenticationManager
                        .authenticate(new UsernamePasswordAuthenticationToken(e.getUsername(), e.getPassword()));
                if(authentication != null) {
                    login.close();
                    SecurityContextHolder.getContext().setAuthentication(authentication);
                    getUI().get().navigate("/");
                }
            } catch (AuthenticationException ex) {
                login.setError(true);
            }
        });
    }
}
Meghdad Pouraghajan
3 years ago Feb 09, 2020 6:17pm

I need this feature too. It's a bit silly to have a login form without giving the user the chance to sign-up first!!!

Brian Sheely
2 years ago Mar 09, 2020 6:35pm

What an incredibly poor design by Vaadin. The Login Overlay is basically worthless without the ability to add a button for new users.

Meghdad Pouraghajan
2 years ago Mar 09, 2020 8:10pm

Brian Sheely: What an incredibly poor design by Vaadin. The Login Overlay is basically worthless without the ability to add a button for new users.

Hi,
Actually, I came up with a workaround for this. I'll give you an example and I hope it helps you too.
Login Overlay provides the developers with an Anchor option (Visible beneath the Login button) for handling the "Forgot Password" situation.
Actually, it doesn't provide any specific feature regarding the "Forgot Password" functionality itself. it is simply an Anchor object you can point it to where ever you want.
In my application I have used this to navigate the user to Sign-Up page, out of the Login Overlay, as following.

LoginOverlay login = new LoginOverlay();
LoginI18n loginForm = LoginI18n.createDefault();
login.setI18n(loginForm);
loginForm.getForm().setForgotPassword("Forgot Password/Sign Up");
login.setForgotPasswordButtonVisible(true);
login.setAction("login");
login.addForgotPasswordListener(event -> {
      login.close();
      switchOrNavigateToView(VIEWS.SIGNUP);
});
Last updated on Mar, 9th 2020
Kaspar Scherrer
2 years ago Mar 10, 2020 7:49am