if(isLogDebugEnabled()) {
logDebug("this servername is " + servername + " and serverpath is " + serverpath, null);
}
// Look for user in "Person" and "user" tables
Identity identity = null;
// See if the entered value is a username
identity = ManagerFactory.getManager().findIdentityByName(emailOrUsername);
if (identity == null) {
// 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.
if (MailHelper.isValidEmailAddress(emailOrUsername)) {
identity = UserManager.getInstance().findIdentityByEmail(emailOrUsername);
}
}
if (identity != null) {
// check if user has an OLAT provider token, otherwhise a pwd change makes no sense
Authentication auth = ManagerFactory.getManager().findAuthentication(identity, OLATAuthenticationController.PROVIDER_OLAT);
if (auth == null) {
getWindowControl().setWarning(translate("password.cantchange"));
return;
}
Preferences prefs = identity.getUser().getPreferences();
Locale locale = I18nManager.getInstance().getLocaleOrDefault(prefs.getLanguage());
ureq.getUserSession().setLocale(locale);
myContent.contextPut("locale", locale);
Translator userTrans = Util.createPackageTranslator(PwChangeController.class, locale) ;
String emailAdress = identity.getUser().getProperty(UserConstants.EMAIL, locale);
TemporaryKey tk = rm.loadTemporaryKeyByEmail(emailAdress);
if (tk == null) tk = rm.createTemporaryKeyByEmail(emailAdress, ip, rm.PW_CHANGE);
myContent.contextPut("pwKey", tk.getRegistrationKey());
body = userTrans.translate("pwchange.intro", new String[] { identity.getName() })
+ userTrans.translate("pwchange.body", new String[] { serverpath, tk.getRegistrationKey(),
I18nManager.getInstance().getLocaleKey(ureq.getLocale()) }) + SEPARATOR
+ userTrans.translate("reg.wherefrom", new String[] { serverpath, today, ip });
subject = userTrans.translate("pwchange.subject");
MailTemplate mailTempl = new MailTemplate(subject, body, null) {