Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java?rev=905899&view=auto ============================================================================== --- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java (added) +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java Wed Feb 3 05:27:01 2010 @@ -0,0 +1,171 @@ +/* + JSPWiki - a JSP-based WikiWiki clone. + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +package org.apache.wiki.action; + +import java.text.MessageFormat; +import java.util.List; +import java.util.ResourceBundle; + +import javax.mail.AuthenticationFailedException; +import javax.mail.SendFailedException; + +import net.sourceforge.stripes.action.*; +import net.sourceforge.stripes.validation.LocalizableError; +import net.sourceforge.stripes.validation.Validate; +import net.sourceforge.stripes.validation.ValidationErrors; + +import org.apache.wiki.WikiContext; +import org.apache.wiki.WikiEngine; +import org.apache.wiki.auth.NoSuchPrincipalException; +import org.apache.wiki.auth.user.UserDatabase; +import org.apache.wiki.auth.user.UserProfile; +import org.apache.wiki.log.Logger; +import org.apache.wiki.log.LoggerFactory; +import org.apache.wiki.util.MailUtil; +import org.apache.wiki.util.TextUtil; + +/** + * Resets user passwords. + */ +...@urlbinding( "/LostPassword.jsp" ) +public class LostPasswordActionBean extends AbstractActionBean +{ + private static final Logger log = LoggerFactory.getLogger( LostPasswordActionBean.class ); + + private String m_email = null; + + /** + * Returns the e-mail address. + * + * @return the e-mail address + */ + public String getEmail() + { + return m_email; + } + + /** + * Event handler that resets the user's password, based on the e-mail + * address returned by {...@link #getEmail()}. + * + * @return always returns <code>null</code> + */ + @HandlesEvent( "reset" ) + public Resolution reset() + { + String messageKey = null; + ResourceBundle rb = getContext().getBundle( "CoreResources" ); + + // Reset pw for account name + WikiEngine engine = getContext().getEngine(); + boolean success = false; + + try + { + // Look up the e-mail supplied by the user + UserDatabase userDatabase = engine.getUserManager().getUserDatabase(); + UserProfile profile = userDatabase.findByEmail( m_email ); + String email = profile.getEmail(); + String randomPassword = TextUtil.generateRandomPassword(); + + // Compose the message e-mail body + Object[] args = { profile.getLoginName(), randomPassword, + engine.getURLConstructor().makeURL( WikiContext.NONE, "Login.jsp", true, "" ), + engine.getApplicationName() }; + String mailMessage = MessageFormat.format( rb.getString( "lostpwd.newpassword.email" ), args ); + + // Compose the message subject line + args = new Object[] { engine.getApplicationName() }; + String mailSubject = MessageFormat.format( rb.getString( "lostpwd.newpassword.subject" ), args ); + + // Send the message. + MailUtil.sendMessage( engine, email, mailSubject, mailMessage ); + log.info( "User " + email + " requested and received a new password." ); + + // Mail succeeded. Now reset the password. + // If this fails, we're kind of screwed, because we already mailed + // it. + profile.setPassword( randomPassword ); + userDatabase.save( profile ); + success = true; + } + catch( NoSuchPrincipalException e ) + { + messageKey = "lostpwd.nouser"; + log.info( "Tried to reset password for non-existent user '" + m_email + "'" ); + } + catch( SendFailedException e ) + { + messageKey = "lostpwd.nomail"; + log.error( "Tried to reset password and got SendFailedException: " + e ); + } + catch( AuthenticationFailedException e ) + { + messageKey = "lostpwd.nomail"; + log.error( "Tried to reset password and got AuthenticationFailedException: " + e ); + } + catch( Exception e ) + { + messageKey = "lostpwd.nomail"; + log.error( "Tried to reset password and got another exception: " + e ); + } + + if( success ) + { + List<Message> messages = getContext().getMessages( "reset" ); + messages.add( new SimpleMessage( rb.getString( "lostpwd.emailed" ) ) ); + } + else + // Error + { + ValidationErrors errors = getContext().getValidationErrors(); + errors.addGlobalError( new LocalizableError( messageKey, m_email ) ); + } + + return new ForwardResolution( "/templates/default/Login.jsp" ).addParameter( "tab", "reset" ); + } + + /** + * Sets the e-mail property. Used by the {...@link #resetPassword()} event. + * + * @param email the e-mail address + */ + @Validate( required = true, on = "reset", converter = net.sourceforge.stripes.validation.EmailTypeConverter.class ) + public void setEmail( String email ) + { + m_email = email; + } + + /** + * Default handler that forwards the user to the template JSP. + * + * @return the resolution + */ + @DefaultHandler + @DontValidate + @HandlesEvent( "view" ) + public Resolution view() + { + return new ForwardResolution( "/templates/default/Login.jsp" ).addParameter( "tab", "reset" ); + } + +}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java?rev=905899&r1=905898&r2=905899&view=diff ============================================================================== --- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java (original) +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java Wed Feb 3 05:27:01 2010 @@ -46,7 +46,7 @@ /** */ -...@urlbinding( "/UserPreferences.action" ) +...@urlbinding( "/UserPreferences.jsp" ) public class UserPreferencesActionBean extends AbstractActionBean { private static final Logger log = LoggerFactory.getLogger( "JSPWiki" ); @@ -350,6 +350,6 @@ @WikiRequestContext( "prefs" ) public Resolution view() { - return new ForwardResolution( "/UserPreferences.jsp" ); + return new ForwardResolution( "/templates/default/Preferences.jsp" ).addParameter( "tab", "prefs" ); } } Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java?rev=905899&r1=905898&r2=905899&view=diff ============================================================================== --- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java (original) +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java Wed Feb 3 05:27:01 2010 @@ -47,7 +47,7 @@ /** */ -...@urlbinding( "/UserProfile.action" ) +...@urlbinding( "/UserProfile.jsp" ) public class UserProfileActionBean extends AbstractActionBean { Logger log = LoggerFactory.getLogger( UserProfileActionBean.class ); @@ -76,7 +76,7 @@ /** * Pre-action that loads the UserProfile before user-supplied parameters are * bound to the ActionBean. Also stashes the UserProfile as a request-scoped - * attribute named <code>profile</code>. This attribute can be used in + * attribute named {...@code userProfile}. This attribute can be used in * JSP EL expressions as <code>$%7Bprofile%7D</code>. * * @return <code>null</code>, always @@ -94,7 +94,7 @@ m_profile.setPassword( null ); // Stash the profile as a request attribute - getContext().getRequest().setAttribute( "profile", m_profile ); + getContext().getRequest().setAttribute( "userProfile", m_profile ); return null; } @@ -136,7 +136,7 @@ // know about them catch( Exception e ) { - errors.addGlobalError( new LocalizableError( "profile.saveError", e.getMessage() ) ); + errors.add( "profile", new LocalizableError( "profile.saveError", e.getMessage() ) ); } // If no errors, send user to front page (or redirected page) @@ -274,7 +274,7 @@ @DontValidate public Resolution create() { - return new ForwardResolution( "/CreateProfile.jsp" ); + return new ForwardResolution( "/templates/default/CreateProfile.jsp" ).addParameter( "tab", "profile" ); } /** @@ -289,9 +289,7 @@ @WikiRequestContext( "profile" ) public Resolution view() { - ForwardResolution r = new ForwardResolution( "/UserPreferences.jsp" ); - r.addParameter( "tab", "profile" ); - return r; + return new ForwardResolution( "/templates/default/Preferences.jsp" ).addParameter( "tab", "profile" ); } } Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java?rev=905899&r1=905898&r2=905899&view=diff ============================================================================== --- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java (original) +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java Wed Feb 3 05:27:01 2010 @@ -108,7 +108,7 @@ /** * Handler that forwards to the page information display JSP - * <code>/Attachments.jsp</code>. + * {...@code PageInfo.jsp}. * * @return a forward to the content template */ @@ -116,7 +116,7 @@ @HandlerPermission( permissionClass = PagePermission.class, target = "${page.path}", actions = PagePermission.VIEW_ACTION ) public Resolution attachments() { - return new ForwardResolution( "/templates/default/Attachments.jsp" ); + return new ForwardResolution( "/templates/default/PageInfo.jsp" ).addParameter( "tab", "attachments" ); } /** @@ -156,7 +156,7 @@ { return new ForwardResolution( "/templates/default/AttachmentInfo.jsp" ); } - return new ForwardResolution( "/templates/default/PageInfo.jsp" ); + return new ForwardResolution( "/templates/default/PageInfo.jsp" ).addParameter( "tab", "info" ); } /** @@ -306,7 +306,7 @@ public Resolution view() throws ProviderException { // Forward to display JSP - return new ForwardResolution( "/templates/default/Wiki.jsp" ); + return new ForwardResolution( "/templates/default/Wiki.jsp" ).addParameter( "tab", "view" ); } /**
