Allow user to reset password if forgot password

On most websites, there is an option to get the system to reset the user’s password if they forgot the password. A new random password is sent to the user’s email after answering some secret question. The “Forgot Password” option is available on the login screen.
Does Cuba platform have this option ? I could not find it in the documentation or any sample app.
How can I develop this function and change the login screen ?

1 Like

Hi,

I’ve updated user-registration sample and added restore password dialog. You can obtain this sample using Samples tab in Studio.

There I show how to use UserManagementService to reset a password and send e-mail with new password.

UserManagementService is a service providing maintenance operations on security entities: users, groups and roles.

First we load user with login equals to login entered in restore password dialog:


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);

Then if targetUser is not null we call changePasswordsAtLogonAndSendEmails method from UserManagementService:


userManagementService.changePasswordsAtLogonAndSendEmails(
    Collections.singletonList(targetUser.getId())
);

UserManagementService.changePasswordsAtLogonAndSendEmails is used by administration menu Reset passwords and we can use it for reset password functionality for public users.

Also there is simple link on login screen that shows Restore password dialog.

OK will look at this example. Thanks

A post was split to a new topic: Tried implementing the Restore password but getting error