📄 passwordhintaction.java
字号:
package org.redsoft.forum.web;import org.apache.struts.action.*;import org.redsoft.forum.dao.AccountDAO;import org.redsoft.forum.dao.DAOFactory;import org.redsoft.forum.dao.Account;import org.redsoft.forum.exception.DAOException;import org.redsoft.forum.exception.AccountNotFoundException;import org.redsoft.forum.mail.MailAgent;import org.redsoft.forum.ForumConstants;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Password Hint Action * When user forget his password, mail password to user when he enter correct * username and email of his account * * @author cinc * @version 1,Novenber 8,2003 */public class PasswordHintAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { final PasswordHintForm passwordHintForm = (PasswordHintForm) form; final ActionErrors errors = new ActionErrors(); final AccountDAO accountDAO = DAOFactory.getInstance().getAccountDAO(); try { final Account account = accountDAO.findByUserName( passwordHintForm.getUserName() ); if ( account.getEmail().equals( passwordHintForm.getEmail() ) ) { // save account to request for display in passwordHintOk.jsp request.setAttribute( ForumConstants.ACCOUNT , account ); // send account info to user final String messageBody = "<br>Welcome to ChinaXP.org." + "<br><br>Following is your account infomation in ChinaXP Forum: " + "<br>Username : " + account.getUserName() + "<br>Password : " + account.getPassword() ; // Spwan a thread to send email to avoid blocking new MailAgent( account.getEmail(), "chinaxp@chinaxp.org", "Your account information in ChinaXP.org", MailAgent.createHtmlMailBody( messageBody ) ).start(); } else { // email mismatch errors.add("Password Hint", new ActionError("error.email.misMatch") ); } } catch (DAOException daoException) { daoException.printStackTrace(); return (mapping.findForward("error")); } catch (AccountNotFoundException e) { errors.add("Password Hint", new ActionError("error.userName.notFound") ); } // Report any errors we have discovered back to the original form if (!errors.isEmpty()) { saveErrors(request, errors); return (new ActionForward(mapping.getInput())); } // Forward control to the specified success URI return (mapping.findForward("success")); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -