kimptoc 01/12/27 07:11:11
Modified: src/java/org/apache/jetspeed/modules/actions JLoginUser.java
src/java/org/apache/jetspeed/modules/localization
JetspeedLocalization_en.properties
webapp/WEB-INF/conf JetspeedResources.properties
webapp/WEB-INF/templates/vm/navigations/html top.vm
Log:
basic password reminder functionality, ala bugzilla item#4142
Revision Changes Path
1.19 +104 -1
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JLoginUser.java
Index: JLoginUser.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JLoginUser.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- JLoginUser.java 2001/12/17 15:32:25 1.18
+++ JLoginUser.java 2001/12/27 15:11:10 1.19
@@ -58,9 +58,15 @@
// Java Core Classes
import java.sql.Connection;
import java.sql.SQLException;
+import java.util.Properties;
+import java.util.Locale;
+import java.io.StringWriter;
// Turbine Modules
+import org.apache.velocity.context.Context;
+import org.apache.turbine.TurbineConstants;
import org.apache.turbine.modules.Action;
+import org.apache.turbine.modules.ActionEvent;
import org.apache.turbine.modules.ActionLoader;
import org.apache.turbine.om.security.peer.RolePeer;
import org.apache.turbine.om.security.peer.TurbineUserPeer;
@@ -69,9 +75,16 @@
import org.apache.turbine.services.db.TurbineDB;
import org.apache.turbine.services.localization.Localization;
import org.apache.turbine.services.resources.TurbineResources;
+import org.apache.turbine.services.velocity.TurbineVelocity;
+import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.services.template.TurbineTemplate;
import org.apache.turbine.util.Log;
+import org.apache.turbine.util.mail.SimpleEmail;
+import org.apache.turbine.util.mail.Email;
import org.apache.turbine.util.RunData;
+import org.apache.turbine.util.DynamicURI;
+import org.apache.turbine.util.security.UnknownEntityException;
+import org.apache.jetspeed.services.TemplateLocator;
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.jetspeed.services.Profiler;
@@ -83,8 +96,98 @@
If the user is not marked as confirmed, then it will show them the
*/
-public class JLoginUser extends Action
+public class JLoginUser extends ActionEvent
{
+
+ /**
+ * called when the password reminder button is pressed.
+ * sends a user their password
+ **/
+ public void doReminder( RunData data ) throws Exception
+ {
+ try {
+ Log.debug("Entering doReminder");
+
+ //always send the user to the login screen
+ data.setScreenTemplate( JetspeedResources.getString(
TurbineConstants.TEMPLATE_LOGIN ) );
+
+ String username = data.getParameters().getString("username", "");
+
+ User user = null;
+
+ try {
+ user = JetspeedSecurity.getUser(username);
+ } catch (UnknownEntityException ignored) {
+ }
+
+ if (user == null)
+ {
+
data.setMessage(Localization.getString("JLOGINUSER_PASSWORDREMINDER_INVALIDUSER"));
+
Log.debug(Localization.getString("JLOGINUSER_PASSWORDREMINDER_INVALIDUSER"));
+ return;
+ }
+
+ user.setHasLoggedIn( new Boolean(false));
+ data.setUser(user);
+
+ DynamicURI url = new DynamicURI(data);
+
+ //build body via template
+ StringWriter email_body = new StringWriter();
+
+ Context context = TurbineVelocity.getContext();
+ context.put( "data", data );
+ context.put( "user", user );
+ context.put("userurl",url);
+ context.put("config",new JetspeedResources());
+
+ //determine the language to be used for the notification email
+ String lang = (String)user.getPerm("language");
+ String ctry = (String)user.getPerm("country");
+ Locale loc = null;
+ if (lang != null && ctry != null)
+ {
+ loc = new Locale(lang,ctry);
+ }
+
+ String templatePath = TemplateLocator.locateEmailTemplate(data,
JetspeedResources.getString("password.reminder.format"), loc);
+
+ //Criteria crit = new Criteria();
+ //String sender =
JetspeedResources.getString("newuser.confirm.email.from");
+ //crit.add ( Email.SENDER_EMAIL, sender );
+ //String senderName =
JetspeedResources.getString("newuser.confirm.email.name");
+ //crit.add ( Email.SENDER_NAME, senderName );
+ //crit.add ( Email.RECEIVER_EMAIL, user.getEmail() );
+ //crit.add ( Email.RECEIVER_NAME, user.getFirstName() + " " +
user.getLastName() );
+
+ SimpleEmail se = new SimpleEmail();
+
+ context.put("email",se);
+
+ TurbineVelocity.handleRequest(context, 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();
+
+ data.setMessage
(Localization.getString("JLOGINUSER_PASSWORDREMINDER_SENT"));
+ Log.debug(Localization.getString("JLOGINUSER_PASSWORDREMINDER_SENT"));
+
+ } catch ( Exception e )
+ {
+ String errorTitle =
Localization.getString("JLOGINUSER_PASSWORDREMINDER_ERROR") ;
+ String errorMessage = errorTitle + e.toString();
+
+ Log.error( errorMessage, e );
+ data.setMessage ( errorMessage );
+ }
+ }
+
public void doPerform( RunData data ) throws Exception
{
1.7 +4 -0
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/localization/JetspeedLocalization_en.properties
Index: JetspeedLocalization_en.properties
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/localization/JetspeedLocalization_en.properties,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JetspeedLocalization_en.properties 2001/12/22 03:03:59 1.6
+++ JetspeedLocalization_en.properties 2001/12/27 15:11:10 1.7
@@ -5,6 +5,10 @@
LOCALIZATION_MAINTAINER=Jetspeed Development Team
+JLOGINUSER_PASSWORDREMINDER_INVALIDUSER=Sorry, that username is not valid.
+JLOGINUSER_PASSWORDREMINDER_SENT=Your password has been emailed to you.
+JLOGINUSER_PASSWORDREMINDER_ERROR=Error sending password reminder:
+
CREATENEWUSERANDCONFIRM_PWNOTMATCH=Sorry, the passwords do not match.
CREATENEWUSERANDCONFIRM_NOUSERNAME=Sorry, you must supply a username.
CREATENEWUSERANDCONFIRM_NOEMAIL=Sorry, you must supply a valid email address.
1.52 +6 -1
jakarta-jetspeed/webapp/WEB-INF/conf/JetspeedResources.properties
Index: JetspeedResources.properties
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/webapp/WEB-INF/conf/JetspeedResources.properties,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- JetspeedResources.properties 2001/12/16 07:11:31 1.51
+++ JetspeedResources.properties 2001/12/27 15:11:10 1.52
@@ -1,7 +1,7 @@
################################################################################
# Jetspeed Configuration
# Author: Kevin A. Burton ([EMAIL PROTECTED])
-# $Id: JetspeedResources.properties,v 1.51 2001/12/16 07:11:31 paulsp Exp $
+# $Id: JetspeedResources.properties,v 1.52 2001/12/27 15:11:10 kimptoc Exp $
################################################################################
# This is the main file you will need to configuration Jetspeed. If there are
# any secondary files they will be pointed to from this file.
@@ -423,6 +423,11 @@
newuser.approval.enable=false
newuser.approval.accept.template=new-user-accept.vm
newuser.approval.reject.template=new-user-reject.vm
+
+# Password reminder options
+password.reminder.option.enable=false
+password.reminder.format=password-reminder.vm
+
#########################################
# Navigation Bar customization #
1.9 +7 -1
jakarta-jetspeed/webapp/WEB-INF/templates/vm/navigations/html/top.vm
Index: top.vm
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/webapp/WEB-INF/templates/vm/navigations/html/top.vm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- top.vm 2001/12/21 03:04:11 1.8
+++ top.vm 2001/12/27 15:11:11 1.9
@@ -102,7 +102,13 @@
<input value="" name="username" maxlength="25" type="text"
tabindex="1" style="font-size:10">
</td>
<td rowspan="2" align="center">
- <input name="submit" type="submit" value="Login" tabindex="3"
style="font-size:10">
+ <input name="submit" type="submit" value="Login" tabindex="3"
style="font-size:10" />
+#if ( $config.getBoolean("password.reminder.option.enable") == true )
+ <input name="eventSubmit_doReminder" type="submit" tabindex="4"
value="Password?" style="font-size:10" />
+ <br/><small>Forgotten your password?<br/>
+ Enter your username<br> and click Password?</small>
+#end
+
</td>
<td> </td>
</tr>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>