Login with email-address (and social login)

Hi,

Cuba Platform standard has usernames for login. Is it possible to make users login with emailadresses instead of login names?

If yes, how is this possible?

Kind regards,
Abdel

2 Likes

Hello,

Why is this question not answered?

Kind regards,
Abdel

Hello Abdel,

Thank you for the heads up! We try our best to meet expectations of our community working hard with limited resourses. We answer questions in order of appearance keeping in mind the complexity of the topic. Please, don’t forget that this forum is free and you can’t expect your question being answered within a certain time. If swiftness is an issue you can always buy SLA or consulting hours. We’ll try to asnwer your question asap.

Regards,
Andrey

Hi Andrey,

Thank you.
I will wait for the answer.

Kind regards,
Abdel

Hi,

At the moment our authentication mechanism is not so flexible as we want. We are planning to rework it in release 6.7.
See this ticket for details: https://youtrack.cuba-platform.com/issue/PL-9404

In case of email login in web client there is a simple workaround to enable it.

  1. Extend loginWindow screen using Studio: Generic UI - New - Login Window
  2. Override doLogin and doLoginRememberMe methods:

public class ExtAppLoginWindow extends AppLoginWindow {
    @Inject
    private DataService dataService;

    @Override
    protected void doLogin(String login, String password, Locale locale) throws LoginException {
        super.doLogin(findLoginByEmail(login), password, locale);
    }

    @Override
    protected void doLoginByRememberMe(String login, String rememberMeToken, Locale locale) throws LoginException {
        super.doLoginByRememberMe(findLoginByEmail(login), rememberMeToken, locale);
    }

    private String findLoginByEmail(String email) throws LoginException {
        if (!email.contains("@")) {
            return email;
        }
        
        // find user login by email using dataService
        List<User> users = dataService.loadList(LoadContext.create(User.class)
                .setQuery(new LoadContext.Query("select u from sec$User u where u.email = :email")
                        .setParameter("email", email)));

        if (users.isEmpty()) {
            throw new LoginException("Unable to find user");
        }

        return users.get(0).getLogin();
    }
}

Alternative solution - create a user with the login that is equal to email. In this case don’t need to extend loginWindow and perform conversion.

As for social login, now there is no simple way to create custom authentication for web application and REST-API.

We have implemented necessary external mechanisms for REST-API in release 6.6 and prepared demo with facebook login for web application.
We will share demos and documentation on this topic right after 6.6 release.