ChangePasswd.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:3k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.opensource.blog.web.action;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionMessage;
- import org.apache.struts.action.ActionMessages;
- import com.laoer.comm.util.Util;
- import com.opensource.blog.comm.BlogUtil;
- import com.opensource.blog.exception.BlogException;
- import com.opensource.blog.model.UserInfo;
- import com.opensource.blog.service.UserInfoService;
- import com.opensource.blog.web.form.ChangePasswdForm;
- import com.opensource.blog.web.servlet.UserSession;
- public class ChangePasswd
- extends BaseAction {
- private UserInfoService userInfoService;
- public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- ActionMessages errors = new ActionMessages();
- ChangePasswdForm form = (ChangePasswdForm) actionForm;
- UserSession us = this.getUserSession(servletRequest);
- if (form.getAction().equalsIgnoreCase("show")) {
- form.setAction("change");
- return actionMapping.findForward("changepasswd");
- }
- if (form.getAction().equalsIgnoreCase("change")) {
- UserInfo ui = us.getUserInfo();
- if (!Util.hash(form.getOldpasswd()).equals(ui.getPasswdre())) {
- errors.add("error.cp.oldpasswderror", new ActionMessage("error.cp.oldpasswderror"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- ui.setPasswd(form.getNewpasswd());
- ui.setPasswdre(form.getNewpasswdre());
- try {
- ui = this.getUserInfoService().saveUserInfo(ui);
- }
- catch (BlogException ex) {
- errors.add("error.cp.changepasswderror", new ActionMessage("error.cp.changepasswderror"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- this.saveUserSession(servletRequest, ui);
- ActionForward f = new ActionForward(BlogUtil.getResultUrl("cp.changepasswd.well",
- "changePasswd.do"), true);
- return f;
- }
- return actionMapping.findForward("error");
- }
- public UserInfoService getUserInfoService() {
- return userInfoService;
- }
- public void setUserInfoService(UserInfoService userInfoService) {
- this.userInfoService = userInfoService;
- }
- }