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

OO-3717: in registration flow, place disclaimer before asking email

parent b89c99a5
No related branches found
No related tags found
No related merge requests found
...@@ -149,6 +149,7 @@ public class OLATAuthenticationController extends AuthenticationController imple ...@@ -149,6 +149,7 @@ public class OLATAuthenticationController extends AuthenticationController imple
subController = new RegistrationController(ureq, getWindowControl()); subController = new RegistrationController(ureq, getWindowControl());
listenTo(subController); listenTo(subController);
cmc = new CloseableModalController(getWindowControl(), translate("close"), subController.getInitialComponent()); cmc = new CloseableModalController(getWindowControl(), translate("close"), subController.getInitialComponent());
listenTo(cmc); listenTo(cmc);
cmc.activate(); cmc.activate();
......
...@@ -99,7 +99,7 @@ public class DisclaimerController extends BasicController { ...@@ -99,7 +99,7 @@ public class DisclaimerController extends BasicController {
listenTo(disclaimerFormController); listenTo(disclaimerFormController);
main = createVelocityContainer("disclaimer"); main = createVelocityContainer("disclaimer");
main.put("dclform", this.disclaimerFormController.getInitialComponent()); main.put("dclform", disclaimerFormController.getInitialComponent());
// add optinal download link, see class comments in DisclaimerFormController // add optinal download link, see class comments in DisclaimerFormController
// Add the additional link to the form (depending on the configuration) // Add the additional link to the form (depending on the configuration)
...@@ -108,38 +108,35 @@ public class DisclaimerController extends BasicController { ...@@ -108,38 +108,35 @@ public class DisclaimerController extends BasicController {
disclaimerDir.mkdirs(); disclaimerDir.mkdirs();
VFSContainer disclaimerContainer = new LocalFolderImpl(disclaimerDir); VFSContainer disclaimerContainer = new LocalFolderImpl(disclaimerDir);
String i18nIfiedFilename = translate("disclaimer.filedownloadurl"); String i18nIfiedFilename = translate("disclaimer.filedownloadurl");
this.downloadFile = (VFSLeaf)disclaimerContainer.resolve(i18nIfiedFilename); downloadFile = (VFSLeaf)disclaimerContainer.resolve(i18nIfiedFilename);
if (this.downloadFile != null) { if (downloadFile != null) {
this.downloadLink = LinkFactory.createLink("disclaimer.additionallinktext", main, this); downloadLink = LinkFactory.createLink("disclaimer.additionallinktext", main, this);
this.downloadLink.setTarget("_blank"); downloadLink.setTarget("_blank");
if (i18nIfiedFilename.toLowerCase().endsWith(".pdf")) { if (i18nIfiedFilename.toLowerCase().endsWith(".pdf")) {
this.downloadLink.setIconLeftCSS("o_icon o_icon-fw o_filetype_pdf"); downloadLink.setIconLeftCSS("o_icon o_icon-fw o_filetype_pdf");
} else if (i18nIfiedFilename.toLowerCase().endsWith(".html") || i18nIfiedFilename.toLowerCase().endsWith(".htm")) { } else if (i18nIfiedFilename.toLowerCase().endsWith(".html") || i18nIfiedFilename.toLowerCase().endsWith(".htm")) {
this.downloadLink.setIconLeftCSS("o_icon o_icon-fw o_filetype_html"); downloadLink.setIconLeftCSS("o_icon o_icon-fw o_filetype_html");
} else if (i18nIfiedFilename.toLowerCase().endsWith(".doc")) { } else if (i18nIfiedFilename.toLowerCase().endsWith(".doc")) {
this.downloadLink.setIconLeftCSS("o_icon o_icon-fw o_filetype_doc"); downloadLink.setIconLeftCSS("o_icon o_icon-fw o_filetype_doc");
} }
} }
} }
putInitialPanel(main); putInitialPanel(main);
} }
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override @Override
public void event(UserRequest ureq, Component source, Event event) { public void event(UserRequest ureq, Component source, Event event) {
if (source == this.downloadLink) { if (source == downloadLink) {
ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(this.downloadFile)); ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(downloadFile));
// Prevent "do not press reload" message. // Prevent "do not press reload" message.
this.downloadLink.setDirty(false); downloadLink.setDirty(false);
} }
} }
@Override @Override
protected void event(UserRequest ureq, Controller source, Event event) { protected void event(UserRequest ureq, Controller source, Event event) {
if (source == this.disclaimerFormController) { if (source == disclaimerFormController) {
if (event == Event.CANCELLED_EVENT) { if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, Event.CANCELLED_EVENT); fireEvent(ureq, Event.CANCELLED_EVENT);
} else if (event == Event.DONE_EVENT) { } else if (event == Event.DONE_EVENT) {
...@@ -175,10 +172,6 @@ public class DisclaimerController extends BasicController { ...@@ -175,10 +172,6 @@ public class DisclaimerController extends BasicController {
main.put("dclform", this.disclaimerFormController.getInitialComponent()); main.put("dclform", this.disclaimerFormController.getInitialComponent());
} }
/**
*
* @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
*/
@Override @Override
protected void doDispose() { protected void doDispose() {
// //
......
...@@ -51,8 +51,10 @@ public class DisclaimerFormController extends FormBasicController { ...@@ -51,8 +51,10 @@ public class DisclaimerFormController extends FormBasicController {
private static final String ACKNOWLEDGE_CHECKBOX_NAME = "acknowledge_checkbox"; private static final String ACKNOWLEDGE_CHECKBOX_NAME = "acknowledge_checkbox";
private static final String ADDITIONAL_CHECKBOX_NAME = "additional_checkbox"; private static final String ADDITIONAL_CHECKBOX_NAME = "additional_checkbox";
private static final String ADDITIONAL_CHECKBOX_2_NAME = "additional_checkbox_2"; private static final String ADDITIONAL_CHECKBOX_2_NAME = "additional_checkbox_2";
protected MultipleSelectionElement acceptCheckbox; protected MultipleSelectionElement acceptCheckbox;
protected MultipleSelectionElement additionalCheckbox, additionalCheckbox2; protected MultipleSelectionElement additionalCheckbox;
protected MultipleSelectionElement additionalCheckbox2;
private boolean readOnly; private boolean readOnly;
@Autowired @Autowired
...@@ -118,9 +120,10 @@ public class DisclaimerFormController extends FormBasicController { ...@@ -118,9 +120,10 @@ public class DisclaimerFormController extends FormBasicController {
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator()); final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
formLayout.add(buttonLayout); formLayout.add(buttonLayout);
buttonLayout.setElementCssClass("o_sel_disclaimer_buttons"); buttonLayout.setElementCssClass("o_sel_disclaimer_buttons");
uifactory.addFormSubmitButton(DCL_ACCEPT, NLS_DISCLAIMER_OK, buttonLayout);
FormCancel cancelButton = uifactory.addFormCancelButton(NLS_DISCLAIMER_NOK, buttonLayout, ureq, getWindowControl()); FormCancel cancelButton = uifactory.addFormCancelButton(NLS_DISCLAIMER_NOK, buttonLayout, ureq, getWindowControl());
cancelButton.setI18nKey(NLS_DISCLAIMER_NOK); cancelButton.setI18nKey(NLS_DISCLAIMER_NOK);
uifactory.addFormSubmitButton(DCL_ACCEPT, NLS_DISCLAIMER_OK, buttonLayout);
} }
} }
} }
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package org.olat.registration; package org.olat.registration;
import org.olat.core.CoreSpringFactory;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.flexible.FormItemContainer; import org.olat.core.gui.components.form.flexible.FormItemContainer;
import org.olat.core.gui.components.form.flexible.elements.TextElement; import org.olat.core.gui.components.form.flexible.elements.TextElement;
...@@ -35,29 +34,25 @@ import org.olat.core.gui.control.Controller; ...@@ -35,29 +34,25 @@ import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event; import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.WindowControl;
import org.olat.core.util.mail.MailHelper; import org.olat.core.util.mail.MailHelper;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* description of first registration form for email-address * Simple form to get an email address.
* *
* @author Sabina Jeger * @author Sabina Jeger
*/ */
public class EmailSendingForm extends FormBasicController { public class EmailSendingForm extends FormBasicController {
private TextElement mail; private TextElement mail;
private final RegistrationManager registrationManager;
@Autowired
private RegistrationManager registrationManager;
public EmailSendingForm(UserRequest ureq, WindowControl wControl) { public EmailSendingForm(UserRequest ureq, WindowControl wControl) {
super(ureq, wControl); super(ureq, wControl);
registrationManager = CoreSpringFactory.getImpl(RegistrationManager.class);
initForm(ureq); initForm(ureq);
} }
/**
* Initialize the form
*/
@Override @Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
mail = uifactory.addTextElement("mail", "email.address", 255, "", formLayout); mail = uifactory.addTextElement("mail", "email.address", 255, "", formLayout);
...@@ -66,8 +61,8 @@ public class EmailSendingForm extends FormBasicController { ...@@ -66,8 +61,8 @@ public class EmailSendingForm extends FormBasicController {
// Button layout // Button layout
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator()); final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout); formLayout.add(buttonLayout);
uifactory.addFormSubmitButton("submit.speichernUndweiter", buttonLayout);
uifactory.addFormCancelButton("submit.cancel", buttonLayout, ureq, getWindowControl()); uifactory.addFormCancelButton("submit.cancel", buttonLayout, ureq, getWindowControl());
uifactory.addFormSubmitButton("submit.speichernUndweiter", buttonLayout);
} }
protected String getEmailAddress() { protected String getEmailAddress() {
...@@ -76,7 +71,7 @@ public class EmailSendingForm extends FormBasicController { ...@@ -76,7 +71,7 @@ public class EmailSendingForm extends FormBasicController {
@Override @Override
public boolean validateFormLogic(UserRequest ureq) { public boolean validateFormLogic(UserRequest ureq) {
boolean allOk = true; boolean allOk = super.validateFormLogic(ureq);
if (mail.isEmpty("email.address.maynotbeempty")) { if (mail.isEmpty("email.address.maynotbeempty")) {
allOk &= false; allOk &= false;
...@@ -93,9 +88,10 @@ public class EmailSendingForm extends FormBasicController { ...@@ -93,9 +88,10 @@ public class EmailSendingForm extends FormBasicController {
allOk &= valid; allOk &= valid;
} }
return allOk && super.validateFormLogic(ureq); return allOk;
} }
@Override
protected void formOK(UserRequest ureq) { protected void formOK(UserRequest ureq) {
fireEvent(ureq, Event.DONE_EVENT); fireEvent(ureq, Event.DONE_EVENT);
} }
......
...@@ -73,9 +73,6 @@ public class LanguageChooserController extends FormBasicController { ...@@ -73,9 +73,6 @@ public class LanguageChooserController extends FormBasicController {
initForm(ureq); initForm(ureq);
} }
/**
* @see org.olat.core.gui.components.form.flexible.FormDefaultController#formOK(org.olat.core.gui.UserRequest)
*/
@Override @Override
protected void formOK(UserRequest ureq) { protected void formOK(UserRequest ureq) {
fireEvent(ureq, Event.DONE_EVENT); fireEvent(ureq, Event.DONE_EVENT);
...@@ -86,11 +83,6 @@ public class LanguageChooserController extends FormBasicController { ...@@ -86,11 +83,6 @@ public class LanguageChooserController extends FormBasicController {
fireEvent(ureq, Event.CANCELLED_EVENT); fireEvent(ureq, Event.CANCELLED_EVENT);
} }
/**
* @see org.olat.core.gui.components.form.flexible.FormDefaultController#formInnerEvent(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.form.flexible.FormItem,
* org.olat.core.gui.components.form.flexible.FormEvent)
*/
@Override @Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if(source == langs) { if(source == langs) {
...@@ -118,10 +110,6 @@ public class LanguageChooserController extends FormBasicController { ...@@ -118,10 +110,6 @@ public class LanguageChooserController extends FormBasicController {
return langs.getSelectedKey(); return langs.getSelectedKey();
} }
/**
* @see org.olat.core.gui.components.form.flexible.FormDefaultController#initFormElements(org.olat.core.gui.components.form.flexible.FormItemContainer,
* org.olat.core.gui.control.Controller)
*/
@Override @Override
protected void initForm(FormItemContainer formLayout, Controller listener, final UserRequest ureq) { protected void initForm(FormItemContainer formLayout, Controller listener, final UserRequest ureq) {
Map<String, String> languages = i18nManager.getEnabledLanguagesTranslated(); Map<String, String> languages = i18nManager.getEnabledLanguagesTranslated();
...@@ -135,13 +123,10 @@ public class LanguageChooserController extends FormBasicController { ...@@ -135,13 +123,10 @@ public class LanguageChooserController extends FormBasicController {
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator()); final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
formLayout.add(buttonLayout); formLayout.add(buttonLayout);
nextButton = uifactory.addFormSubmitButton("submit.weiter", buttonLayout);
uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl()); uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
nextButton = uifactory.addFormSubmitButton("submit.weiter", buttonLayout);
} }
/**
* @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
*/
@Override @Override
protected void doDispose() { protected void doDispose() {
langs = null; langs = null;
......
...@@ -23,7 +23,6 @@ package org.olat.registration; ...@@ -23,7 +23,6 @@ package org.olat.registration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.olat.core.CoreSpringFactory;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.ValidationError; import org.olat.core.gui.components.form.ValidationError;
import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItem;
...@@ -42,6 +41,7 @@ import org.olat.core.util.StringHelper; ...@@ -42,6 +41,7 @@ import org.olat.core.util.StringHelper;
import org.olat.user.UserPropertiesConfig; import org.olat.user.UserPropertiesConfig;
import org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler; import org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler;
import org.olat.user.propertyhandlers.UserPropertyHandler; import org.olat.user.propertyhandlers.UserPropertyHandler;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* Admin panel to configure the registration settings: should link appear on the login page... * Admin panel to configure the registration settings: should link appear on the login page...
...@@ -64,24 +64,23 @@ public class RegistrationAdminController extends FormBasicController { ...@@ -64,24 +64,23 @@ public class RegistrationAdminController extends FormBasicController {
private FormLayoutContainer staticPropContainer; private FormLayoutContainer staticPropContainer;
private static final String[] enableRegistrationKeys = new String[]{ "on" }; private static final String[] enableRegistrationKeys = new String[]{ "on" };
private static final String[] enableRegistrationValues = new String[1]; private String[] propertyKeys;
private String[] propertyKeys, propertyValues; private String[] propertyValues;
private final RegistrationModule registrationModule; @Autowired
private final RegistrationManager registrationManager; private RegistrationModule registrationModule;
private final UserPropertiesConfig userPropertiesConfig; @Autowired
private RegistrationManager registrationManager;
@Autowired
private UserPropertiesConfig userPropertiesConfig;
private final Translator userPropTranslator; private final Translator userPropTranslator;
public RegistrationAdminController(UserRequest ureq, WindowControl wControl) { public RegistrationAdminController(UserRequest ureq, WindowControl wControl) {
super(ureq, wControl, "admin"); super(ureq, wControl, "admin");
registrationModule = CoreSpringFactory.getImpl(RegistrationModule.class);
registrationManager = CoreSpringFactory.getImpl(RegistrationManager.class);
userPropertiesConfig = CoreSpringFactory.getImpl(UserPropertiesConfig.class);
//decorate the translator //decorate the translator
userPropTranslator = userPropertiesConfig.getTranslator(getTranslator()); userPropTranslator = userPropertiesConfig.getTranslator(getTranslator());
enableRegistrationValues[0] = translate("admin.enableRegistration.on");
List<UserPropertyHandler> allPropertyHandlers = userPropertiesConfig.getAllUserPropertyHandlers(); List<UserPropertyHandler> allPropertyHandlers = userPropertiesConfig.getAllUserPropertyHandlers();
List<UserPropertyHandler> propertyHandlers = new ArrayList<>(allPropertyHandlers.size()); List<UserPropertyHandler> propertyHandlers = new ArrayList<>(allPropertyHandlers.size());
...@@ -106,6 +105,7 @@ public class RegistrationAdminController extends FormBasicController { ...@@ -106,6 +105,7 @@ public class RegistrationAdminController extends FormBasicController {
@Override @Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String[] enableRegistrationValues = new String[] { translate("admin.enableRegistration.on") };
//settings //settings
FormLayoutContainer settingsContainer = FormLayoutContainer.createDefaultFormLayout("settings", getTranslator()); FormLayoutContainer settingsContainer = FormLayoutContainer.createDefaultFormLayout("settings", getTranslator());
......
...@@ -89,16 +89,18 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -89,16 +89,18 @@ public class RegistrationController extends BasicController implements Activatea
private static final String SEPARATOR = "____________________________________________________________________\n"; private static final String SEPARATOR = "____________________________________________________________________\n";
private VelocityContainer myContent;
private Panel regarea; private Panel regarea;
private Link loginButton; private Link loginButton;
private VelocityContainer myContent;
private WizardInfoController wizInfoController; private WizardInfoController wizInfoController;
private DisclaimerController disclaimerController; private DisclaimerController disclaimerController;
private EmailSendingForm emailSendForm; private EmailSendingForm emailSendForm;
private RegistrationForm2 registrationForm; private RegistrationForm2 registrationForm;
private LanguageChooserController langChooserController; private LanguageChooserController langChooserController;
private String uniqueRegistrationKey;
private TemporaryKey tempKey; private TemporaryKey tempKey;
private String uniqueRegistrationKey;
@Autowired @Autowired
private I18nModule i18nModule; private I18nModule i18nModule;
...@@ -118,7 +120,7 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -118,7 +120,7 @@ public class RegistrationController extends BasicController implements Activatea
private RegistrationManager registrationManager; private RegistrationManager registrationManager;
/** /**
* Controller implementing registration work flow. * Controller implementing registration workflow.
* @param ureq * @param ureq
* @param wControl * @param wControl
*/ */
...@@ -162,13 +164,7 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -162,13 +164,7 @@ public class RegistrationController extends BasicController implements Activatea
// no temporary key is given, we assume step 1. If this is the case, we // no temporary key is given, we assume step 1. If this is the case, we
// render in a modal dialog, no need to add the 3cols layout controller // render in a modal dialog, no need to add the 3cols layout controller
// wrapper // wrapper
//fxdiff FXOLAT-113: business path in DMZ displayLanguageChooserStep(ureq);
if(i18nModule.getEnabledLanguageKeys().size() == 1) {
wizInfoController.setCurStep(2);
createEmailForm(ureq);
} else {
createLanguageForm(ureq, wControl);
}
putInitialPanel(myContent); putInitialPanel(myContent);
} else { } else {
// we check if given key is a valid temporary key // we check if given key is a valid temporary key
...@@ -177,49 +173,9 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -177,49 +173,9 @@ public class RegistrationController extends BasicController implements Activatea
if (tempKey == null) { if (tempKey == null) {
// error, there should be an entry // error, there should be an entry
showError("regkey.missingentry"); showError("regkey.missingentry");
//fxdiff FXOLAT-113: business path in DMZ displayLanguageChooserStep(ureq);
if(i18nModule.getEnabledLanguageKeys().size() == 1) {
wizInfoController.setCurStep(2);
createEmailForm(ureq);
} else {
createLanguageForm(ureq, wControl);
}
} else { } else {
wizInfoController.setCurStep(3); displayRegistrationForm2(ureq);
myContent.contextPut("pwdhelp", translate("pwdhelp"));
myContent.contextPut("loginhelp", translate("loginhelp"));
myContent.contextPut("text", translate("step3.reg.text"));
myContent.contextPut("email", tempKey.getEmailAddress());
Map<String,String> userAttrs = new HashMap<String,String>();
userAttrs.put("email", tempKey.getEmailAddress());
if(registrationModule.getUsernamePresetBean() != null) {
UserNameCreationInterceptor interceptor = registrationModule.getUsernamePresetBean();
String proposedUsername = interceptor.getUsernameFor(userAttrs);
if(proposedUsername == null) {
if(interceptor.allowChangeOfUsername()) {
createRegForm2(ureq, null, false, false);
} else {
myContent = setErrorPage("reg.error.no_username", wControl);
}
} else {
Identity identity = securityManager.findIdentityByName(proposedUsername);
if(identity != null) {
if(interceptor.allowChangeOfUsername()) {
createRegForm2(ureq, proposedUsername, true, false);
} else {
myContent = setErrorPage("reg.error.user_in_use", wControl);
}
} else if (interceptor.allowChangeOfUsername()) {
createRegForm2(ureq, proposedUsername, false, false);
} else {
createRegForm2(ureq, proposedUsername, false, true);
}
}
} else {
createRegForm2(ureq, null, false, false);
}
} }
// load view in layout // load view in layout
LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), null, myContent, null); LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), null, myContent, null);
...@@ -254,21 +210,9 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -254,21 +210,9 @@ public class RegistrationController extends BasicController implements Activatea
regarea.setContent(langChooserController.getInitialComponent()); regarea.setContent(langChooserController.getInitialComponent());
} }
/**
* just needed for creating EmailForm
*/
private void createEmailForm(UserRequest ureq) {
removeAsListenerAndDispose(emailSendForm);
emailSendForm = new EmailSendingForm(ureq, getWindowControl());
listenTo(emailSendForm);
myContent.contextPut("text", translate("step1.reg.text"));
regarea.setContent(emailSendForm.getInitialComponent());
}
@Override @Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) { public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
if(entries == null || entries.isEmpty()) return; //
} }
@Override @Override
...@@ -279,142 +223,213 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -279,142 +223,213 @@ public class RegistrationController extends BasicController implements Activatea
} }
} }
/**
* @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)
*/
@Override @Override
public void event(UserRequest ureq, Controller source, Event event) { public void event(UserRequest ureq, Controller source, Event event) {
if (source == emailSendForm) { if (source == langChooserController) {
if (event == Event.DONE_EVENT) { // form
// validation
// was ok
wizInfoController.setCurStep(2);
// Email requested for tempkey
//save the fields somewhere
String email = emailSendForm.getEmailAddress();
myContent.contextPut("email", email);
myContent.contextPut("text", translate("step2.reg.text", email));
//ef.setVisible(false);
regarea.setVisible(false);
// get remote address
String ip = ureq.getHttpReq().getRemoteAddr();
String serverpath = Settings.getServerContextPathURI();
String today = DateFormat.getDateInstance(DateFormat.LONG, ureq.getLocale()).format(new Date());
String[] whereFromAttrs = new String[]{
serverpath, today, ip
};
boolean isMailSent = false;
if (registrationManager.isRegistrationPending(email) || UserManager.getInstance().isEmailAllowed(email)) {
TemporaryKey tk = null;
if (userModule.isEmailUnique()) {
tk = registrationManager.loadTemporaryKeyByEmail(email);
}
if (tk == null) {
tk = registrationManager.loadOrCreateTemporaryKeyByEmail(email, ip,
RegistrationManager.REGISTRATION, registrationModule.getValidUntilHoursGui());
}
myContent.contextPut("regKey", tk.getRegistrationKey());
String link = serverpath + "/dmz/registration/index.html?key=" + tk.getRegistrationKey() + "&language=" + i18nModule.getLocaleKey(ureq.getLocale());
String[] bodyAttrs = new String[]{
serverpath, //0
tk.getRegistrationKey(), //1
i18nModule.getLocaleKey(ureq.getLocale()), //2
"<a href=\"" + link + "\">" + link + "</a>" //3
};
String body = translate("reg.body", bodyAttrs);
boolean htmlBody = StringHelper.isHtml(body);
if(!htmlBody) {
body += SEPARATOR + translate("reg.wherefrom", whereFromAttrs);
}
try {
MailBundle bundle = new MailBundle();
bundle.setTo(email);
bundle.setContent(translate("reg.subject"), body);
MailerResult result = mailManager.sendExternMessage(bundle, null, htmlBody);
if (result.isSuccessful()) {
isMailSent = true;
}
} catch (Exception e) {
// nothing to do, emailSent flag is false, errors will be reported to user
}
} else {
// if users with this email address exists, they are informed.
List<Identity> identities = UserManager.getInstance().findIdentitiesByEmail(Collections.singletonList(email));
for (Identity identity: identities) {
String body = translate("login.body", identity.getName()) + SEPARATOR + translate("reg.wherefrom", whereFromAttrs);
try {
MailBundle bundle = new MailBundle();
bundle.setTo(email);
bundle.setContent(translate("login.subject"), body);
MailerResult result = mailManager.sendExternMessage(bundle, null, true);
if (result.isSuccessful()) {
isMailSent = true;
}
} catch (Exception e) {
// nothing to do, emailSent flag is false, errors will be reported to user
}
}
}
if (isMailSent) {
showInfo("email.sent");
} else {
showError("email.notsent");
}
} else if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, Event.CANCELLED_EVENT);
}
} else if (source == langChooserController) {
if (event == Event.DONE_EVENT) { if (event == Event.DONE_EVENT) {
wizInfoController.setCurStep(2); displayDisclaimer(ureq);
createEmailForm(ureq);
ureq.getUserSession().removeEntry(LocaleNegotiator.NEGOTIATED_LOCALE); ureq.getUserSession().removeEntry(LocaleNegotiator.NEGOTIATED_LOCALE);
} else if (event == Event.CANCELLED_EVENT) { } else if (event == Event.CANCELLED_EVENT) {
ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(Settings.getServerContextPathURI())); cancel(ureq);
} else if (event instanceof LanguageChangedEvent) { } else if (event instanceof LanguageChangedEvent) {
LanguageChangedEvent lcev = (LanguageChangedEvent)event; LanguageChangedEvent lcev = (LanguageChangedEvent)event;
setLocale(lcev.getNewLocale(), true); setLocale(lcev.getNewLocale(), true);
myContent.contextPut("text", translate("select.language.description")); myContent.contextPut("text", translate("select.language.description"));
} }
} else if (source == registrationForm) { } else if (source == disclaimerController) {
// Userdata entered
if (event == Event.DONE_EVENT) { if (event == Event.DONE_EVENT) {
String lang = registrationForm.getLangKey(); // finalize the registration by creating the user
// change language if different then current language displayEmailForm(ureq);
if (! lang.equals(i18nModule.getLocaleKey(ureq.getLocale()))) { } else if (event == Event.CANCELLED_EVENT) {
Locale loc = i18nManager.getLocaleOrDefault(lang); cancel(ureq);
ureq.getUserSession().setLocale(loc); }
getTranslator().setLocale(loc); } else if (source == emailSendForm) {
if (event == Event.DONE_EVENT) { // form
boolean isMailSent = processEmail(ureq);
if (isMailSent) {
showInfo("email.sent");
} else {
showError("email.notsent");
} }
wizInfoController.setCurStep(4);
myContent.contextPut("pwdhelp", "");
myContent.contextPut("loginhelp", "");
myContent.contextPut("text", translate("step4.reg.text"));
removeAsListenerAndDispose(disclaimerController);
disclaimerController = new DisclaimerController(ureq, getWindowControl());
listenTo(disclaimerController);
regarea.setContent(disclaimerController.getInitialComponent());
} else if (event == Event.CANCELLED_EVENT) { } else if (event == Event.CANCELLED_EVENT) {
ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(Settings.getServerContextPathURI())); fireEvent(ureq, Event.CANCELLED_EVENT);
} }
} else if (source == disclaimerController) { } else if (source == registrationForm) {
// Userdata entered
if (event == Event.DONE_EVENT) { if (event == Event.DONE_EVENT) {
// finalize the registration by creating the user
Identity persitedIdentity = createNewUserAfterRegistration(); Identity persitedIdentity = createNewUserAfterRegistration();
// display step5 if(persitedIdentity == null) {
displayFinalStep(persitedIdentity); cancel(ureq);
} else {
displayFinalStep(persitedIdentity);
}
} else if (event == Event.CANCELLED_EVENT) { } else if (event == Event.CANCELLED_EVENT) {
ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(Settings.getServerContextPathURI())); cancel(ureq);
} }
}
}
private void cancel(UserRequest ureq) {
ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(Settings.getServerContextPathURI()));
}
/**
* Display the language chooser or jump to the email form if
* not needed.
*
* @param ureq The user request
*/
private void displayLanguageChooserStep(UserRequest ureq) {
if(i18nModule.getEnabledLanguageKeys().size() == 1) {
displayDisclaimer(ureq);
} else {
createLanguageForm(ureq, getWindowControl());
} }
}
/**
* Display the disclaimer if enabled, else jump to the
* email form.
*
* @param ureq The user request
*/
private void displayDisclaimer(UserRequest ureq) {
if(registrationModule.isDisclaimerEnabled()) {
wizInfoController.setCurStep(2);
myContent.contextPut("pwdhelp", "");
myContent.contextPut("loginhelp", "");
myContent.contextPut("text", translate("step4.reg.text"));
removeAsListenerAndDispose(disclaimerController);
disclaimerController = new DisclaimerController(ureq, getWindowControl());
listenTo(disclaimerController);
regarea.setContent(disclaimerController.getInitialComponent());
} else {
displayEmailForm(ureq);
}
}
private void displayEmailForm(UserRequest ureq) {
wizInfoController.setCurStep(3);
removeAsListenerAndDispose(emailSendForm);
emailSendForm = new EmailSendingForm(ureq, getWindowControl());
listenTo(emailSendForm);
myContent.contextPut("text", translate("step1.reg.text"));
regarea.setContent(emailSendForm.getInitialComponent());
}
private boolean processEmail(UserRequest ureq) {
// validation
// was ok
wizInfoController.setCurStep(3);
// Email requested for tempkey
//save the fields somewhere
String email = emailSendForm.getEmailAddress();
myContent.contextPut("email", email);
myContent.contextPut("text", translate("step2.reg.text", email));
regarea.setVisible(false);
// get remote address
String ip = ureq.getHttpReq().getRemoteAddr();
String serverpath = Settings.getServerContextPathURI();
String today = DateFormat.getDateInstance(DateFormat.LONG, ureq.getLocale()).format(new Date());
String[] whereFromAttrs = new String[]{
serverpath, today, ip
};
boolean isMailSent = false;
if (registrationManager.isRegistrationPending(email) || userManager.isEmailAllowed(email)) {
TemporaryKey tk = null;
if (userModule.isEmailUnique()) {
tk = registrationManager.loadTemporaryKeyByEmail(email);
}
if (tk == null) {
tk = registrationManager.loadOrCreateTemporaryKeyByEmail(email, ip,
RegistrationManager.REGISTRATION, registrationModule.getValidUntilHoursGui());
}
myContent.contextPut("regKey", tk.getRegistrationKey());
String link = serverpath + "/dmz/registration/index.html?key=" + tk.getRegistrationKey() + "&language=" + i18nModule.getLocaleKey(ureq.getLocale());
String[] bodyAttrs = new String[]{
serverpath, //0
tk.getRegistrationKey(), //1
i18nModule.getLocaleKey(ureq.getLocale()), //2
"<a href=\"" + link + "\">" + link + "</a>" //3
};
String body = translate("reg.body", bodyAttrs);
boolean htmlBody = StringHelper.isHtml(body);
if(!htmlBody) {
body += SEPARATOR + translate("reg.wherefrom", whereFromAttrs);
}
sendMessage(email, translate("reg.subject"), body);
} else {
// if users with this email address exists, they are informed.
List<Identity> identities = userManager.findIdentitiesByEmail(Collections.singletonList(email));
for (Identity identity: identities) {
String subject = translate("login.subject");
String body = translate("login.body", identity.getName()) + SEPARATOR + translate("reg.wherefrom", whereFromAttrs);
sendMessage(email, subject, body);
}
}
return isMailSent;
}
private boolean sendMessage(String email, String subject, String body) {
boolean isMailSent = false;
try {
MailBundle bundle = new MailBundle();
bundle.setTo(email);
bundle.setContent(subject, body);
boolean htmlBody = StringHelper.isHtml(body);
MailerResult result = mailManager.sendExternMessage(bundle, null, htmlBody);
if (result.isSuccessful()) {
isMailSent = true;
}
} catch (Exception e) {
// nothing to do, emailSent flag is false, errors will be reported to user
}
return isMailSent;
}
private void displayRegistrationForm2(UserRequest ureq) {
wizInfoController.setCurStep(4);
myContent.contextPut("pwdhelp", translate("pwdhelp"));
myContent.contextPut("loginhelp", translate("loginhelp"));
myContent.contextPut("text", translate("step3.reg.text"));
myContent.contextPut("email", tempKey.getEmailAddress());
Map<String,String> userAttrs = new HashMap<>();
userAttrs.put("email", tempKey.getEmailAddress());
if(registrationModule.getUsernamePresetBean() != null) {
UserNameCreationInterceptor interceptor = registrationModule.getUsernamePresetBean();
String proposedUsername = interceptor.getUsernameFor(userAttrs);
if(proposedUsername == null) {
if(interceptor.allowChangeOfUsername()) {
createRegForm2(ureq, null, false, false);
} else {
myContent = setErrorPage("reg.error.no_username", getWindowControl());
}
} else {
Identity identity = securityManager.findIdentityByName(proposedUsername);
if(identity != null) {
if(interceptor.allowChangeOfUsername()) {
createRegForm2(ureq, proposedUsername, true, false);
} else {
myContent = setErrorPage("reg.error.user_in_use", getWindowControl());
}
} else {
createRegForm2(ureq, proposedUsername, false, !interceptor.allowChangeOfUsername());
}
}
} else {
createRegForm2(ureq, null, false, false);
}
} }
/** /**
...@@ -439,7 +454,7 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -439,7 +454,7 @@ public class RegistrationController extends BasicController implements Activatea
// show last screen // show last screen
VelocityContainer finishVC = createVelocityContainer("finish"); VelocityContainer finishVC = createVelocityContainer("finish");
List<UserPropertyHandler> userPropertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false); List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false);
finishVC.contextPut("userPropertyHandlers", userPropertyHandlers); finishVC.contextPut("userPropertyHandlers", userPropertyHandlers);
finishVC.contextPut("user", persitedIdentity.getUser()); finishVC.contextPut("user", persitedIdentity.getUser());
finishVC.contextPut("locale", getLocale()); finishVC.contextPut("locale", getLocale());
...@@ -461,8 +476,7 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -461,8 +476,7 @@ public class RegistrationController extends BasicController implements Activatea
*/ */
private Identity createNewUserAfterRegistration() { private Identity createNewUserAfterRegistration() {
// create user with mandatory fields from registration-form // create user with mandatory fields from registration-form
UserManager um = UserManager.getInstance(); User volatileUser = userManager.createUser(registrationForm.getFirstName(), registrationForm.getLastName(), tempKey.getEmailAddress());
User volatileUser = um.createUser(registrationForm.getFirstName(), registrationForm.getLastName(), tempKey.getEmailAddress());
// set user configured language // set user configured language
Preferences preferences = volatileUser.getPreferences(); Preferences preferences = volatileUser.getPreferences();
...@@ -477,7 +491,7 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -477,7 +491,7 @@ public class RegistrationController extends BasicController implements Activatea
return null; return null;
} else { } else {
// update other user properties from form // update other user properties from form
List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false); List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false);
User persistedUser = persistedIdentity.getUser(); User persistedUser = persistedIdentity.getUser();
//add eventually static value //add eventually static value
...@@ -501,7 +515,7 @@ public class RegistrationController extends BasicController implements Activatea ...@@ -501,7 +515,7 @@ public class RegistrationController extends BasicController implements Activatea
userPropertyHandler.updateUserFromFormItem(persistedUser, fi); userPropertyHandler.updateUserFromFormItem(persistedUser, fi);
} }
// persist changes in db // persist changes in db
um.updateUserFromIdentity(persistedIdentity); userManager.updateUserFromIdentity(persistedIdentity);
// send notification mail to sys admin // send notification mail to sys admin
String notiEmail = CoreSpringFactory.getImpl(RegistrationModule.class).getRegistrationNotificationEmail(); String notiEmail = CoreSpringFactory.getImpl(RegistrationModule.class).getRegistrationNotificationEmail();
if (notiEmail != null) { if (notiEmail != 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