String ip = ureq.getHttpReq().getRemoteAddr();
String today = DateFormat.getDateInstance(DateFormat.LONG, ureq.getLocale()).format(new Date());
// mailer configuration
String serverpath = Settings.getServerContextPathURI();
String servername = ureq.getHttpReq().getServerName();
Emailer mailer = new Emailer(ureq.getLocale());
Tracing.createLoggerFor(ProfileAndHomePageEditController.class).debug("this servername is " + servername + " and serverpath is " + serverpath);
// load or create temporary key
HashMap<String, String> mailMap = new HashMap<String, String>();
mailMap.put("currentEMail", currentEmail);
mailMap.put("changedEMail", changedEmail);
XStream xml = new XStream();
String serMailMap = xml.toXML(mailMap);
TemporaryKey tk = loadCleanTemporaryKey(serMailMap);
if (tk == null) {
tk = rm.createTemporaryKeyByEmail(serMailMap, ip, RegistrationManager.EMAIL_CHANGE);
} else {
rm.deleteTemporaryKeyWithId(tk.getRegistrationKey());
tk = rm.createTemporaryKeyByEmail(serMailMap, ip, RegistrationManager.EMAIL_CHANGE);
}
// create date, time string
Calendar cal = Calendar.getInstance();
cal.setTime(tk.getCreationDate());
cal.add(Calendar.DAY_OF_WEEK, ChangeEMailController.TIME_OUT);
String time = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, ureq.getLocale()).format(cal.getTime());
// create body and subject for email
body = this.translator.translate("email.change.body", new String[] { serverpath + "/dmz/emchange/index.html?key=" + tk.getRegistrationKey() + "&lang=" + ureq.getLocale().getLanguage(), time })
+ SEPARATOR + this.translator.translate("email.change.wherefrom", new String[] { serverpath, today, ip });
subject = translate("email.change.subject");
// send email
try {
boolean isMailSent = mailer.sendEmail(changedEmail, subject, body);
if (isMailSent) {
tk.setMailSent(true);
// set key
User user = this.identityToModify.getUser();
user.setProperty("emchangeKey", tk.getRegistrationKey());