/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.registration;
import org.olat.core.configuration.OLATModule;
import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper;
import com.anthonyeden.lib.config.Configuration;
/**
* Initial Date: May 4, 2004
*
* @author gnaegi
*
* Comment:
*
*/
public class RegistrationModule implements OLATModule {
private static final String CONFIG_SELFREGISTRATION = "enable_selfregistration";
private static final String CONFIG_REGISTRATION_NOTIFICATION ="registrationNotification";
private static final String CONFIG_ADDITIONAL_CHECKBOX ="disclaimerAdditionalCheckbox";
private static final String CONFIG_ADDITIONAL_LINK ="disclaimerAdditionaLinkText";
private static boolean selfRegistrationEnabled = false;
private static String registrationNotificationEmail;
private static boolean additionalCheckbox = false;
private static boolean additionaLinkText = false;
/**
* @see org.olat.core.configuration.OLATModule#init(com.anthonyeden.lib.config.Configuration)
*/
public void init(Configuration configuration) {
String configSelfreg = configuration.getChildValue(CONFIG_SELFREGISTRATION);
selfRegistrationEnabled = configSelfreg.equalsIgnoreCase("true") ? true : false;
if (selfRegistrationEnabled) {
Tracing.logInfo("Selfregistration is turned ON", RegistrationModule.class);
} else {
Tracing.logInfo("Selfregistration is turned OFF", RegistrationModule.class);
}
// Check for registration email notification configuration
Configuration regNoti = configuration.getChild(CONFIG_REGISTRATION_NOTIFICATION);
registrationNotificationEmail = null; // default is not set
if (regNoti != null) {
String enabled = regNoti.getAttribute("enabled");
String email = regNoti.getAttribute("email");
if (!StringHelper.containsNonWhitespace(enabled)) {
Tracing.logWarn("Missing parameter 'enabled' in registrationNotification configuration element. Assuming false.", RegistrationModule.class);
} else {
if (enabled.equalsIgnoreCase("true")) {
if (!StringHelper.containsNonWhitespace(email) || email.indexOf("@") == -1) {
Tracing.logWarn("Missing parameter 'email' in registrationNotification configuration element or parameter invalid.", RegistrationModule.class);
} else {
// everything is fine, we have an email
registrationNotificationEmail = email;
}
}
}
// log finally used configuration
if (registrationNotificationEmail == null) {
Tracing.logInfo("Registration notification email is turned OFF", RegistrationModule.class);
} else {
Tracing.logInfo("Registration notification email is turned ON, email used is '" + registrationNotificationEmail + "'", RegistrationModule.class);
}
}
String configAddCheckBox = configuration.getChildValue(CONFIG_ADDITIONAL_CHECKBOX);
additionalCheckbox = configAddCheckBox.equalsIgnoreCase("true");
String configAddLink = configuration.getChildValue(CONFIG_ADDITIONAL_LINK);
additionaLinkText = configAddLink.equalsIgnoreCase("true");
}
/**
* @see org.olat.core.configuration.OLATModule#destroy()
*/
public void destroy() {
// Nothing to destroy
}
/**
* @return true if self registration is turned on, false otherwhise
*/
public static boolean isSelfRegistrationEnabled(){
return selfRegistrationEnabled;
}
/**
* Returns the notification email address that should be used in case
* of new user registrations. Returns null if no such notification
* should be applied.
* @return String or null if not configured
*/
public static String getRegistrationNotificationEmail() {
return registrationNotificationEmail;
}
/**
* @return true to add a second checkbox to the disclaimer
*/
public static boolean isDisclaimerAdditionalCheckbox() {
return additionalCheckbox;
}
/**
* @return true to add a link to the disclaimer
*/
public static boolean isDisclaimerAdditionaLinkText() {
return additionaLinkText;
}
}