|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package de.bps.olat.user; |
|
|
|
import java.util.HashMap; |
|
|
|
import org.olat.basesecurity.BaseSecurity; |
|
import org.olat.core.gui.UserRequest; |
|
import org.olat.core.gui.control.WindowControl; |
|
import org.olat.core.gui.translator.Translator; |
|
import org.olat.core.id.Identity; |
|
import org.olat.core.id.User; |
|
import org.olat.core.util.StringHelper; |
|
import org.olat.core.util.Util; |
|
import org.olat.core.util.xml.XStreamHelper; |
|
import org.olat.home.HomeMainController; |
|
import org.olat.login.SupportsAfterLoginInterceptor; |
|
import org.olat.user.ProfileAndHomePageEditController; |
|
import org.olat.user.UserManager; |
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import com.thoughtworks.xstream.XStream; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ChangeEMailExecuteController extends ChangeEMailController implements SupportsAfterLoginInterceptor { |
|
|
|
private static final String PRESENTED_EMAIL_CHANGE_REMINDER = "presentedemailchangereminder"; |
|
|
|
protected static final String PACKAGE_HOME = ProfileAndHomePageEditController.class.getPackage().getName(); |
|
|
|
@Autowired |
|
private UserManager userManager; |
|
@Autowired |
|
private BaseSecurity securityManager; |
|
|
|
public ChangeEMailExecuteController(UserRequest ureq, WindowControl wControl) { |
|
super(ureq, wControl); |
|
this.userRequest = ureq; |
|
pT = Util.createPackageTranslator(ProfileAndHomePageEditController.class, userRequest.getLocale()); |
|
pT = userManager.getPropertyHandlerTranslator(pT); |
|
emKey = userRequest.getHttpReq().getParameter("key"); |
|
if (emKey == null) { |
|
emKey = userRequest.getIdentity().getUser().getProperty("emchangeKey", null); |
|
} |
|
if (emKey != null) { |
|
|
|
|
|
tempKey = rm.loadTemporaryKeyByRegistrationKey(emKey); |
|
} |
|
} |
|
|
|
@Override |
|
public boolean isUserInteractionRequired(UserRequest ureq) { |
|
User user = ureq.getIdentity().getUser(); |
|
if(StringHelper.containsNonWhitespace(user.getProperty("emchangeKey", null))) { |
|
if (isLinkTimeUp()) { |
|
deleteRegistrationKey(); |
|
} else { |
|
if (isLinkClicked()) { |
|
changeEMail(getWindowControl()); |
|
} else { |
|
Boolean alreadySeen = ((Boolean)ureq.getUserSession().getEntry(PRESENTED_EMAIL_CHANGE_REMINDER)); |
|
if (alreadySeen == null) { |
|
getWindowControl().setWarning(getPackageTranslator().translate("email.change.reminder")); |
|
ureq.getUserSession().putEntry(PRESENTED_EMAIL_CHANGE_REMINDER, Boolean.TRUE); |
|
} |
|
} |
|
} |
|
} else { |
|
String value = user.getProperty("emailDisabled", null); |
|
if (value != null && value.equals("true")) { |
|
Translator translator = Util.createPackageTranslator(HomeMainController.class, ureq.getLocale()); |
|
getWindowControl().setWarning(translator.translate("email.disabled")); |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean changeEMail(WindowControl wControl) { |
|
XStream xml = XStreamHelper.createXStreamInstance(); |
|
|
|
|
|
|
|
XStreamHelper.allowDefaultPackage(xml); |
|
@SuppressWarnings("unchecked") |
|
HashMap<String, String> mails = (HashMap<String, String>) xml.fromXML(tempKey.getEmailAddress()); |
|
|
|
Identity identity = securityManager.loadIdentityByKey(tempKey.getIdentityKey()); |
|
if (identity != null) { |
|
String oldEmail = identity.getUser().getEmail(); |
|
identity.getUser().setProperty("email", mails.get("changedEMail")); |
|
|
|
|
|
String value = identity.getUser().getProperty("emailDisabled", null); |
|
if (value != null && value.equals("true")) { |
|
identity.getUser().setProperty("emailDisabled", "false"); |
|
} |
|
identity.getUser().setProperty("email", mails.get("changedEMail")); |
|
|
|
String currentEmailDisplay = userManager.getUserDisplayEmail(mails.get("currentEMail"), userRequest.getLocale()); |
|
String changedEmailDisplay = userManager.getUserDisplayEmail(mails.get("changedEMail"), userRequest.getLocale()); |
|
wControl.setInfo(pT.translate("success.change.email", new String[] { currentEmailDisplay, changedEmailDisplay })); |
|
|
|
identity.getUser().setProperty("emchangeKey", null); |
|
userRequest.getUserSession().removeEntryFromNonClearedStore(ChangeEMailController.CHANGE_EMAIL_ENTRY); |
|
securityManager.deleteInvalidAuthenticationsByEmail(oldEmail); |
|
} else { |
|
|
|
wControl.setWarning(pT.translate("error.change.email.unexpected", new String[] { mails.get("currentEMail"), mails.get("changedEMail") })); |
|
} |
|
|
|
rm.deleteTemporaryKeyWithId(tempKey.getRegistrationKey()); |
|
|
|
return true; |
|
} |
|
|
|
public boolean isLinkClicked() { |
|
Object entry = userRequest.getUserSession().getEntry(ChangeEMailController.CHANGE_EMAIL_ENTRY); |
|
return (entry != null); |
|
} |
|
|
|
public Translator getPackageTranslator() { |
|
return pT; |
|
} |
|
} |
|
|