You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by pa...@apache.org on 2001/11/19 08:51:06 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/security UserUpdateAction.java
paulsp 01/11/18 23:51:06
Modified: src/java/org/apache/jetspeed/modules/actions/portlets/security
UserUpdateAction.java
Log:
Adding New User Confirmation and Notification
PR: 4192
Submitted by: Chris Kimpton
Revision Changes Path
1.4 +197 -0 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/security/UserUpdateAction.java
Index: UserUpdateAction.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/security/UserUpdateAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UserUpdateAction.java 2001/07/08 03:41:35 1.3
+++ UserUpdateAction.java 2001/11/19 07:51:06 1.4
@@ -56,7 +56,12 @@
// java util
import java.util.Date;
+import java.util.Properties;
+import java.util.Locale;
+// java io
+import java.io.StringWriter;
+
// velocity context
import org.apache.velocity.context.Context;
@@ -66,16 +71,29 @@
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.DynamicURI;
+// turbine velocity
+import org.apache.turbine.services.velocity.TurbineVelocity;
+
// turbine om security
import org.apache.turbine.om.security.User;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.security.DataBackendException;
import org.apache.turbine.util.security.EntityExistsException;
+//turbine email
+import org.apache.turbine.util.mail.SimpleEmail;
+
+// turbine services
+import org.apache.turbine.services.localization.Localization;
+import org.apache.turbine.services.resources.TurbineResources;
+
// jetspeed velocity
import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction;
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
+// jetspeed services
+import org.apache.jetspeed.services.TemplateLocator;
+
// jetspeed security
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.services.resources.JetspeedResources;
@@ -84,6 +102,8 @@
* This action sets up the template context for editing users in the Turbine database.
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @author <a href="mailto:kimptoc_mail@yahoo.com">Chris Kimpton</a>
+ * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
*/
public class UserUpdateAction extends VelocityPortletAction
{
@@ -252,6 +272,183 @@
}
}
+
+ /**
+ * Database Update Action for Users. Performs accepting of new users into security database.
+ *
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ */
+ public void doAccept(RunData rundata, Context context)
+ throws Exception
+ {
+ User user = null;
+ try
+ {
+ //
+ // get the user object from the selected entry in the browser
+ //
+ user = JetspeedSecurity.getUser(
+ rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID));
+
+ user.setConfirmed(JetspeedResources.CONFIRM_VALUE);
+
+ //
+ // update the user in the database
+ //
+ JetspeedSecurity.saveUser(user);
+
+
+ //
+ // tell the user that they can now use jetspeed
+ //
+
+ DynamicURI url = new DynamicURI(rundata);
+
+ //build body via template
+ StringWriter email_body = new StringWriter();
+ SimpleEmail se = new SimpleEmail();
+ Context emailContext = TurbineVelocity.getContext();
+ emailContext.put( "data", rundata );
+ emailContext.put( "user", user );
+ emailContext.put( "config",new JetspeedResources());
+ emailContext.put( "urltojetspeed",url);
+ emailContext.put( "email",se);
+
+ //determine the language to be used for the notification email
+ String language = (String)user.getPerm("language",TurbineResources.getString("locale.default.language", "en"));
+ String country = (String)user.getPerm("country",TurbineResources.getString("locale.default.country", "US"));
+ Locale locale = new Locale(language,country);
+
+ String templateFile = JetspeedResources.getString("newuser.approval.accept.template");
+ String templatePath = TemplateLocator.locateEmailTemplate(rundata, templateFile, locale );
+ TurbineVelocity.handleRequest(emailContext, templatePath, email_body);
+
+ se.setMsg( email_body.toString() );
+
+ Properties props = System.getProperties();
+ String mailServerMachine = JetspeedResources.getString( "mail.server" );
+ props.put ( "mail.host", mailServerMachine );
+ props.put("mail.smtp.host", mailServerMachine);
+
+ se.send();
+
+ //
+ // success -- bring user back to user browser
+ //
+ DynamicURI duri = new DynamicURI (rundata);
+ duri.addPathInfo(JetspeedResources.PATH_PANEL_KEY, SecurityConstants.PANEID_USER_BROWSER);
+ rundata.getResponse().sendRedirect(duri.toString());
+
+ } catch (Exception e)
+ {
+ // log the error msg
+ Log.error(e);
+
+ //
+ // error on update - display error message
+ //
+ DynamicURI duri = new DynamicURI (rundata);
+ duri.addPathInfo(JetspeedResources.PATH_PANEL_KEY, SecurityConstants.PANEID_USER_UPDATE);
+ duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED);
+ if (user != null)
+ duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, user.getUserName());
+ duri.addQueryData(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_UPDATE);
+ rundata.getResponse().sendRedirect(duri.toString());
+ // save values that user just entered so they don't have to re-enter
+ if (user != null)
+ rundata.getUser().setTemp(TEMP_USER, user);
+ }
+ }
+
+ /**
+ * Database Update Action for Users. Performs accepting of new users into security database.
+ *
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ */
+ public void doReject(RunData rundata, Context context)
+ throws Exception
+ {
+ User user = null;
+ try
+ {
+ //
+ // get the user object from the selected entry in the browser
+ //
+ user = JetspeedSecurity.getUser(
+ rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID));
+
+ user.setConfirmed(JetspeedResources.CONFIRM_VALUE_REJECTED);
+
+ //
+ // update the user in the database
+ //
+ JetspeedSecurity.saveUser(user);
+
+
+
+ //
+ // tell the user that they can now use jetspeed
+ //
+
+ DynamicURI url = new DynamicURI(rundata);
+
+ //build body via template
+ StringWriter email_body = new StringWriter();
+ SimpleEmail se = new SimpleEmail();
+ Context emailContext = TurbineVelocity.getContext();
+ emailContext.put( "data", rundata );
+ emailContext.put( "user", user );
+ emailContext.put( "config",new JetspeedResources());
+ emailContext.put( "urltojetspeed",url);
+ emailContext.put( "email",se);
+
+ //determine the language to be used for the notification email
+ String language = (String)user.getPerm("language",TurbineResources.getString("locale.default.language", "en"));
+ String country = (String)user.getPerm("country",TurbineResources.getString("locale.default.country", "US"));
+ Locale locale = new Locale(language,country);
+
+ String templateFile = JetspeedResources.getString("newuser.approval.reject.template");
+ String templatePath = TemplateLocator.locateEmailTemplate(rundata, templateFile, locale );
+ TurbineVelocity.handleRequest(emailContext, templatePath, email_body);
+
+ se.setMsg( email_body.toString() );
+
+ Properties props = System.getProperties();
+ String mailServerMachine = JetspeedResources.getString( "mail.server" );
+ props.put ( "mail.host", mailServerMachine );
+ props.put("mail.smtp.host", mailServerMachine);
+
+ se.send();
+
+ //
+ // success -- bring user back to user browser
+ //
+ DynamicURI duri = new DynamicURI (rundata);
+ duri.addPathInfo(JetspeedResources.PATH_PANEL_KEY, SecurityConstants.PANEID_USER_BROWSER);
+ rundata.getResponse().sendRedirect(duri.toString());
+
+ } catch (Exception e)
+ {
+ // log the error msg
+ Log.error(e);
+
+ //
+ // error on update - display error message
+ //
+ DynamicURI duri = new DynamicURI (rundata);
+ duri.addPathInfo(JetspeedResources.PATH_PANEL_KEY, SecurityConstants.PANEID_USER_UPDATE);
+ duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED);
+ if (user != null)
+ duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, user.getUserName());
+ duri.addQueryData(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_UPDATE);
+ rundata.getResponse().sendRedirect(duri.toString());
+ // save values that user just entered so they don't have to re-enter
+ if (user != null)
+ rundata.getUser().setTemp(TEMP_USER, user);
+ }
+ }
/**
* Database Update Action for Users. Performs updates into security database.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>