Sample User Registration - Restore Password not finding user

Hello again, CUBA Team!

I’m attempting to finish up my User Registration project using the sample-user-registration project, but the “Restore Password” portion is not finding the user, and the code is unchanged from the sample project. The error message is triggered every time. The code is:

/**
     * "Send new password" button click handler.
     */
    @Subscribe("okBtn")
    public void onOkBtnClick(Button.ClickEvent event) {
        // validate required fields first
        if (validateScreen()) {
            LoadContext<User> lc = LoadContext.create(User.class);
            lc.setView(View.MINIMAL);
            lc.setQueryString("select u from sec$User u where u.loginLowerCase = :login and (u.active = true or u.active is null)")
                    .setParameter("login", loginField.getValue());

            User targetUser = dataManager.load(lc);
            if (targetUser == null) {
                warningLabel.setVisible(true);

                loginField.focus();
            } else {
                // generate new temporary password and send email
                // user must have specified e-mail in the database
                userManagementService.changePasswordsAtLogonAndSendEmails(Collections.singletonList(targetUser.getId()));

                notifications.create(Notifications.NotificationType.TRAY)
                        .withCaption("Success")
                        .withDescription("E-mail with your new password has been sent")
                        .show();

                close(WINDOW_COMMIT_AND_CLOSE_ACTION);
            }
        }
    }

It always gets stuck in the targetUser == null block.

I’m curious if there is something not quite right in the sample code, or if I need to do something extra to get this to load the user properly. I’ve verified that the logins do exist and are active.

Thanks,
Adam

Hi,
Just an educated guess from me.

Maybe you have not enabled READ access for the sec$User entity for the anonymous user, or other user that is used to execute the code in the “restore password” screen?

1 Like

Hello @AlexBudarov,

Yep. That was it! I really wish the README of the sample-user-registration project was much more detailed.

Regardless, I thank you very much for your help!

Actually Alex, everything seemed to go through correctly, only I didn’t receive the email for the restore password action. Am I supposed to set something up on my localhost to get SMTP functioning?

Yeah, I’m pretty sure I just need to set it up on my machine. I found a way to set up postfix on my Mac, though it didn’t work. I’m wondering if I need to set something up in CUBA to use postfix.

Hi,
In order to send emails you need an SMTP server.
CUBA does not have build-in SMTP server inside.

For development purposes you can use your own gmail account:

For production - there are plenty of services to use, depending on amount of emails you are going to send.