Skip to content
Snippets Groups Projects
Commit 9fd1b716 authored by srosse's avatar srosse
Browse files

OO-1715: show an error message instead of a red screen

parent 1752f339
No related branches found
No related tags found
No related merge requests found
...@@ -106,8 +106,14 @@ public class OLATAuthManager extends BasicManager implements AuthenticationSPI { ...@@ -106,8 +106,14 @@ public class OLATAuthManager extends BasicManager implements AuthenticationSPI {
// check for email instead of username if ident is null // check for email instead of username if ident is null
if(loginModule.isAllowLoginUsingEmail()) { if(loginModule.isAllowLoginUsingEmail()) {
if (MailHelper.isValidEmailAddress(login)){ if (MailHelper.isValidEmailAddress(login)){
ident = userManager.findIdentityByEmail(login); List<Identity> identities = userManager.findIdentitiesByEmail(Collections.singletonList(login));
// check for email changed with verification workflow // check for email changed with verification workflow
if(identities.size() == 1) {
ident = identities.get(0);
} else if(identities.size() > 1) {
logError("more than one identity found with email::" + login, null);
}
if (ident == null) { if (ident == null) {
ident = findIdentInChangingEmailWorkflow(login); ident = findIdentInChangingEmailWorkflow(login);
} }
......
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
package org.olat.registration; package org.olat.registration;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.olat.basesecurity.Authentication; import org.olat.basesecurity.Authentication;
...@@ -83,6 +85,8 @@ public class PwChangeController extends BasicController { ...@@ -83,6 +85,8 @@ public class PwChangeController extends BasicController {
@Autowired @Autowired
private RegistrationManager rm; private RegistrationManager rm;
@Autowired
private UserManager userManager;
/** /**
* Controller to change a user's password. * Controller to change a user's password.
...@@ -167,6 +171,7 @@ public class PwChangeController extends BasicController { ...@@ -167,6 +171,7 @@ public class PwChangeController extends BasicController {
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event) * org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/ */
@Override
public void event(UserRequest ureq, Controller source, Event event) { public void event(UserRequest ureq, Controller source, Event event) {
if (source == pwf) { if (source == pwf) {
// pwchange Form was clicked // pwchange Form was clicked
...@@ -179,9 +184,14 @@ public class PwChangeController extends BasicController { ...@@ -179,9 +184,14 @@ public class PwChangeController extends BasicController {
pwchangeHomelink.setCustomEnabledLinkCSS("btn btn-primary"); pwchangeHomelink.setCustomEnabledLinkCSS("btn btn-primary");
//pwf.setVisible(false); //pwf.setVisible(false);
pwarea.setVisible(false); pwarea.setVisible(false);
Identity identToChange = UserManager.getInstance().findIdentityByEmail(tempKey.getEmailAddress()); List<Identity> identToChanges = userManager.findIdentitiesByEmail(Collections.singletonList(tempKey.getEmailAddress()));
if(identToChange == null || !pwf.saveFormData(identToChange)) { if(identToChanges == null || identToChanges.size() == 0 || identToChanges.size() > 1) {
getWindowControl().setError(translate("pwchange.failed")); getWindowControl().setError(translate("pwchange.failed"));
} else {
Identity identToChange = identToChanges.get(0);
if(!pwf.saveFormData(identToChange)) {
getWindowControl().setError(translate("pwchange.failed"));
}
} }
rm.deleteTemporaryKeyWithId(tempKey.getRegistrationKey()); rm.deleteTemporaryKeyWithId(tempKey.getRegistrationKey());
} else if (event == Event.CANCELLED_EVENT) { } else if (event == Event.CANCELLED_EVENT) {
...@@ -213,7 +223,10 @@ public class PwChangeController extends BasicController { ...@@ -213,7 +223,10 @@ public class PwChangeController extends BasicController {
// Try fallback with email, maybe user used his email address instead // Try fallback with email, maybe user used his email address instead
// only do this, if its really an email, may lead to multiple results else. // only do this, if its really an email, may lead to multiple results else.
if (MailHelper.isValidEmailAddress(emailOrUsername)) { if (MailHelper.isValidEmailAddress(emailOrUsername)) {
identity = UserManager.getInstance().findIdentityByEmail(emailOrUsername); List<Identity> identities = userManager.findIdentitiesByEmail(Collections.singletonList(emailOrUsername));
if(identities.size() == 1) {
identity = identities.get(0);
}
} }
} }
if (identity != null) { if (identity != null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment