Skip to content
Snippets Groups Projects
Commit 190e9792 authored by gnaegi's avatar gnaegi
Browse files

OO-335 controller creator that checks if user has a missing mandatory field

parent d215bfab
No related branches found
No related tags found
No related merge requests found
/**
* <a href=“http://www.openolat.org“>
* OpenOLAT - Online Learning and Training</a><br>
* <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 the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <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>
* Initial code contributed and copyrighted by<br>
* 28. August 2012 by frentix GmbH, http://www.frentix.com
* <p>
**/
package org.olat.user;
import java.util.List;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.creator.AutoCreator;
import org.olat.core.util.StringHelper;
import org.olat.user.propertyhandlers.UserPropertyHandler;
/**
* <h3>Description:</h3> This interceptor checks if the user has filled all
* mandatory fields of the profile form. If yes, the controller creator method
* creates the profile form controller, if no it returns null
* <p>
* Note that the controller does not actually validate each field, it only
* checks if any mandatory field is empty.
* <p>
* <h3>Events thrown by this controller:</h3>
* <p>
* none
* <p>
* Initial Date: 27.08.2012 <br>
*
* @author Florian Gnaegi, frentix GmbH, http://www.frentix.com
*/
public class ProfileAndHomePageEditIfMissingMandatoryControllerCreator
extends AutoCreator {
/*
* (non-Javadoc)
*
* @see
* org.olat.core.gui.control.creator.ControllerCreator#createController(
* org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
*/
@Override
public ProfileAndHomePageEditController createController(UserRequest lureq,
WindowControl lwControl) {
// get all userproperties from the profile form
UserManager um = UserManager.getInstance();
String usageIdentifier = ProfileFormController.class.getCanonicalName();
List<UserPropertyHandler> userPropertyHandlers = um
.getUserPropertyHandlersFor(usageIdentifier, false);
// check if all mandatory properties are set
boolean foundMissingMandatory = false; // think positive!
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (um.isMandatoryUserProperty(usageIdentifier, userPropertyHandler)) {
String curValue = userPropertyHandler.getUserProperty(lureq
.getIdentity().getUser(), lureq.getLocale());
if (!StringHelper.containsNonWhitespace(curValue)) {
foundMissingMandatory = true;
break;
}
}
}
// only create profile controller when profile contains empty mandatory
// fields
if (foundMissingMandatory) {
return new ProfileAndHomePageEditController(lureq, lwControl);
} else {
return null;
}
}
/*
* (non-Javadoc)
* @see org.olat.core.gui.control.creator.AutoCreator#getClassName()
*/
@Override
public String getClassName() {
return ProfileAndHomePageEditController.class.getName();
}
}
...@@ -178,6 +178,8 @@ ...@@ -178,6 +178,8 @@
<!-- <bean id="org.olat.user.AfterLoginConfig" class="org.olat.login.AfterLoginConfig" scope="prototype"> <!-- <bean id="org.olat.user.AfterLoginConfig" class="org.olat.login.AfterLoginConfig" scope="prototype">
<property name="afterLoginControllerList"> <property name="afterLoginControllerList">
<list> <list>
-->
<!-- Configuration to force users to regularly check and update the user profile, redoTimeout sets the interval (seconds)
<map> <map>
<entry key="controller"> <entry key="controller">
<bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype"> <bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype">
...@@ -187,8 +189,21 @@ ...@@ -187,8 +189,21 @@
<entry key="forceUser"><value>true</value></entry> <entry key="forceUser"><value>true</value></entry>
<entry key="redoTimeout"><value>10</value></entry> <entry key="redoTimeout"><value>10</value></entry>
<entry key="i18nIntro"><value>org.olat.user:runonce.profile.intro</value></entry> <entry key="i18nIntro"><value>org.olat.user:runonce.profile.intro</value></entry>
</map> --> </map>
<!-- <map> -->
<!-- Alternative configuration to force users to fill out profile if a mandatory user property is missing (no syntax checks done, only checks if property exists)
<map>
<entry key="controller">
<bean class="org.olat.user.ProfileAndHomePageEditIfMissingMandatoryControllerCreator" scope="prototype" />
</entry>
<entry key="forceUser"><value>true</value></entry>
<entry key="redoTimeout"><value>31536000</value></entry>
<entry key="i18nIntro"><value>org.olat.user:runonce.profile.intro</value></entry>
<entry key="size"><value>800x600</value></entry>
</map>
-->
<!-- Configuration to force users to change their password after the configured redoTimeout (seconds)
<map>
<entry key="controller"> <entry key="controller">
<bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype"> <bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype">
<property name="className" value="org.olat.user.ChangePasswordController"/> <property name="className" value="org.olat.user.ChangePasswordController"/>
...@@ -198,9 +213,10 @@ ...@@ -198,9 +213,10 @@
## equals 30d in seconds ## ## equals 30d in seconds ##
<entry key="redoTimeout"><value>2592000</value></entry> <entry key="redoTimeout"><value>2592000</value></entry>
<entry key="i18nIntro"><value>org.olat.user:runonce.changepw.intro</value></entry> <entry key="i18nIntro"><value>org.olat.user:runonce.changepw.intro</value></entry>
</map> --> </map>
-->
<!-- example config: <map> <!-- Documented example of the change password dialog
<map>
## specify a controller to start with default args (ureq, wControl) ## specify a controller to start with default args (ureq, wControl)
<entry key="controller"> <entry key="controller">
<bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype"> <bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype">
...@@ -215,7 +231,8 @@ ...@@ -215,7 +231,8 @@
## optional i18nKey to present an intro-text for this controller ## optional i18nKey to present an intro-text for this controller
## specify in the form of "package:i18nKey" ## specify in the form of "package:i18nKey"
<entry key="i18nIntro"><value>org.olat.user:runonce.intro</value></entry> <entry key="i18nIntro"><value>org.olat.user:runonce.intro</value></entry>
</map> --> </map>
-->
<!-- </list> <!-- </list>
</property> </property>
</bean> --> </bean> -->
......
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