ChangePasswd.java
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:3k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.opensource.blog.web.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.apache.struts.action.ActionForm;
  5. import org.apache.struts.action.ActionForward;
  6. import org.apache.struts.action.ActionMapping;
  7. import org.apache.struts.action.ActionMessage;
  8. import org.apache.struts.action.ActionMessages;
  9. import com.laoer.comm.util.Util;
  10. import com.opensource.blog.comm.BlogUtil;
  11. import com.opensource.blog.exception.BlogException;
  12. import com.opensource.blog.model.UserInfo;
  13. import com.opensource.blog.service.UserInfoService;
  14. import com.opensource.blog.web.form.ChangePasswdForm;
  15. import com.opensource.blog.web.servlet.UserSession;
  16. public class ChangePasswd
  17.     extends BaseAction {
  18.   private UserInfoService userInfoService;
  19.   public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
  20.                                HttpServletRequest servletRequest,
  21.                                HttpServletResponse servletResponse) {
  22.     ActionMessages errors = new ActionMessages();
  23.     ChangePasswdForm form = (ChangePasswdForm) actionForm;
  24.     UserSession us = this.getUserSession(servletRequest);
  25.     if (form.getAction().equalsIgnoreCase("show")) {
  26.       form.setAction("change");
  27.       return actionMapping.findForward("changepasswd");
  28.     }
  29.     if (form.getAction().equalsIgnoreCase("change")) {
  30.       UserInfo ui = us.getUserInfo();
  31.       if (!Util.hash(form.getOldpasswd()).equals(ui.getPasswdre())) {
  32.         errors.add("error.cp.oldpasswderror", new ActionMessage("error.cp.oldpasswderror"));
  33.         saveErrors(servletRequest, errors);
  34.         return actionMapping.findForward("error");
  35.       }
  36.       ui.setPasswd(form.getNewpasswd());
  37.       ui.setPasswdre(form.getNewpasswdre());
  38.       try {
  39.         ui = this.getUserInfoService().saveUserInfo(ui);
  40.       }
  41.       catch (BlogException ex) {
  42.         errors.add("error.cp.changepasswderror", new ActionMessage("error.cp.changepasswderror"));
  43.         saveErrors(servletRequest, errors);
  44.         return actionMapping.findForward("error");
  45.       }
  46.       this.saveUserSession(servletRequest, ui);
  47.       ActionForward f = new ActionForward(BlogUtil.getResultUrl("cp.changepasswd.well",
  48.           "changePasswd.do"), true);
  49.       return f;
  50.     }
  51.     return actionMapping.findForward("error");
  52.   }
  53.   public UserInfoService getUserInfoService() {
  54.     return userInfoService;
  55.   }
  56.   public void setUserInfoService(UserInfoService userInfoService) {
  57.     this.userInfoService = userInfoService;
  58.   }
  59. }